Easy WP SMTP - Version 1.3.2

Version Description

  • Hopefully fixed inability for plugin to save settings in some circumstances (thanks to all who kept reporting this issue).
  • The plugin is no longer failing if PHP mbstring extension is not installed on the server.
  • Settings page is using tabs now.
  • Fixed default settings were not set upon plugin activation.
  • Fixed some lines that couldn't be translated to other languages (thanks to jranavas).
Download this release

Release Info

Developer mra13
Plugin Icon 128x128 Easy WP SMTP
Version 1.3.2
Comparing to
See all releases

Code changes from version 1.3.1 to 1.3.2

Files changed (4) hide show
  1. easy-wp-smtp-admin-menu.php +380 -345
  2. easy-wp-smtp.php +316 -300
  3. js/script.js +1 -7
  4. readme.txt +8 -1
easy-wp-smtp-admin-menu.php CHANGED
@@ -5,8 +5,8 @@
5
  * @return void
6
  */
7
  function swpsmtp_admin_default_setup() {
8
- //add_submenu_page( 'options-general.php', __( 'Easy WP SMTP', 'easy-wp-smtp' ), __( 'Easy WP SMTP', 'easy-wp-smtp' ), $capabilities, 'swpsmtp_settings', 'swpsmtp_settings' );
9
- add_options_page( __( 'Easy WP SMTP', 'easy-wp-smtp' ), __( 'Easy WP SMTP', 'easy-wp-smtp' ), 'manage_options', 'swpsmtp_settings', 'swpsmtp_settings' );
10
  }
11
 
12
  /**
@@ -14,364 +14,399 @@ function swpsmtp_admin_default_setup() {
14
  * @return void
15
  */
16
  function swpsmtp_settings() {
17
- echo '<div class="wrap" id="swpsmtp-mail">';
18
- echo '<h2>' . __( "Easy WP SMTP Settings", 'easy-wp-smtp' ) . '</h2>';
19
- echo '<div id="poststuff"><div id="post-body">';
20
 
21
- $display_add_options = $message = $error = $result = '';
22
 
23
- $swpsmtp_options = get_option( 'swpsmtp_options' );
24
- $smtp_test_mail = get_option( 'smtp_test_mail' );
25
- $gag_password = '#easywpsmtpgagpass#';
26
- if ( empty( $smtp_test_mail ) ) {
27
- $smtp_test_mail = array( 'swpsmtp_to' => '', 'swpsmtp_subject' => '', 'swpsmtp_message' => '', );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
  }
29
 
30
- if ( isset( $_POST['swpsmtp_form_submit'] ) && check_admin_referer( plugin_basename( __FILE__ ), 'swpsmtp_nonce_name' ) ) {
31
- /* Update settings */
32
- $swpsmtp_options['from_name_field'] = isset( $_POST['swpsmtp_from_name'] ) ? sanitize_text_field( wp_unslash( $_POST['swpsmtp_from_name'] ) ) : '';
33
- if ( isset( $_POST['swpsmtp_from_email'] ) ) {
34
- if ( is_email( $_POST['swpsmtp_from_email'] ) ) {
35
- $swpsmtp_options['from_email_field'] = sanitize_email( $_POST['swpsmtp_from_email'] );
36
- } else {
37
- $error .= " " . __( "Please enter a valid email address in the 'FROM' field.", 'easy-wp-smtp' );
38
- }
39
- }
40
- if ( isset( $_POST['swpsmtp_reply_to_email'] ) ) {
41
- $swpsmtp_options['reply_to_email'] = sanitize_email( $_POST['swpsmtp_reply_to_email'] );
42
- }
43
-
44
- if ( isset( $_POST['swpsmtp_email_ignore_list'] ) ) {
45
- $swpsmtp_options['email_ignore_list'] = sanitize_text_field( $_POST['swpsmtp_email_ignore_list'] );
46
- }
47
-
48
- $swpsmtp_options['smtp_settings']['host'] = sanitize_text_field( $_POST['swpsmtp_smtp_host'] );
49
- $swpsmtp_options['smtp_settings']['type_encryption'] = ( isset( $_POST['swpsmtp_smtp_type_encryption'] ) ) ? sanitize_text_field( $_POST['swpsmtp_smtp_type_encryption'] ) : 'none';
50
- $swpsmtp_options['smtp_settings']['autentication'] = ( isset( $_POST['swpsmtp_smtp_autentication'] ) ) ? sanitize_text_field( $_POST['swpsmtp_smtp_autentication'] ) : 'yes';
51
- $swpsmtp_options['smtp_settings']['username'] = sanitize_text_field( $_POST['swpsmtp_smtp_username'] );
52
- $smtp_password = $_POST['swpsmtp_smtp_password'];
53
- if ( $smtp_password !== $gag_password ) {
54
- $swpsmtp_options['smtp_settings']['password'] = base64_encode( $smtp_password );
55
- }
56
- $swpsmtp_options['smtp_settings']['enable_debug'] = isset( $_POST['swpsmtp_enable_debug'] ) ? 1 : false;
57
- $swpsmtp_options['enable_domain_check'] = isset( $_POST['swpsmtp_enable_domain_check'] ) ? 1 : false;
58
- if ( isset( $_POST['swpsmtp_allowed_domains'] ) ) {
59
- $swpsmtp_options['block_all_emails'] = isset( $_POST['swpsmtp_block_all_emails'] ) ? 1 : false;
60
- $swpsmtp_options['allowed_domains'] = base64_encode( sanitize_text_field( $_POST['swpsmtp_allowed_domains'] ) );
61
- } else if ( !isset( $swpsmtp_options['allowed_domains'] ) ) {
62
- $swpsmtp_options['allowed_domains'] = '';
63
- }
64
-
65
- /* Check value from "SMTP port" option */
66
- if ( isset( $_POST['swpsmtp_smtp_port'] ) ) {
67
- if ( empty( $_POST['swpsmtp_smtp_port'] ) || 1 > intval( $_POST['swpsmtp_smtp_port'] ) || (!preg_match( '/^\d+$/', $_POST['swpsmtp_smtp_port'] ) ) ) {
68
- $swpsmtp_options['smtp_settings']['port'] = '25';
69
- $error .= " " . __( "Please enter a valid port in the 'SMTP Port' field.", 'easy-wp-smtp' );
70
- } else {
71
- $swpsmtp_options['smtp_settings']['port'] = sanitize_text_field( $_POST['swpsmtp_smtp_port'] );
72
- }
73
- }
74
-
75
- /* Update settings in the database */
76
- if ( empty( $error ) ) {
77
- update_option( 'swpsmtp_options', $swpsmtp_options );
78
- $message .= __( "Settings saved.", 'easy-wp-smtp' );
79
- } else {
80
- $error .= " " . __( "Settings are not saved.", 'easy-wp-smtp' );
81
- }
82
  }
83
 
84
- /* Send test letter */
85
- $swpsmtp_to = '';
86
- if ( isset( $_POST['swpsmtp_test_submit'] ) && check_admin_referer( plugin_basename( __FILE__ ), 'swpsmtp_nonce_name' ) ) {
87
- if ( isset( $_POST['swpsmtp_to'] ) ) {
88
- $to_email = sanitize_text_field( $_POST['swpsmtp_to'] );
89
- if ( is_email( $to_email ) ) {
90
- $swpsmtp_to = $to_email;
91
- } else {
92
- $error .= __( "Please enter a valid email address in the recipient email field.", 'easy-wp-smtp' );
93
- }
94
- }
95
- $swpsmtp_subject = isset( $_POST['swpsmtp_subject'] ) ? sanitize_text_field( $_POST['swpsmtp_subject'] ) : '';
96
- $swpsmtp_message = isset( $_POST['swpsmtp_message'] ) ? sanitize_textarea_field( $_POST['swpsmtp_message'] ) : '';
97
-
98
- //Save the test mail details so it doesn't need to be filled in everytime.
99
- $smtp_test_mail['swpsmtp_to'] = $swpsmtp_to;
100
- $smtp_test_mail['swpsmtp_subject'] = $swpsmtp_subject;
101
- $smtp_test_mail['swpsmtp_message'] = $swpsmtp_message;
102
- update_option( 'smtp_test_mail', $smtp_test_mail );
103
-
104
- if ( !empty( $swpsmtp_to ) ) {
105
- $result = swpsmtp_test_mail( $swpsmtp_to, $swpsmtp_subject, $swpsmtp_message );
106
- }
107
  }
108
- ?>
109
- <div class="swpsmtp-yellow-box">
110
- Please visit the <a target="_blank" href="https://wp-ecommerce.net/easy-wordpress-smtp-send-emails-from-your-wordpress-site-using-a-smtp-server-2197">Easy WP SMTP</a> plugin's documentation page for usage instructions.
111
- </div>
112
-
113
- <div class="updated fade" <?php if ( empty( $message ) ) echo "style=\"display:none\""; ?>>
114
- <p><strong><?php echo $message; ?></strong></p>
115
- </div>
116
- <div class="error" <?php if ( empty( $error ) ) echo "style=\"display:none\""; ?>>
117
- <p><strong><?php echo $error; ?></strong></p>
118
- </div>
119
- <div id="swpsmtp-settings-notice" class="updated fade" style="display:none">
120
- <p><strong><?php _e( "Notice:", 'easy-wp-smtp' ); ?></strong> <?php _e( "The plugin's settings have been changed. In order to save them please don't forget to click the 'Save Changes' button.", 'easy-wp-smtp' ); ?></p>
121
- </div>
122
- <form id="swpsmtp_settings_form" method="post" action="">
123
-
124
- <div class="postbox">
125
- <h3 class="hndle"><label for="title"><?php _e( 'SMTP Configuration Settings', 'easy-wp-smtp' ); ?></label></h3>
126
- <div class="inside">
127
-
128
- <p>You can request your hosting provider for the SMTP details of your site. Use the SMTP details provided by your hosting provider to configure the following settings.</p>
129
-
130
- <table class="form-table">
131
- <tr valign="top">
132
- <th scope="row"><?php _e( "From Email Address", 'easy-wp-smtp' ); ?></th>
133
- <td>
134
- <input type="text" name="swpsmtp_from_email" value="<?php echo isset( $swpsmtp_options['from_email_field'] ) ? esc_attr( $swpsmtp_options['from_email_field'] ) : ''; ?>"/><br />
135
- <p class="description"><?php _e( "This email address will be used in the 'From' field.", 'easy-wp-smtp' ); ?></p>
136
- </td>
137
- </tr>
138
- <tr valign="top">
139
- <th scope="row"><?php _e( "From Name", 'easy-wp-smtp' ); ?></th>
140
- <td>
141
- <input type="text" name="swpsmtp_from_name" value="<?php echo isset( $swpsmtp_options['from_name_field'] ) ? esc_attr( $swpsmtp_options['from_name_field'] ) : ''; ?>"/><br />
142
- <p class="description"><?php _e( "This text will be used in the 'FROM' field", 'easy-wp-smtp' ); ?></p>
143
- </td>
144
- </tr>
145
- <tr valign="top">
146
- <th scope="row"><?php _e( "Reply-To Email Address", 'easy-wp-smtp' ); ?></th>
147
- <td>
148
- <input type="email" name="swpsmtp_reply_to_email" value="<?php echo isset( $swpsmtp_options['reply_to_email'] ) ? esc_attr( $swpsmtp_options['reply_to_email'] ) : ''; ?>"/><br />
149
- <p class="description"><?php _e( "Optional. This email address will be used in the 'Reply-To' field of the email. Leave it blank to use 'From' email as the reply-to value.", 'easy-wp-smtp' ); ?></p>
150
- </td>
151
- </tr>
152
- <tr class="ad_opt swpsmtp_smtp_options">
153
- <th><?php _e( 'SMTP Host', 'easy-wp-smtp' ); ?></th>
154
- <td>
155
- <input type='text' name='swpsmtp_smtp_host' value='<?php echo isset( $swpsmtp_options['smtp_settings']['host'] ) ? esc_attr( $swpsmtp_options['smtp_settings']['host'] ) : ''; ?>' /><br />
156
- <p class="description"><?php _e( "Your mail server", 'easy-wp-smtp' ); ?></p>
157
- </td>
158
- </tr>
159
- <tr class="ad_opt swpsmtp_smtp_options">
160
- <th><?php _e( 'Type of Encryption', 'easy-wp-smtp' ); ?></th>
161
- <td>
162
- <label for="swpsmtp_smtp_type_encryption_1"><input type="radio" id="swpsmtp_smtp_type_encryption_1" name="swpsmtp_smtp_type_encryption" value='none' <?php if ( isset( $swpsmtp_options['smtp_settings']['type_encryption'] ) && 'none' == $swpsmtp_options['smtp_settings']['type_encryption'] ) echo 'checked="checked"'; ?> /> <?php _e( 'None', 'easy-wp-smtp' ); ?></label>
163
- <label for="swpsmtp_smtp_type_encryption_2"><input type="radio" id="swpsmtp_smtp_type_encryption_2" name="swpsmtp_smtp_type_encryption" value='ssl' <?php if ( isset( $swpsmtp_options['smtp_settings']['type_encryption'] ) && 'ssl' == $swpsmtp_options['smtp_settings']['type_encryption'] ) echo 'checked="checked"'; ?> /> <?php _e( 'SSL', 'easy-wp-smtp' ); ?></label>
164
- <label for="swpsmtp_smtp_type_encryption_3"><input type="radio" id="swpsmtp_smtp_type_encryption_3" name="swpsmtp_smtp_type_encryption" value='tls' <?php if ( isset( $swpsmtp_options['smtp_settings']['type_encryption'] ) && 'tls' == $swpsmtp_options['smtp_settings']['type_encryption'] ) echo 'checked="checked"'; ?> /> <?php _e( 'TLS', 'easy-wp-smtp' ); ?></label><br />
165
- <p class="description"><?php _e( "For most servers SSL is the recommended option", 'easy-wp-smtp' ); ?></p>
166
- </td>
167
- </tr>
168
- <tr class="ad_opt swpsmtp_smtp_options">
169
- <th><?php _e( 'SMTP Port', 'easy-wp-smtp' ); ?></th>
170
- <td>
171
- <input type='text' name='swpsmtp_smtp_port' value='<?php echo isset( $swpsmtp_options['smtp_settings']['port'] ) ? esc_attr( $swpsmtp_options['smtp_settings']['port'] ) : ''; ?>' /><br />
172
- <p class="description"><?php _e( "The port to your mail server", 'easy-wp-smtp' ); ?></p>
173
- </td>
174
- </tr>
175
- <tr class="ad_opt swpsmtp_smtp_options">
176
- <th><?php _e( 'SMTP Authentication', 'easy-wp-smtp' ); ?></th>
177
- <td>
178
- <label for="swpsmtp_smtp_autentication"><input type="radio" id="swpsmtp_smtp_autentication" name="swpsmtp_smtp_autentication" value='no' <?php if ( isset( $swpsmtp_options['smtp_settings']['autentication'] ) && 'no' == $swpsmtp_options['smtp_settings']['autentication'] ) echo 'checked="checked"'; ?> /> <?php _e( 'No', 'easy-wp-smtp' ); ?></label>
179
- <label for="swpsmtp_smtp_autentication"><input type="radio" id="swpsmtp_smtp_autentication" name="swpsmtp_smtp_autentication" value='yes' <?php if ( isset( $swpsmtp_options['smtp_settings']['autentication'] ) && 'yes' == $swpsmtp_options['smtp_settings']['autentication'] ) echo 'checked="checked"'; ?> /> <?php _e( 'Yes', 'easy-wp-smtp' ); ?></label><br />
180
- <p class="description"><?php _e( "This options should always be checked 'Yes'", 'easy-wp-smtp' ); ?></p>
181
- </td>
182
- </tr>
183
- <tr class="ad_opt swpsmtp_smtp_options">
184
- <th><?php _e( 'SMTP username', 'easy-wp-smtp' ); ?></th>
185
- <td>
186
- <input type='text' name='swpsmtp_smtp_username' value='<?php echo isset( $swpsmtp_options['smtp_settings']['username'] ) ? esc_attr( $swpsmtp_options['smtp_settings']['username'] ) : ''; ?>' /><br />
187
- <p class="description"><?php _e( "The username to login to your mail server", 'easy-wp-smtp' ); ?></p>
188
- </td>
189
- </tr>
190
- <tr class="ad_opt swpsmtp_smtp_options">
191
- <th><?php _e( 'SMTP Password', 'easy-wp-smtp' ); ?></th>
192
- <td>
193
- <input type='password' name='swpsmtp_smtp_password' value='<?php echo (swpsmtp_get_password() !== '' ? $gag_password : ''); ?>' /><br />
194
- <p class="description"><?php _e( "The password to login to your mail server", 'easy-wp-smtp' ); ?></p>
195
- </td>
196
- </tr>
197
- </table>
198
- <p class="submit">
199
- <input type="submit" id="settings-form-submit" class="button-primary" value="<?php _e( 'Save Changes', 'easy-wp-smtp' ) ?>" />
200
- </p>
201
- </div><!-- end of inside -->
202
- </div><!-- end of postbox -->
203
-
204
- <div class="postbox">
205
- <h3 class="hndle"><label for="title"><?php _e( 'Additional Settings (Optional)', 'easy-wp-smtp' ); ?></label></h3>
206
- <div class="inside">
207
- <table class="form-table">
208
- <tr valign="top">
209
- <th scope="row"><?php _e( "Don't Replace \"From\" Field", 'easy-wp-smtp' ); ?></th>
210
- <td>
211
- <input type="text" name="swpsmtp_email_ignore_list" value="<?php echo isset( $swpsmtp_options['email_ignore_list'] ) ? esc_attr( $swpsmtp_options['email_ignore_list'] ) : ''; ?>"/><br />
212
- <p class="description"><?php _e( "Comma separated emails list. Example value: email1@domain.com, email2@domain.com", "easy-wp-smtp" ); ?></p>
213
- <p class="description"><?php _e( "This option is useful when you are using several email aliases on your SMTP server. If you don't want your aliases to be replaced by the address specified in \"From\" field, enter them in this field.", 'easy-wp-smtp' ); ?></p>
214
- </td>
215
- </tr>
216
- <tr valign="top">
217
- <th scope="row"><?php _e( "Enable Domain Check", 'easy-wp-smtp' ); ?></th>
218
- <td>
219
- <input type="checkbox" id="swpsmtp_enable_domain_check" name="swpsmtp_enable_domain_check" value="1"<?php echo (isset( $swpsmtp_options['enable_domain_check'] ) && ($swpsmtp_options['enable_domain_check'])) ? ' checked' : ''; ?>/>
220
- <p class="description"><?php _e( "This option is usually used by developers only. SMTP settings will be used only if the site is running on following domain(s):", 'easy-wp-smtp' ); ?></p>
221
- <input type="text" name="swpsmtp_allowed_domains" value="<?php echo base64_decode_maybe( $swpsmtp_options['allowed_domains'] ); ?>"<?php echo (isset( $swpsmtp_options['enable_domain_check'] ) && ($swpsmtp_options['enable_domain_check'])) ? '' : ' disabled'; ?>/>
222
- <p class="description"><?php _e( "Coma-separated domains list. Example: domain1.com, domain2.com", 'easy-wp-smtp' ); ?></p>
223
- <p>
224
- <label><input type="checkbox" id="swpsmtp_block_all_emails" name="swpsmtp_block_all_emails" value="1"<?php echo (isset( $swpsmtp_options['block_all_emails'] ) && ($swpsmtp_options['block_all_emails'])) ? ' checked' : ''; ?><?php echo (isset( $swpsmtp_options['enable_domain_check'] ) && ($swpsmtp_options['enable_domain_check'])) ? '' : ' disabled'; ?>/> Block all emails</label>
225
- </p>
226
- <p class="description"><?php _e( "When enabled, plugin attempts to block ALL emails from being sent out if domain mismtach." ); ?></p>
227
- </td>
228
- </tr>
229
- <tr valign="top">
230
- <th scope="row"><?php _e( "Enable Debug Log", 'easy-wp-smtp' ); ?></th>
231
- <td>
232
- <input type="checkbox" name="swpsmtp_enable_debug" value="1" <?php echo (isset( $swpsmtp_options['smtp_settings']['enable_debug'] ) && ($swpsmtp_options['smtp_settings']['enable_debug'])) ? 'checked' : ''; ?>/>
233
- <p class="description"><?php _e( "Check this box to enable mail debug log", 'easy-wp-smtp' ); ?></p>
234
- <a href="<?php echo admin_url(); ?>?swpsmtp_action=view_log" target="_blank"><?php _e( 'View Log', 'easy-wp-smtp' ); ?></a> | <a style="color: red;" id="swpsmtp_clear_log_btn" href="#0"><?php _e( 'Clear Log', 'easy-wp-smtp' ); ?></a>
235
- </td>
236
- </tr>
237
- </table>
238
- <p class="submit">
239
- <input type="submit" id="settings-form-submit" class="button-primary" value="<?php _e( 'Save Changes', 'easy-wp-smtp' ) ?>" />
240
- <input type="hidden" name="swpsmtp_form_submit" value="submit" />
241
- <?php wp_nonce_field( plugin_basename( __FILE__ ), 'swpsmtp_nonce_name' ); ?>
242
- </p>
243
-
244
- <script>
245
- jQuery(function ($) {
246
- $('#swpsmtp_enable_domain_check').change(function () {
247
- $('input[name="swpsmtp_allowed_domains"]').prop('disabled', !$(this).is(':checked'));
248
- $('input[name="swpsmtp_block_all_emails"]').prop('disabled', !$(this).is(':checked'));
249
- });
250
- $('#swpsmtp_clear_log_btn').click(function (e) {
251
- e.preventDefault();
252
- if (confirm("<?php _e( 'Are you sure want to clear log?', 'easy-wp-smtp' ); ?>")) {
253
- var req = jQuery.ajax({
254
- url: ajaxurl,
255
- type: "post",
256
- data: {action: "swpsmtp_clear_log"}
257
- });
258
- req.done(function (data) {
259
- if (data === '1') {
260
- alert("<?php _e( 'Log cleared.', 'easy-wp-smtp' ); ?>");
261
- } else {
262
- alert("Error occured: " + data);
263
- }
264
- });
265
- }
266
- });
267
- });
268
- </script>
269
- </div><!-- end of inside -->
270
- </div><!-- end of postbox -->
271
- </form>
272
- <div class="postbox">
273
- <h3 class="hndle"><label for="title"><?php _e( 'Test Email', 'easy-wp-smtp' ); ?></label></h3>
274
- <div class="inside">
275
-
276
- <p>You can use this section to send an email from your server using the above configured SMTP details to see if the email gets delivered.</p>
277
- <p><b>Note</b>: debug log for this test email will be automatically displayed right after you send it. Test email also ignores "Enable Domain Check" option.</p>
278
-
279
- <form id="swpsmtp_settings_form" method="post" action="">
280
- <table class="form-table">
281
- <tr valign="top">
282
- <th scope="row"><?php _e( "To", 'easy-wp-smtp' ); ?>:</th>
283
- <td>
284
- <input type="text" name="swpsmtp_to" value="<?php echo esc_html( $smtp_test_mail['swpsmtp_to'] ); ?>" /><br />
285
- <p class="description"><?php _e( "Enter the recipient's email address", 'easy-wp-smtp' ); ?></p>
286
- </td>
287
- </tr>
288
- <tr valign="top">
289
- <th scope="row"><?php _e( "Subject", 'easy-wp-smtp' ); ?>:</th>
290
- <td>
291
- <input type="text" name="swpsmtp_subject" value="<?php echo esc_html( $smtp_test_mail['swpsmtp_subject'] ); ?>" /><br />
292
- <p class="description"><?php _e( "Enter a subject for your message", 'easy-wp-smtp' ); ?></p>
293
- </td>
294
- </tr>
295
- <tr valign="top">
296
- <th scope="row"><?php _e( "Message", 'easy-wp-smtp' ); ?>:</th>
297
- <td>
298
- <textarea name="swpsmtp_message" id="swpsmtp_message" rows="5"><?php echo stripslashes( esc_textarea( $smtp_test_mail['swpsmtp_message'] ) ); ?></textarea><br />
299
- <p class="description"><?php _e( "Write your email message", 'easy-wp-smtp' ); ?></p>
300
- </td>
301
- </tr>
302
- </table>
303
- <p class="submit">
304
- <input type="submit" id="settings-form-submit" class="button-primary" value="<?php _e( 'Send Test Email', 'easy-wp-smtp' ) ?>" />
305
- <input type="hidden" name="swpsmtp_test_submit" value="submit" />
306
- <?php wp_nonce_field( plugin_basename( __FILE__ ), 'swpsmtp_nonce_name' ); ?>
307
- </p>
308
- </form>
309
- </div><!-- end of inside -->
310
- </div><!-- end of postbox -->
311
-
312
- <div class="swpsmtp-yellow-box">
313
- Visit the <a target="_blank" href="https://wp-ecommerce.net/easy-wordpress-smtp-send-emails-from-your-wordpress-site-using-a-smtp-server-2197">Easy WP SMTP</a> plugin's documentation page to learn how to use this plugin.
314
- </div>
315
-
316
- <?php
317
- echo '</div></div>'; //<!-- end of #poststuff and #post-body -->
318
- echo '</div>'; //<!-- end of .wrap #swpsmtp-mail .swpsmtp-mail -->
319
- }
320
 
321
- /**
322
- * Plugin functions for init
323
- * @return void
324
- */
325
- function swpsmtp_admin_init() {
326
- /* Internationalization, first(!) */
327
- load_plugin_textdomain( 'easy-wp-smtp', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
 
 
328
 
329
- if ( isset( $_REQUEST['page'] ) && 'swpsmtp_settings' == $_REQUEST['page'] ) {
330
- /* register plugin settings */
331
- swpsmtp_register_settings();
 
 
 
332
  }
333
- add_action( 'wp_ajax_swpsmtp_clear_log', 'swpsmtp_clear_log' );
334
- //view log file
335
- if ( isset( $_GET['swpsmtp_action'] ) ) {
336
- if ( $_GET['swpsmtp_action'] === 'view_log' ) {
337
- $swpsmtp_options = get_option( 'swpsmtp_options' );
338
- $log_file_name = $swpsmtp_options['smtp_settings']['log_file_name'];
339
- if ( !file_exists( plugin_dir_path( __FILE__ ) . $log_file_name ) ) {
340
- if ( swpsmtp_write_to_log( "Easy WP SMTP debug log file\r\n\r\n" ) === false ) {
341
- wp_die( 'Can\'t write to log file. Check if plugin directory (' . plugin_dir_path( __FILE__ ) . ') is writeable.' );
342
- };
343
- }
344
- $logfile = fopen( plugin_dir_path( __FILE__ ) . $log_file_name, 'rb' );
345
- if ( !$logfile ) {
346
- wp_die( 'Can\'t open log file.' );
347
- }
348
- header( 'Content-Type: text/plain' );
349
- fpassthru( $logfile );
350
- die;
351
- }
352
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
353
  }
354
 
355
  /**
356
- * Register settings function
357
  * @return void
358
  */
359
- function swpsmtp_register_settings() {
360
- $swpsmtp_options_default = array(
361
- 'from_email_field' => '',
362
- 'from_name_field' => '',
363
- 'smtp_settings' => array(
364
- 'host' => 'smtp.example.com',
365
- 'type_encryption' => 'none',
366
- 'port' => 25,
367
- 'autentication' => 'yes',
368
- 'username' => 'yourusername',
369
- 'password' => 'yourpassword'
370
- )
371
- );
372
-
373
- /* install the default plugin options */
374
- if ( !get_option( 'swpsmtp_options' ) ) {
375
- add_option( 'swpsmtp_options', $swpsmtp_options_default, '', 'yes' );
 
 
 
 
 
376
  }
 
377
  }
5
  * @return void
6
  */
7
  function swpsmtp_admin_default_setup() {
8
+ //add_submenu_page( 'options-general.php', __( 'Easy WP SMTP', 'easy-wp-smtp' ), __( 'Easy WP SMTP', 'easy-wp-smtp' ), $capabilities, 'swpsmtp_settings', 'swpsmtp_settings' );
9
+ add_options_page( __( 'Easy WP SMTP', 'easy-wp-smtp' ), __( 'Easy WP SMTP', 'easy-wp-smtp' ), 'manage_options', 'swpsmtp_settings', 'swpsmtp_settings' );
10
  }
11
 
12
  /**
14
  * @return void
15
  */
16
  function swpsmtp_settings() {
17
+ echo '<div class="wrap" id="swpsmtp-mail">';
18
+ echo '<h2>' . __( "Easy WP SMTP Settings", 'easy-wp-smtp' ) . '</h2>';
19
+ echo '<div id="poststuff"><div id="post-body">';
20
 
21
+ $display_add_options = $message = $error = $result = '';
22
 
23
+ $swpsmtp_options = get_option( 'swpsmtp_options' );
24
+ $smtp_test_mail = get_option( 'smtp_test_mail' );
25
+ $gag_password = '#easywpsmtpgagpass#';
26
+ if ( empty( $smtp_test_mail ) ) {
27
+ $smtp_test_mail = array( 'swpsmtp_to' => '', 'swpsmtp_subject' => '', 'swpsmtp_message' => '', );
28
+ }
29
+
30
+ if ( isset( $_POST[ 'swpsmtp_form_submit' ] )) {
31
+ // check nounce
32
+ if (!check_admin_referer( plugin_basename( __FILE__ ), 'swpsmtp_nonce_name' )) {
33
+ $error .= " " . __( "Nonce check failed.", 'easy-wp-smtp' );
34
+ }
35
+ /* Update settings */
36
+ $swpsmtp_options[ 'from_name_field' ] = isset( $_POST[ 'swpsmtp_from_name' ] ) ? sanitize_text_field( wp_unslash( $_POST[ 'swpsmtp_from_name' ] ) ) : '';
37
+ if ( isset( $_POST[ 'swpsmtp_from_email' ] ) ) {
38
+ if ( is_email( $_POST[ 'swpsmtp_from_email' ] ) ) {
39
+ $swpsmtp_options[ 'from_email_field' ] = sanitize_email( $_POST[ 'swpsmtp_from_email' ] );
40
+ } else {
41
+ $error .= " " . __( "Please enter a valid email address in the 'FROM' field.", 'easy-wp-smtp' );
42
+ }
43
+ }
44
+ if ( isset( $_POST[ 'swpsmtp_reply_to_email' ] ) ) {
45
+ $swpsmtp_options[ 'reply_to_email' ] = sanitize_email( $_POST[ 'swpsmtp_reply_to_email' ] );
46
  }
47
 
48
+ if ( isset( $_POST[ 'swpsmtp_email_ignore_list' ] ) ) {
49
+ $swpsmtp_options[ 'email_ignore_list' ] = sanitize_text_field( $_POST[ 'swpsmtp_email_ignore_list' ] );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50
  }
51
 
52
+ $swpsmtp_options[ 'smtp_settings' ][ 'host' ] = sanitize_text_field( $_POST[ 'swpsmtp_smtp_host' ] );
53
+ $swpsmtp_options[ 'smtp_settings' ][ 'type_encryption' ] = ( isset( $_POST[ 'swpsmtp_smtp_type_encryption' ] ) ) ? sanitize_text_field( $_POST[ 'swpsmtp_smtp_type_encryption' ] ) : 'none';
54
+ $swpsmtp_options[ 'smtp_settings' ][ 'autentication' ] = ( isset( $_POST[ 'swpsmtp_smtp_autentication' ] ) ) ? sanitize_text_field( $_POST[ 'swpsmtp_smtp_autentication' ] ) : 'yes';
55
+ $swpsmtp_options[ 'smtp_settings' ][ 'username' ] = sanitize_text_field( $_POST[ 'swpsmtp_smtp_username' ] );
56
+ $smtp_password = $_POST[ 'swpsmtp_smtp_password' ];
57
+ if ( $smtp_password !== $gag_password ) {
58
+ $swpsmtp_options[ 'smtp_settings' ][ 'password' ] = base64_encode( $smtp_password );
59
+ }
60
+ $swpsmtp_options[ 'smtp_settings' ][ 'enable_debug' ] = isset( $_POST[ 'swpsmtp_enable_debug' ] ) ? 1 : false;
61
+ $swpsmtp_options[ 'enable_domain_check' ] = isset( $_POST[ 'swpsmtp_enable_domain_check' ] ) ? 1 : false;
62
+ if ( isset( $_POST[ 'swpsmtp_allowed_domains' ] ) ) {
63
+ $swpsmtp_options[ 'block_all_emails' ] = isset( $_POST[ 'swpsmtp_block_all_emails' ] ) ? 1 : false;
64
+ $swpsmtp_options[ 'allowed_domains' ] = base64_encode( sanitize_text_field( $_POST[ 'swpsmtp_allowed_domains' ] ) );
65
+ } else if ( ! isset( $swpsmtp_options[ 'allowed_domains' ] ) ) {
66
+ $swpsmtp_options[ 'allowed_domains' ] = '';
 
 
 
 
 
 
 
 
67
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
68
 
69
+ /* Check value from "SMTP port" option */
70
+ if ( isset( $_POST[ 'swpsmtp_smtp_port' ] ) ) {
71
+ if ( empty( $_POST[ 'swpsmtp_smtp_port' ] ) || 1 > intval( $_POST[ 'swpsmtp_smtp_port' ] ) || ( ! preg_match( '/^\d+$/', $_POST[ 'swpsmtp_smtp_port' ] ) ) ) {
72
+ $swpsmtp_options[ 'smtp_settings' ][ 'port' ] = '25';
73
+ $error .= " " . __( "Please enter a valid port in the 'SMTP Port' field.", 'easy-wp-smtp' );
74
+ } else {
75
+ $swpsmtp_options[ 'smtp_settings' ][ 'port' ] = sanitize_text_field( $_POST[ 'swpsmtp_smtp_port' ] );
76
+ }
77
+ }
78
 
79
+ /* Update settings in the database */
80
+ if ( empty( $error ) ) {
81
+ update_option( 'swpsmtp_options', $swpsmtp_options );
82
+ $message .= __( "Settings saved.", 'easy-wp-smtp' );
83
+ } else {
84
+ $error .= " " . __( "Settings are not saved.", 'easy-wp-smtp' );
85
  }
86
+ }
87
+
88
+ /* Send test letter */
89
+ $swpsmtp_to = '';
90
+ if ( isset( $_POST[ 'swpsmtp_test_submit' ] ) && check_admin_referer( plugin_basename( __FILE__ ), 'swpsmtp_nonce_name' ) ) {
91
+ if ( isset( $_POST[ 'swpsmtp_to' ] ) ) {
92
+ $to_email = sanitize_text_field( $_POST[ 'swpsmtp_to' ] );
93
+ if ( is_email( $to_email ) ) {
94
+ $swpsmtp_to = $to_email;
95
+ } else {
96
+ $error .= __( "Please enter a valid email address in the recipient email field.", 'easy-wp-smtp' );
97
+ }
 
 
 
 
 
 
 
98
  }
99
+ $swpsmtp_subject = isset( $_POST[ 'swpsmtp_subject' ] ) ? sanitize_text_field( $_POST[ 'swpsmtp_subject' ] ) : '';
100
+ $swpsmtp_message = isset( $_POST[ 'swpsmtp_message' ] ) ? sanitize_textarea_field( $_POST[ 'swpsmtp_message' ] ) : '';
101
+
102
+ //Save the test mail details so it doesn't need to be filled in everytime.
103
+ $smtp_test_mail[ 'swpsmtp_to' ] = $swpsmtp_to;
104
+ $smtp_test_mail[ 'swpsmtp_subject' ] = $swpsmtp_subject;
105
+ $smtp_test_mail[ 'swpsmtp_message' ] = $swpsmtp_message;
106
+ update_option( 'smtp_test_mail', $smtp_test_mail );
107
+
108
+ if ( ! empty( $swpsmtp_to ) ) {
109
+ $result = swpsmtp_test_mail( $swpsmtp_to, $swpsmtp_subject, $swpsmtp_message );
110
+ }
111
+ }
112
+
113
+ ?>
114
+ <style>
115
+ div.swpsmtp-tab-container, #swpsmtp-save-settings-notice {
116
+ display: none;
117
+ }
118
+ #swpsmtp-save-settings-notice {
119
+ padding: 10px 0;
120
+ }
121
+ #swpsmtp-save-settings-notice span {
122
+ background-color: #ffff76;
123
+ padding: 7px;
124
+ border: 1px dashed red;
125
+ display: block;
126
+ }
127
+ </style>
128
+ <div class="updated fade" <?php if ( empty( $message ) ) echo "style=\"display:none\""; ?>>
129
+ <p><strong><?php echo $message; ?></strong></p>
130
+ </div>
131
+ <div class="error" <?php if ( empty( $error ) ) echo "style=\"display:none\""; ?>>
132
+ <p><strong><?php echo $error; ?></strong></p>
133
+ </div>
134
+
135
+ <div class="nav-tab-wrapper">
136
+ <a href="#smtp" data-tab-name="smtp" class="nav-tab"><?php _e( 'SMTP Settings', 'easy-wp-smtp' ); ?></a>
137
+ <a href="#additional" data-tab-name="additional" class="nav-tab"><?php _e( 'Additional Settings', 'easy-wp-smtp' ); ?></a>
138
+ <a href="#testemail" data-tab-name="testemail" class="nav-tab"><?php _e( 'Test Email', 'easy-wp-smtp' ); ?></a>
139
+ </div>
140
+
141
+ <div class="swpsmtp-yellow-box">
142
+ <?php _ex( sprintf( "Please visit the %s plugin's documentation page to learn how to use this plugin.", '<a target="_blank" href="https://wp-ecommerce.net/easy-wordpress-smtp-send-emails-from-your-wordpress-site-using-a-smtp-server-2197">Easy WP SMTP</a>' ), '%s is replaced by <a target="_blank" href="https://wp-ecommerce.net/easy-wordpress-smtp-send-emails-from-your-wordpress-site-using-a-smtp-server-2197">Easy WP SMTP</a>', 'easy-wp-smtp' ); ?>
143
+ </div>
144
+
145
+ <form id="swpsmtp_settings_form" method="post" action="">
146
+
147
+ <input type="hidden" id="swpsmtp-urlHash" name="swpsmtp-urlHash" value="">
148
+
149
+ <div class="swpsmtp-tab-container" data-tab-name="smtp">
150
+ <div class="postbox">
151
+ <h3 class="hndle"><label for="title"><?php _e( 'SMTP Configuration Settings', 'easy-wp-smtp' ); ?></label></h3>
152
+ <div class="inside">
153
+
154
+ <p><?php _e( 'You can request your hosting provider for the SMTP details of your site. Use the SMTP details provided by your hosting provider to configure the following settings.', 'easy-wp-smtp' ) ?></p>
155
+
156
+ <table class="form-table">
157
+ <tr valign="top">
158
+ <th scope="row"><?php _e( "From Email Address", 'easy-wp-smtp' ); ?></th>
159
+ <td>
160
+ <input type="text" name="swpsmtp_from_email" value="<?php echo isset( $swpsmtp_options[ 'from_email_field' ] ) ? esc_attr( $swpsmtp_options[ 'from_email_field' ] ) : ''; ?>"/><br />
161
+ <p class="description"><?php _e( "This email address will be used in the 'From' field.", 'easy-wp-smtp' ); ?></p>
162
+ </td>
163
+ </tr>
164
+ <tr valign="top">
165
+ <th scope="row"><?php _e( "From Name", 'easy-wp-smtp' ); ?></th>
166
+ <td>
167
+ <input type="text" name="swpsmtp_from_name" value="<?php echo isset( $swpsmtp_options[ 'from_name_field' ] ) ? esc_attr( $swpsmtp_options[ 'from_name_field' ] ) : ''; ?>"/><br />
168
+ <p class="description"><?php _e( "This text will be used in the 'FROM' field", 'easy-wp-smtp' ); ?></p>
169
+ </td>
170
+ </tr>
171
+ <tr valign="top">
172
+ <th scope="row"><?php _e( "Reply-To Email Address", 'easy-wp-smtp' ); ?></th>
173
+ <td>
174
+ <input type="email" name="swpsmtp_reply_to_email" value="<?php echo isset( $swpsmtp_options[ 'reply_to_email' ] ) ? esc_attr( $swpsmtp_options[ 'reply_to_email' ] ) : ''; ?>"/><br />
175
+ <p class="description"><?php _e( "Optional. This email address will be used in the 'Reply-To' field of the email. Leave it blank to use 'From' email as the reply-to value.", 'easy-wp-smtp' ); ?></p>
176
+ </td>
177
+ </tr>
178
+ <tr class="ad_opt swpsmtp_smtp_options">
179
+ <th><?php _e( 'SMTP Host', 'easy-wp-smtp' ); ?></th>
180
+ <td>
181
+ <input type='text' name='swpsmtp_smtp_host' value='<?php echo isset( $swpsmtp_options[ 'smtp_settings' ][ 'host' ] ) ? esc_attr( $swpsmtp_options[ 'smtp_settings' ][ 'host' ] ) : ''; ?>' /><br />
182
+ <p class="description"><?php _e( "Your mail server", 'easy-wp-smtp' ); ?></p>
183
+ </td>
184
+ </tr>
185
+ <tr class="ad_opt swpsmtp_smtp_options">
186
+ <th><?php _e( 'Type of Encryption', 'easy-wp-smtp' ); ?></th>
187
+ <td>
188
+ <label for="swpsmtp_smtp_type_encryption_1"><input type="radio" id="swpsmtp_smtp_type_encryption_1" name="swpsmtp_smtp_type_encryption" value='none' <?php if ( isset( $swpsmtp_options[ 'smtp_settings' ][ 'type_encryption' ] ) && 'none' == $swpsmtp_options[ 'smtp_settings' ][ 'type_encryption' ] ) echo 'checked="checked"'; ?> /> <?php _e( 'None', 'easy-wp-smtp' ); ?></label>
189
+ <label for="swpsmtp_smtp_type_encryption_2"><input type="radio" id="swpsmtp_smtp_type_encryption_2" name="swpsmtp_smtp_type_encryption" value='ssl' <?php if ( isset( $swpsmtp_options[ 'smtp_settings' ][ 'type_encryption' ] ) && 'ssl' == $swpsmtp_options[ 'smtp_settings' ][ 'type_encryption' ] ) echo 'checked="checked"'; ?> /> <?php _e( 'SSL', 'easy-wp-smtp' ); ?></label>
190
+ <label for="swpsmtp_smtp_type_encryption_3"><input type="radio" id="swpsmtp_smtp_type_encryption_3" name="swpsmtp_smtp_type_encryption" value='tls' <?php if ( isset( $swpsmtp_options[ 'smtp_settings' ][ 'type_encryption' ] ) && 'tls' == $swpsmtp_options[ 'smtp_settings' ][ 'type_encryption' ] ) echo 'checked="checked"'; ?> /> <?php _e( 'TLS', 'easy-wp-smtp' ); ?></label><br />
191
+ <p class="description"><?php _e( "For most servers SSL is the recommended option", 'easy-wp-smtp' ); ?></p>
192
+ </td>
193
+ </tr>
194
+ <tr class="ad_opt swpsmtp_smtp_options">
195
+ <th><?php _e( 'SMTP Port', 'easy-wp-smtp' ); ?></th>
196
+ <td>
197
+ <input type='text' name='swpsmtp_smtp_port' value='<?php echo isset( $swpsmtp_options[ 'smtp_settings' ][ 'port' ] ) ? esc_attr( $swpsmtp_options[ 'smtp_settings' ][ 'port' ] ) : ''; ?>' /><br />
198
+ <p class="description"><?php _e( "The port to your mail server", 'easy-wp-smtp' ); ?></p>
199
+ </td>
200
+ </tr>
201
+ <tr class="ad_opt swpsmtp_smtp_options">
202
+ <th><?php _e( 'SMTP Authentication', 'easy-wp-smtp' ); ?></th>
203
+ <td>
204
+ <label for="swpsmtp_smtp_autentication"><input type="radio" id="swpsmtp_smtp_autentication" name="swpsmtp_smtp_autentication" value='no' <?php if ( isset( $swpsmtp_options[ 'smtp_settings' ][ 'autentication' ] ) && 'no' == $swpsmtp_options[ 'smtp_settings' ][ 'autentication' ] ) echo 'checked="checked"'; ?> /> <?php _e( 'No', 'easy-wp-smtp' ); ?></label>
205
+ <label for="swpsmtp_smtp_autentication"><input type="radio" id="swpsmtp_smtp_autentication" name="swpsmtp_smtp_autentication" value='yes' <?php if ( isset( $swpsmtp_options[ 'smtp_settings' ][ 'autentication' ] ) && 'yes' == $swpsmtp_options[ 'smtp_settings' ][ 'autentication' ] ) echo 'checked="checked"'; ?> /> <?php _e( 'Yes', 'easy-wp-smtp' ); ?></label><br />
206
+ <p class="description"><?php _e( "This options should always be checked 'Yes'", 'easy-wp-smtp' ); ?></p>
207
+ </td>
208
+ </tr>
209
+ <tr class="ad_opt swpsmtp_smtp_options">
210
+ <th><?php _e( 'SMTP username', 'easy-wp-smtp' ); ?></th>
211
+ <td>
212
+ <input type='text' name='swpsmtp_smtp_username' value='<?php echo isset( $swpsmtp_options[ 'smtp_settings' ][ 'username' ] ) ? esc_attr( $swpsmtp_options[ 'smtp_settings' ][ 'username' ] ) : ''; ?>' /><br />
213
+ <p class="description"><?php _e( "The username to login to your mail server", 'easy-wp-smtp' ); ?></p>
214
+ </td>
215
+ </tr>
216
+ <tr class="ad_opt swpsmtp_smtp_options">
217
+ <th><?php _e( 'SMTP Password', 'easy-wp-smtp' ); ?></th>
218
+ <td>
219
+ <input type='password' name='swpsmtp_smtp_password' value='<?php echo (swpsmtp_get_password() !== '' ? $gag_password : ''); ?>' /><br />
220
+ <p class="description"><?php _e( "The password to login to your mail server", 'easy-wp-smtp' ); ?></p>
221
+ </td>
222
+ </tr>
223
+ </table>
224
+ <p class="submit">
225
+ <input type="submit" id="settings-form-submit" class="button-primary" value="<?php _e( 'Save Changes', 'easy-wp-smtp' ) ?>" />
226
+ <input type="hidden" name="swpsmtp_form_submit" value="submit" />
227
+ <?php wp_nonce_field( plugin_basename( __FILE__ ), 'swpsmtp_nonce_name' ); ?>
228
+ </p>
229
+ </div><!-- end of inside -->
230
+ </div><!-- end of postbox -->
231
+ </div>
232
+
233
+ <div class="swpsmtp-tab-container" data-tab-name="additional">
234
+ <div class="postbox">
235
+ <h3 class="hndle"><label for="title"><?php _e( 'Additional Settings (Optional)', 'easy-wp-smtp' ); ?></label></h3>
236
+ <div class="inside">
237
+ <table class="form-table">
238
+ <tr valign="top">
239
+ <th scope="row"><?php _e( "Don't Replace \"From\" Field", 'easy-wp-smtp' ); ?></th>
240
+ <td>
241
+ <input type="text" name="swpsmtp_email_ignore_list" value="<?php echo isset( $swpsmtp_options[ 'email_ignore_list' ] ) ? esc_attr( $swpsmtp_options[ 'email_ignore_list' ] ) : ''; ?>"/><br />
242
+ <p class="description"><?php _e( "Comma separated emails list. Example value: email1@domain.com, email2@domain.com", "easy-wp-smtp" ); ?></p>
243
+ <p class="description"><?php _e( "This option is useful when you are using several email aliases on your SMTP server. If you don't want your aliases to be replaced by the address specified in \"From\" field, enter them in this field.", 'easy-wp-smtp' ); ?></p>
244
+ </td>
245
+ </tr>
246
+ <tr valign="top">
247
+ <th scope="row"><?php _e( "Enable Domain Check", 'easy-wp-smtp' ); ?></th>
248
+ <td>
249
+ <input type="checkbox" id="swpsmtp_enable_domain_check" name="swpsmtp_enable_domain_check" value="1"<?php echo (isset( $swpsmtp_options[ 'enable_domain_check' ] ) && ($swpsmtp_options[ 'enable_domain_check' ])) ? ' checked' : ''; ?>/>
250
+ <p class="description"><?php _e( "This option is usually used by developers only. SMTP settings will be used only if the site is running on following domain(s):", 'easy-wp-smtp' ); ?></p>
251
+ <input type="text" name="swpsmtp_allowed_domains" value="<?php echo base64_decode_maybe( $swpsmtp_options[ 'allowed_domains' ] ); ?>"<?php echo (isset( $swpsmtp_options[ 'enable_domain_check' ] ) && ($swpsmtp_options[ 'enable_domain_check' ])) ? '' : ' disabled'; ?>/>
252
+ <p class="description"><?php _e( "Coma-separated domains list. Example: domain1.com, domain2.com", 'easy-wp-smtp' ); ?></p>
253
+ <p>
254
+ <label><input type="checkbox" id="swpsmtp_block_all_emails" name="swpsmtp_block_all_emails" value="1"<?php echo (isset( $swpsmtp_options[ 'block_all_emails' ] ) && ($swpsmtp_options[ 'block_all_emails' ])) ? ' checked' : ''; ?><?php echo (isset( $swpsmtp_options[ 'enable_domain_check' ] ) && ($swpsmtp_options[ 'enable_domain_check' ])) ? '' : ' disabled'; ?>/> <?php _e( 'Block all emails', 'easy-wp-smtp' ); ?></label>
255
+ </p>
256
+ <p class="description"><?php _e( "When enabled, plugin attempts to block ALL emails from being sent out if domain mismtach." ); ?></p>
257
+ </td>
258
+ </tr>
259
+ <tr valign="top">
260
+ <th scope="row"><?php _e( "Enable Debug Log", 'easy-wp-smtp' ); ?></th>
261
+ <td>
262
+ <input type="checkbox" name="swpsmtp_enable_debug" value="1" <?php echo (isset( $swpsmtp_options[ 'smtp_settings' ][ 'enable_debug' ] ) && ($swpsmtp_options[ 'smtp_settings' ][ 'enable_debug' ])) ? 'checked' : ''; ?>/>
263
+ <p class="description"><?php _e( "Check this box to enable mail debug log", 'easy-wp-smtp' ); ?></p>
264
+ <a href="<?php echo admin_url(); ?>?swpsmtp_action=view_log" target="_blank"><?php _e( 'View Log', 'easy-wp-smtp' ); ?></a> | <a style="color: red;" id="swpsmtp_clear_log_btn" href="#0"><?php _e( 'Clear Log', 'easy-wp-smtp' ); ?></a>
265
+ </td>
266
+ </tr>
267
+ </table>
268
+ <p class="submit">
269
+ <input type="submit" id="settings-form-submit" class="button-primary" value="<?php _e( 'Save Changes', 'easy-wp-smtp' ) ?>" />
270
+ <input type="hidden" name="swpsmtp_form_submit" value="submit" />
271
+ <?php wp_nonce_field( plugin_basename( __FILE__ ), 'swpsmtp_nonce_name' ); ?>
272
+ </p>
273
+
274
+ </div><!-- end of inside -->
275
+ </div><!-- end of postbox -->
276
+ </div>
277
+ </form>
278
+
279
+ <div class="swpsmtp-tab-container" data-tab-name="testemail">
280
+ <div class="postbox">
281
+ <h3 class="hndle"><label for="title"><?php _e( 'Test Email', 'easy-wp-smtp' ); ?></label></h3>
282
+ <div class="inside">
283
+ <div id="swpsmtp-save-settings-notice"><span><b><?php _e( 'Notice:', 'easy-wp-smtp' ); ?></b> <?php _e( 'You have unsaved settings. In order to send a test email, you need to go back to previous tab and click "Save Changes" button first.', 'easy-wp-smtp' ); ?></span></div>
284
+ <p><?php _e( 'You can use this section to send an email from your server using the above configured SMTP details to see if the email gets delivered.', 'easy-wp-smtp' ); ?></p>
285
+ <p><b><?php _ex( 'Note:', '"Note" as in "Note: keep this in mind"', 'easy-wp-smtp' ); ?></b> <?php _e( 'debug log for this test email will be automatically displayed right after you send it. Test email also ignores "Enable Domain Check" option.', 'easy-wp-smtp' ); ?></p>
286
+
287
+ <form id="swpsmtp_settings_form" method="post" action="">
288
+ <table class="form-table">
289
+ <tr valign="top">
290
+ <th scope="row"><?php _e( "To", 'easy-wp-smtp' ); ?>:</th>
291
+ <td>
292
+ <input type="text" name="swpsmtp_to" value="<?php echo esc_html( $smtp_test_mail[ 'swpsmtp_to' ] ); ?>" /><br />
293
+ <p class="description"><?php _e( "Enter the recipient's email address", 'easy-wp-smtp' ); ?></p>
294
+ </td>
295
+ </tr>
296
+ <tr valign="top">
297
+ <th scope="row"><?php _e( "Subject", 'easy-wp-smtp' ); ?>:</th>
298
+ <td>
299
+ <input type="text" name="swpsmtp_subject" value="<?php echo esc_html( $smtp_test_mail[ 'swpsmtp_subject' ] ); ?>" /><br />
300
+ <p class="description"><?php _e( "Enter a subject for your message", 'easy-wp-smtp' ); ?></p>
301
+ </td>
302
+ </tr>
303
+ <tr valign="top">
304
+ <th scope="row"><?php _e( "Message", 'easy-wp-smtp' ); ?>:</th>
305
+ <td>
306
+ <textarea name="swpsmtp_message" id="swpsmtp_message" rows="5"><?php echo stripslashes( esc_textarea( $smtp_test_mail[ 'swpsmtp_message' ] ) ); ?></textarea><br />
307
+ <p class="description"><?php _e( "Write your email message", 'easy-wp-smtp' ); ?></p>
308
+ </td>
309
+ </tr>
310
+ </table>
311
+ <p class="submit">
312
+ <input type="submit" id="settings-form-submit" class="button-primary" value="<?php _e( 'Send Test Email', 'easy-wp-smtp' ) ?>" />
313
+ <input type="hidden" name="swpsmtp_test_submit" value="submit" />
314
+ <?php wp_nonce_field( plugin_basename( __FILE__ ), 'swpsmtp_nonce_name' ); ?>
315
+ </p>
316
+ </form>
317
+ </div><!-- end of inside -->
318
+ </div><!-- end of postbox -->
319
+
320
+ </div>
321
+ <div class="swpsmtp-yellow-box">
322
+ <?php _ex( sprintf( "Please visit the %s plugin's documentation page to learn how to use this plugin.", '<a target="_blank" href="https://wp-ecommerce.net/easy-wordpress-smtp-send-emails-from-your-wordpress-site-using-a-smtp-server-2197">Easy WP SMTP</a>' ), '%s is replaced by <a target="_blank" href="https://wp-ecommerce.net/easy-wordpress-smtp-send-emails-from-your-wordpress-site-using-a-smtp-server-2197">Easy WP SMTP</a>', 'easy-wp-smtp' ); ?>
323
+ </div>
324
+
325
+ <script>
326
+ var swpsmtp_urlHash = window.location.hash.substr(1);
327
+
328
+ if (swpsmtp_urlHash === '') {
329
+ swpsmtp_urlHash = 'smtp';
330
+ }
331
+ jQuery(function ($) {
332
+ var swpsmtp_activeTab = "";
333
+ $('a.nav-tab').click(function (e) {
334
+ if ($(this).attr('data-tab-name') !== swpsmtp_activeTab) {
335
+ $('div.swpsmtp-tab-container[data-tab-name="' + swpsmtp_activeTab + '"]').hide();
336
+ $('a.nav-tab[data-tab-name="' + swpsmtp_activeTab + '"]').removeClass('nav-tab-active');
337
+ swpsmtp_activeTab = $(this).attr('data-tab-name');
338
+ $('div.swpsmtp-tab-container[data-tab-name="' + swpsmtp_activeTab + '"]').show();
339
+ $(this).addClass('nav-tab-active');
340
+ $('input#swpsmtp-urlHash').val(swpsmtp_activeTab);
341
+ if (window.location.hash !== swpsmtp_activeTab) {
342
+ window.location.hash = swpsmtp_activeTab;
343
+ }
344
+ }
345
+ });
346
+ $('a.nav-tab[data-tab-name="' + swpsmtp_urlHash + '"]').trigger('click');
347
+ });
348
+
349
+ jQuery(function ($) {
350
+ $('#swpsmtp-mail input').change(function () {
351
+ $('#swpsmtp-save-settings-notice').show();
352
+ ;
353
+ });
354
+ $('#swpsmtp_enable_domain_check').change(function () {
355
+ $('input[name="swpsmtp_allowed_domains"]').prop('disabled', !$(this).is(':checked'));
356
+ $('input[name="swpsmtp_block_all_emails"]').prop('disabled', !$(this).is(':checked'));
357
+ });
358
+ $('#swpsmtp_clear_log_btn').click(function (e) {
359
+ e.preventDefault();
360
+ if (confirm("<?php _e( 'Are you sure want to clear log?', 'easy-wp-smtp' ); ?>")) {
361
+ var req = jQuery.ajax({
362
+ url: ajaxurl,
363
+ type: "post",
364
+ data: {action: "swpsmtp_clear_log"}
365
+ });
366
+ req.done(function (data) {
367
+ if (data === '1') {
368
+ alert("<?php _e( 'Log cleared.', 'easy-wp-smtp' ); ?>");
369
+ } else {
370
+ alert("Error occured: " + data);
371
+ }
372
+ });
373
+ }
374
+ });
375
+ });
376
+
377
+ </script>
378
+
379
+ <?php
380
+ echo '</div></div>'; //<!-- end of #poststuff and #post-body -->
381
+ echo '</div>'; //<!-- end of .wrap #swpsmtp-mail .swpsmtp-mail -->
382
  }
383
 
384
  /**
385
+ * Plugin functions for init
386
  * @return void
387
  */
388
+ function swpsmtp_admin_init() {
389
+ /* Internationalization, first(!) */
390
+ load_plugin_textdomain( 'easy-wp-smtp', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
391
+
392
+ add_action( 'wp_ajax_swpsmtp_clear_log', 'swpsmtp_clear_log' );
393
+ //view log file
394
+ if ( isset( $_GET[ 'swpsmtp_action' ] ) ) {
395
+ if ( $_GET[ 'swpsmtp_action' ] === 'view_log' ) {
396
+ $swpsmtp_options = get_option( 'swpsmtp_options' );
397
+ $log_file_name = $swpsmtp_options[ 'smtp_settings' ][ 'log_file_name' ];
398
+ if ( ! file_exists( plugin_dir_path( __FILE__ ) . $log_file_name ) ) {
399
+ if ( swpsmtp_write_to_log( "Easy WP SMTP debug log file\r\n\r\n" ) === false ) {
400
+ wp_die( 'Can\'t write to log file. Check if plugin directory (' . plugin_dir_path( __FILE__ ) . ') is writeable.' );
401
+ };
402
+ }
403
+ $logfile = fopen( plugin_dir_path( __FILE__ ) . $log_file_name, 'rb' );
404
+ if ( ! $logfile ) {
405
+ wp_die( 'Can\'t open log file.' );
406
+ }
407
+ header( 'Content-Type: text/plain' );
408
+ fpassthru( $logfile );
409
+ die;
410
  }
411
+ }
412
  }
easy-wp-smtp.php CHANGED
@@ -1,7 +1,7 @@
1
  <?php
2
  /*
3
  Plugin Name: Easy WP SMTP
4
- Version: 1.3.1
5
  Plugin URI: https://wp-ecommerce.net/easy-wordpress-smtp-send-emails-from-your-wordpress-site-using-a-smtp-server-2197
6
  Author: wpecommerce
7
  Author URI: https://wp-ecommerce.net/
@@ -20,20 +20,20 @@ include_once('easy-wp-smtp-admin-menu.php');
20
  * @param $file string relative path to pugin "easy-wp-smtp/easy-wp-smtp.php"
21
  * @return $links array() action links
22
  */
23
- if ( !function_exists( 'swpsmtp_plugin_action_links' ) ) {
24
 
25
- function swpsmtp_plugin_action_links( $links, $file ) {
26
- /* Static so we don't call plugin_basename on every plugin row. */
27
- static $this_plugin;
28
- if ( !$this_plugin ) {
29
- $this_plugin = plugin_basename( __FILE__ );
30
- }
31
- if ( $file == $this_plugin ) {
32
- $settings_link = '<a href="options-general.php?page=swpsmtp_settings">' . __( 'Settings', 'easy-wp-smtp' ) . '</a>';
33
- array_unshift( $links, $settings_link );
34
- }
35
- return $links;
36
  }
 
 
 
 
 
 
37
 
38
  }
39
 
@@ -43,24 +43,24 @@ if ( !function_exists( 'swpsmtp_plugin_action_links' ) ) {
43
  * @param $file string relative path to pugin "easy-wp-smtp/easy-wp-smtp.php"
44
  * @return $links array() action links
45
  */
46
- if ( !function_exists( 'swpsmtp_register_plugin_links' ) ) {
47
 
48
- function swpsmtp_register_plugin_links( $links, $file ) {
49
- $base = plugin_basename( __FILE__ );
50
- if ( $file == $base ) {
51
- $links[] = '<a href="options-general.php?page=swpsmtp_settings">' . __( 'Settings', 'easy-wp-smtp' ) . '</a>';
52
- }
53
- return $links;
54
  }
 
 
55
 
56
  }
57
 
58
  //plugins_loaded action hook handler
59
- if ( !function_exists( 'swpsmtp_plugins_loaded_handler' ) ) {
60
 
61
- function swpsmtp_plugins_loaded_handler() {
62
- load_plugin_textdomain( 'easy-wp-smtp', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
63
- }
64
 
65
  }
66
 
@@ -69,138 +69,137 @@ if ( !function_exists( 'swpsmtp_plugins_loaded_handler' ) ) {
69
  * Function to add plugin scripts
70
  * @return void
71
  */
72
- if ( !function_exists( 'swpsmtp_admin_head' ) ) {
73
-
74
- function swpsmtp_admin_head() {
75
- wp_enqueue_style( 'swpsmtp_stylesheet', plugins_url( 'css/style.css', __FILE__ ) );
76
 
77
- if ( isset( $_REQUEST['page'] ) && 'swpsmtp_settings' == $_REQUEST['page'] ) {
78
- wp_enqueue_script( 'swpsmtp_script', plugins_url( 'js/script.js', __FILE__ ), array( 'jquery' ) );
79
- }
80
- }
81
 
82
  }
83
 
84
  function swpsmtp_clear_log() {
85
- if ( swpsmtp_write_to_log( "Easy WP SMTP debug log file\r\n\r\n", true ) !== false ) {
86
- echo '1';
87
- } else {
88
- echo 'Can\'t clear log - log file is not writeable.';
89
- }
90
- wp_die();
91
  }
92
 
93
  function swpsmtp_write_to_log( $str, $overwrite = false ) {
94
- $swpsmtp_options = get_option( 'swpsmtp_options' );
95
- if ( isset( $swpsmtp_options['smtp_settings']['log_file_name'] ) ) {
96
- $log_file_name = $swpsmtp_options['smtp_settings']['log_file_name'];
97
- } else {
98
- // let's generate log file name
99
- $log_file_name = uniqid() . '_debug_log.txt';
100
- $swpsmtp_options['smtp_settings']['log_file_name'] = $log_file_name;
101
- update_option( 'swpsmtp_options', $swpsmtp_options );
102
- file_put_contents( plugin_dir_path( __FILE__ ) . $log_file_name, "Easy WP SMTP debug log file\r\n\r\n" );
103
- }
104
- return(file_put_contents( plugin_dir_path( __FILE__ ) . $log_file_name, $str, (!$overwrite ? FILE_APPEND : 0 ) ));
105
  }
106
 
107
  function base64_decode_maybe( $str ) {
108
- if ( mb_detect_encoding( $str ) === mb_detect_encoding( base64_decode( base64_encode( base64_decode( $str ) ) ) ) ) {
109
- $str = base64_decode( $str );
110
- }
111
- return $str;
 
 
 
112
  }
113
 
114
  /**
115
  * Function to add smtp options in the phpmailer_init
116
  * @return void
117
  */
118
- if ( !function_exists( 'swpsmtp_init_smtp' ) ) {
119
 
120
- function swpsmtp_init_smtp( &$phpmailer ) {
121
- //check if SMTP credentials have been configured.
122
- if ( !swpsmtp_credentials_configured() ) {
123
- return;
124
- }
125
- $swpsmtp_options = get_option( 'swpsmtp_options' );
126
- //check if Domain Check enabled
127
- $domain = swpsmtp_is_domain_blocked();
128
- if ( $domain !== false ) {
129
- //domain check failed
130
- //let's check if we have block all emails option enabled
131
- if ( isset( $swpsmtp_options['block_all_emails'] ) && $swpsmtp_options['block_all_emails'] === 1 ) {
132
- // it's enabled. Let's use gag mailer class that would prevent emails from being sent out.
133
- $phpmailer = new swpsmtp_gag_mailer();
134
- } else {
135
- // it's disabled. Let's write some info to the log
136
- swpsmtp_write_to_log(
137
- "\r\n------------------------------------------------------------------------------------------------------\r\n" .
138
- "Domain check failed: website domain (" . $domain . ") is not in allowed domains list.\r\n" .
139
- "SMTP settings won't be used.\r\n" .
140
- "------------------------------------------------------------------------------------------------------\r\n\r\n" );
141
- }
142
- return;
143
- }
144
- /* Set the mailer type as per config above, this overrides the already called isMail method */
145
- $phpmailer->IsSMTP();
146
- $from_name = $swpsmtp_options['from_name_field'];
147
- $from_email = $swpsmtp_options['from_email_field'];
148
- //set ReplyTo option if needed
149
- //this should be set before SetFrom, otherwise might be ignored
150
- if ( !empty( $swpsmtp_options['reply_to_email'] ) ) {
151
- $phpmailer->AddReplyTo( $swpsmtp_options['reply_to_email'], $from_name );
152
- }
153
- // let's see if we have email ignore list populated
154
- if ( isset( $swpsmtp_options['email_ignore_list'] ) && !empty( $swpsmtp_options['email_ignore_list'] ) ) {
155
- $emails_arr = explode( ',', $swpsmtp_options['email_ignore_list'] );
156
- if ( is_array( $emails_arr ) && !empty( $emails_arr ) ) {
157
- //we have coma-separated list
158
- } else {
159
- //it's single email
160
- unset( $emails_arr );
161
- $emails_arr = array( $swpsmtp_options['email_ignore_list'] );
162
- }
163
- $from = $phpmailer->From;
164
- $match_found = false;
165
- foreach ( $emails_arr as $email ) {
166
- if ( strtolower( trim( $email ) ) === strtolower( trim( $from ) ) ) {
167
- $match_found = true;
168
- break;
169
- }
170
- }
171
- if ( $match_found ) {
172
- //we should not override From and Fromname
173
- $from_email = $phpmailer->From;
174
- $from_name = $phpmailer->FromName;
175
- }
176
- }
177
- $phpmailer->From = $from_email;
178
- $phpmailer->FromName = $from_name;
179
- $phpmailer->SetFrom( $phpmailer->From, $phpmailer->FromName );
180
- /* Set the SMTPSecure value */
181
- if ( $swpsmtp_options['smtp_settings']['type_encryption'] !== 'none' ) {
182
- $phpmailer->SMTPSecure = $swpsmtp_options['smtp_settings']['type_encryption'];
183
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
184
 
185
- /* Set the other options */
186
- $phpmailer->Host = $swpsmtp_options['smtp_settings']['host'];
187
- $phpmailer->Port = $swpsmtp_options['smtp_settings']['port'];
188
 
189
- /* If we're using smtp auth, set the username & password */
190
- if ( 'yes' == $swpsmtp_options['smtp_settings']['autentication'] ) {
191
- $phpmailer->SMTPAuth = true;
192
- $phpmailer->Username = $swpsmtp_options['smtp_settings']['username'];
193
- $phpmailer->Password = swpsmtp_get_password();
194
- }
195
  //PHPMailer 5.2.10 introduced this option. However, this might cause issues if the server is advertising TLS with an invalid certificate.
196
- $phpmailer->SMTPAutoTLS = false;
197
- if ( isset( $swpsmtp_options['smtp_settings']['enable_debug'] ) && $swpsmtp_options['smtp_settings']['enable_debug'] ) {
198
- $phpmailer->Debugoutput = function($str, $level) {
199
- swpsmtp_write_to_log( $str );
200
- };
201
- $phpmailer->SMTPDebug = 1;
202
- }
203
  }
 
204
 
205
  }
206
 
@@ -208,139 +207,139 @@ if ( !function_exists( 'swpsmtp_init_smtp' ) ) {
208
  * Function to test mail sending
209
  * @return text or errors
210
  */
211
- if ( !function_exists( 'swpsmtp_test_mail' ) ) {
212
 
213
- function swpsmtp_test_mail( $to_email, $subject, $message ) {
214
- if ( !swpsmtp_credentials_configured() ) {
215
- return;
216
- }
217
- $errors = '';
218
 
219
- $swpsmtp_options = get_option( 'swpsmtp_options' );
220
 
221
- require_once( ABSPATH . WPINC . '/class-phpmailer.php' );
222
- $mail = new PHPMailer();
223
 
224
- $charset = get_bloginfo( 'charset' );
225
- $mail->CharSet = $charset;
226
 
227
- $from_name = $swpsmtp_options['from_name_field'];
228
- $from_email = $swpsmtp_options['from_email_field'];
229
 
230
- $mail->IsSMTP();
231
 
232
- /* If using smtp auth, set the username & password */
233
- if ( 'yes' == $swpsmtp_options['smtp_settings']['autentication'] ) {
234
- $mail->SMTPAuth = true;
235
- $mail->Username = $swpsmtp_options['smtp_settings']['username'];
236
- $mail->Password = swpsmtp_get_password();
237
- }
238
 
239
- /* Set the SMTPSecure value, if set to none, leave this blank */
240
- if ( $swpsmtp_options['smtp_settings']['type_encryption'] !== 'none' ) {
241
- $mail->SMTPSecure = $swpsmtp_options['smtp_settings']['type_encryption'];
242
- }
243
 
244
- /* PHPMailer 5.2.10 introduced this option. However, this might cause issues if the server is advertising TLS with an invalid certificate. */
245
- $mail->SMTPAutoTLS = false;
246
 
247
- /* Set the other options */
248
- $mail->Host = $swpsmtp_options['smtp_settings']['host'];
249
- $mail->Port = $swpsmtp_options['smtp_settings']['port'];
250
- if ( !empty( $swpsmtp_options['reply_to_email'] ) ) {
251
- $mail->AddReplyTo( $swpsmtp_options['reply_to_email'], $from_name );
252
- }
253
- $mail->SetFrom( $from_email, $from_name );
254
- $mail->isHTML( true );
255
- $mail->Subject = $subject;
256
- $mail->MsgHTML( $message );
257
- $mail->AddAddress( $to_email );
258
- global $debugMSG;
259
- $debugMSG = '';
260
- $mail->Debugoutput = function($str, $level) {
261
- global $debugMSG;
262
- $debugMSG .= $str;
263
- };
264
- $mail->SMTPDebug = 1;
265
-
266
- /* Send mail and return result */
267
- if ( !$mail->Send() )
268
- $errors = $mail->ErrorInfo;
269
-
270
- $mail->ClearAddresses();
271
- $mail->ClearAllRecipients();
272
-
273
- echo '<div class="swpsmtp-yellow-box"><h3>Debug Info</h3>';
274
- echo '<textarea rows="20" style="width: 100%;">' . $debugMSG . '</textarea>';
275
- echo '</div>';
276
-
277
- if ( !empty( $errors ) ) {
278
- return $errors;
279
- } else {
280
- return 'Test mail was sent';
281
- }
282
  }
 
283
 
284
  }
285
 
286
- if ( !function_exists( 'swpsmtp_get_password' ) ) {
287
 
288
- function swpsmtp_get_password() {
289
- $swpsmtp_options = get_option( 'swpsmtp_options' );
290
- $temp_password = isset( $swpsmtp_options['smtp_settings']['password'] ) ? $swpsmtp_options['smtp_settings']['password'] : '';
291
- if ( $temp_password == '' ) {
292
- return '';
293
- }
294
- $password = "";
295
- $decoded_pass = base64_decode( $temp_password );
296
- /* no additional checks for servers that aren't configured with mbstring enabled */
297
- if ( !function_exists( 'mb_detect_encoding' ) ) {
298
- return $decoded_pass;
299
- }
300
- /* end of mbstring check */
301
- if ( base64_encode( $decoded_pass ) === $temp_password ) { //it might be encoded
302
- if ( false === mb_detect_encoding( $decoded_pass ) ) { //could not find character encoding.
303
- $password = $temp_password;
304
- } else {
305
- $password = base64_decode( $temp_password );
306
- }
307
- } else { //not encoded
308
- $password = $temp_password;
309
- }
310
- return stripslashes( $password );
311
  }
 
 
 
 
 
 
 
 
 
 
 
 
312
 
313
  }
314
 
315
- if ( !function_exists( 'swpsmtp_admin_notice' ) ) {
316
 
317
- function swpsmtp_admin_notice() {
318
- if ( !swpsmtp_credentials_configured() ) {
319
- $settings_url = admin_url() . 'options-general.php?page=swpsmtp_settings';
320
- ?>
321
- <div class="error">
322
- <p><?php printf( __( 'Please configure your SMTP credentials in the <a href="%s">settings menu</a> in order to send email using Easy WP SMTP plugin.', 'easy-wp-smtp' ), esc_url( $settings_url ) ); ?></p>
323
- </div>
324
- <?php
325
- }
326
  }
 
327
 
328
  }
329
 
330
- if ( !function_exists( 'swpsmtp_credentials_configured' ) ) {
331
 
332
- function swpsmtp_credentials_configured() {
333
- $swpsmtp_options = get_option( 'swpsmtp_options' );
334
- $credentials_configured = true;
335
- if ( !isset( $swpsmtp_options['from_email_field'] ) || empty( $swpsmtp_options['from_email_field'] ) ) {
336
- $credentials_configured = false;
337
- }
338
- if ( !isset( $swpsmtp_options['from_name_field'] ) || empty( $swpsmtp_options['from_name_field'] ) ) {
339
- $credentials_configured = false;
340
- ;
341
- }
342
- return $credentials_configured;
343
  }
 
 
 
 
 
 
344
 
345
  }
346
 
@@ -348,87 +347,104 @@ if ( !function_exists( 'swpsmtp_credentials_configured' ) ) {
348
  * Performed at uninstal.
349
  * @return void
350
  */
351
- if ( !function_exists( 'swpsmtp_send_uninstall' ) ) {
352
 
353
- function swpsmtp_send_uninstall() {
354
- /* Don't delete plugin options. It is better to retain the options so if someone accidentally deactivates, the configuration is not lost. */
355
 
356
  //delete_site_option('swpsmtp_options');
357
  //delete_option('swpsmtp_options');
358
- }
359
 
360
  }
361
 
362
  function swpsmtp_activate() {
363
- $swpsmtp_options = get_option( 'swpsmtp_options' );
364
- //add current domain to allowed domains list
365
- if ( !isset( $swpsmtp_options['allowed_domains'] ) ) {
366
- $domain = parse_url( get_site_url(), PHP_URL_HOST );
367
- if ( $domain ) {
368
- $swpsmtp_options['allowed_domains'] = base64_encode( $domain );
369
- update_option( 'swpsmtp_options', $swpsmtp_options );
370
- }
371
- } else { // let's check if existing value should be base64 encoded
372
- if ( !empty( $swpsmtp_options['allowed_domains'] ) ) {
373
- if ( base64_decode_maybe( $swpsmtp_options['allowed_domains'] ) === $swpsmtp_options['allowed_domains'] ) {
374
- $swpsmtp_options['allowed_domains'] = base64_encode( $swpsmtp_options['allowed_domains'] );
375
- update_option( 'swpsmtp_options', $swpsmtp_options );
376
- }
377
- }
 
 
 
 
 
 
 
 
 
378
  }
 
 
 
 
 
 
 
 
379
  }
380
 
381
  function swpsmtp_is_domain_blocked() {
382
- $swpsmtp_options = get_option( 'swpsmtp_options' );
383
- //check if Domain Check enabled
384
- if ( isset( $swpsmtp_options['enable_domain_check'] ) && $swpsmtp_options['enable_domain_check'] ) {
385
- //check if allowed domains list is not blank
386
- if ( isset( $swpsmtp_options['allowed_domains'] ) && !empty( $swpsmtp_options['allowed_domains'] ) ) {
387
- $swpsmtp_options['allowed_domains'] = base64_decode_maybe( $swpsmtp_options['allowed_domains'] );
388
- //let's see if we have one domain or coma-separated domains
389
- $domains_arr = explode( ',', $swpsmtp_options['allowed_domains'] );
390
- if ( is_array( $domains_arr ) && !empty( $domains_arr ) ) {
391
- //we have coma-separated list
392
- } else {
393
- //it's single domain
394
- unset( $domains_arr );
395
- $domains_arr = array( $swpsmtp_options['allowed_domains'] );
396
- }
397
- $site_domain = parse_url( get_site_url(), PHP_URL_HOST );
398
- $match_found = false;
399
- foreach ( $domains_arr as $domain ) {
400
- if ( strtolower( trim( $domain ) ) === strtolower( trim( $site_domain ) ) ) {
401
- $match_found = true;
402
- break;
403
- }
404
- }
405
- if ( !$match_found ) {
406
- return $site_domain;
407
- }
408
  }
 
 
 
 
409
  }
410
- return false;
 
411
  }
412
 
413
  function swpsmtp_wp_mail( $args ) {
414
- $swpsmtp_options = get_option( 'swpsmtp_options' );
415
- $domain = swpsmtp_is_domain_blocked();
416
- if ( $domain !== false && (isset( $swpsmtp_options['block_all_emails'] ) && $swpsmtp_options['block_all_emails'] === 1) ) {
417
- swpsmtp_write_to_log(
418
- "\r\n------------------------------------------------------------------------------------------------------\r\n" .
419
- "Domain check failed: website domain (" . $domain . ") is not in allowed domains list.\r\n" .
420
- "Following email not sent (block all emails option is enabled):\r\n" .
421
- "To: " . $args['to'] . "; Subject: " . $args['subject'] . "\r\n" .
422
- "------------------------------------------------------------------------------------------------------\r\n\r\n" );
423
- }
424
- return $args;
425
  }
426
 
427
  class swpsmtp_gag_mailer extends stdClass {
428
 
429
- public function Send() {
430
- return true;
431
- }
432
 
433
  }
434
 
1
  <?php
2
  /*
3
  Plugin Name: Easy WP SMTP
4
+ Version: 1.3.2
5
  Plugin URI: https://wp-ecommerce.net/easy-wordpress-smtp-send-emails-from-your-wordpress-site-using-a-smtp-server-2197
6
  Author: wpecommerce
7
  Author URI: https://wp-ecommerce.net/
20
  * @param $file string relative path to pugin "easy-wp-smtp/easy-wp-smtp.php"
21
  * @return $links array() action links
22
  */
23
+ if ( ! function_exists( 'swpsmtp_plugin_action_links' ) ) {
24
 
25
+ function swpsmtp_plugin_action_links( $links, $file ) {
26
+ /* Static so we don't call plugin_basename on every plugin row. */
27
+ static $this_plugin;
28
+ if ( ! $this_plugin ) {
29
+ $this_plugin = plugin_basename( __FILE__ );
 
 
 
 
 
 
30
  }
31
+ if ( $file == $this_plugin ) {
32
+ $settings_link = '<a href="options-general.php?page=swpsmtp_settings">' . __( 'Settings', 'easy-wp-smtp' ) . '</a>';
33
+ array_unshift( $links, $settings_link );
34
+ }
35
+ return $links;
36
+ }
37
 
38
  }
39
 
43
  * @param $file string relative path to pugin "easy-wp-smtp/easy-wp-smtp.php"
44
  * @return $links array() action links
45
  */
46
+ if ( ! function_exists( 'swpsmtp_register_plugin_links' ) ) {
47
 
48
+ function swpsmtp_register_plugin_links( $links, $file ) {
49
+ $base = plugin_basename( __FILE__ );
50
+ if ( $file == $base ) {
51
+ $links[] = '<a href="options-general.php?page=swpsmtp_settings">' . __( 'Settings', 'easy-wp-smtp' ) . '</a>';
 
 
52
  }
53
+ return $links;
54
+ }
55
 
56
  }
57
 
58
  //plugins_loaded action hook handler
59
+ if ( ! function_exists( 'swpsmtp_plugins_loaded_handler' ) ) {
60
 
61
+ function swpsmtp_plugins_loaded_handler() {
62
+ load_plugin_textdomain( 'easy-wp-smtp', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
63
+ }
64
 
65
  }
66
 
69
  * Function to add plugin scripts
70
  * @return void
71
  */
72
+ if ( ! function_exists( 'swpsmtp_admin_head' ) ) {
 
 
 
73
 
74
+ function swpsmtp_admin_head() {
75
+ wp_enqueue_style( 'swpsmtp_stylesheet', plugins_url( 'css/style.css', __FILE__ ) );
76
+ }
 
77
 
78
  }
79
 
80
  function swpsmtp_clear_log() {
81
+ if ( swpsmtp_write_to_log( "Easy WP SMTP debug log file\r\n\r\n", true ) !== false ) {
82
+ echo '1';
83
+ } else {
84
+ echo 'Can\'t clear log - log file is not writeable.';
85
+ }
86
+ wp_die();
87
  }
88
 
89
  function swpsmtp_write_to_log( $str, $overwrite = false ) {
90
+ $swpsmtp_options = get_option( 'swpsmtp_options' );
91
+ if ( isset( $swpsmtp_options[ 'smtp_settings' ][ 'log_file_name' ] ) ) {
92
+ $log_file_name = $swpsmtp_options[ 'smtp_settings' ][ 'log_file_name' ];
93
+ } else {
94
+ // let's generate log file name
95
+ $log_file_name = uniqid() . '_debug_log.txt';
96
+ $swpsmtp_options[ 'smtp_settings' ][ 'log_file_name' ] = $log_file_name;
97
+ update_option( 'swpsmtp_options', $swpsmtp_options );
98
+ file_put_contents( plugin_dir_path( __FILE__ ) . $log_file_name, "Easy WP SMTP debug log file\r\n\r\n" );
99
+ }
100
+ return(file_put_contents( plugin_dir_path( __FILE__ ) . $log_file_name, $str, ( ! $overwrite ? FILE_APPEND : 0 ) ));
101
  }
102
 
103
  function base64_decode_maybe( $str ) {
104
+ if ( ! function_exists( 'mb_detect_encoding' ) ) {
105
+ return base64_decode( $str );
106
+ }
107
+ if ( mb_detect_encoding( $str ) === mb_detect_encoding( base64_decode( base64_encode( base64_decode( $str ) ) ) ) ) {
108
+ $str = base64_decode( $str );
109
+ }
110
+ return $str;
111
  }
112
 
113
  /**
114
  * Function to add smtp options in the phpmailer_init
115
  * @return void
116
  */
117
+ if ( ! function_exists( 'swpsmtp_init_smtp' ) ) {
118
 
119
+ function swpsmtp_init_smtp( &$phpmailer ) {
120
+ //check if SMTP credentials have been configured.
121
+ if ( ! swpsmtp_credentials_configured() ) {
122
+ return;
123
+ }
124
+ $swpsmtp_options = get_option( 'swpsmtp_options' );
125
+ //check if Domain Check enabled
126
+ $domain = swpsmtp_is_domain_blocked();
127
+ if ( $domain !== false ) {
128
+ //domain check failed
129
+ //let's check if we have block all emails option enabled
130
+ if ( isset( $swpsmtp_options[ 'block_all_emails' ] ) && $swpsmtp_options[ 'block_all_emails' ] === 1 ) {
131
+ // it's enabled. Let's use gag mailer class that would prevent emails from being sent out.
132
+ $phpmailer = new swpsmtp_gag_mailer();
133
+ } else {
134
+ // it's disabled. Let's write some info to the log
135
+ swpsmtp_write_to_log(
136
+ "\r\n------------------------------------------------------------------------------------------------------\r\n" .
137
+ "Domain check failed: website domain (" . $domain . ") is not in allowed domains list.\r\n" .
138
+ "SMTP settings won't be used.\r\n" .
139
+ "------------------------------------------------------------------------------------------------------\r\n\r\n" );
140
+ }
141
+ return;
142
+ }
143
+ /* Set the mailer type as per config above, this overrides the already called isMail method */
144
+ $phpmailer->IsSMTP();
145
+ $from_name = $swpsmtp_options[ 'from_name_field' ];
146
+ $from_email = $swpsmtp_options[ 'from_email_field' ];
147
+ //set ReplyTo option if needed
148
+ //this should be set before SetFrom, otherwise might be ignored
149
+ if ( ! empty( $swpsmtp_options[ 'reply_to_email' ] ) ) {
150
+ $phpmailer->AddReplyTo( $swpsmtp_options[ 'reply_to_email' ], $from_name );
151
+ }
152
+ // let's see if we have email ignore list populated
153
+ if ( isset( $swpsmtp_options[ 'email_ignore_list' ] ) && ! empty( $swpsmtp_options[ 'email_ignore_list' ] ) ) {
154
+ $emails_arr = explode( ',', $swpsmtp_options[ 'email_ignore_list' ] );
155
+ if ( is_array( $emails_arr ) && ! empty( $emails_arr ) ) {
156
+ //we have coma-separated list
157
+ } else {
158
+ //it's single email
159
+ unset( $emails_arr );
160
+ $emails_arr = array( $swpsmtp_options[ 'email_ignore_list' ] );
161
+ }
162
+ $from = $phpmailer->From;
163
+ $match_found = false;
164
+ foreach ( $emails_arr as $email ) {
165
+ if ( strtolower( trim( $email ) ) === strtolower( trim( $from ) ) ) {
166
+ $match_found = true;
167
+ break;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
168
  }
169
+ }
170
+ if ( $match_found ) {
171
+ //we should not override From and Fromname
172
+ $from_email = $phpmailer->From;
173
+ $from_name = $phpmailer->FromName;
174
+ }
175
+ }
176
+ $phpmailer->From = $from_email;
177
+ $phpmailer->FromName = $from_name;
178
+ $phpmailer->SetFrom( $phpmailer->From, $phpmailer->FromName );
179
+ /* Set the SMTPSecure value */
180
+ if ( $swpsmtp_options[ 'smtp_settings' ][ 'type_encryption' ] !== 'none' ) {
181
+ $phpmailer->SMTPSecure = $swpsmtp_options[ 'smtp_settings' ][ 'type_encryption' ];
182
+ }
183
 
184
+ /* Set the other options */
185
+ $phpmailer->Host = $swpsmtp_options[ 'smtp_settings' ][ 'host' ];
186
+ $phpmailer->Port = $swpsmtp_options[ 'smtp_settings' ][ 'port' ];
187
 
188
+ /* If we're using smtp auth, set the username & password */
189
+ if ( 'yes' == $swpsmtp_options[ 'smtp_settings' ][ 'autentication' ] ) {
190
+ $phpmailer->SMTPAuth = true;
191
+ $phpmailer->Username = $swpsmtp_options[ 'smtp_settings' ][ 'username' ];
192
+ $phpmailer->Password = swpsmtp_get_password();
193
+ }
194
  //PHPMailer 5.2.10 introduced this option. However, this might cause issues if the server is advertising TLS with an invalid certificate.
195
+ $phpmailer->SMTPAutoTLS = false;
196
+ if ( isset( $swpsmtp_options[ 'smtp_settings' ][ 'enable_debug' ] ) && $swpsmtp_options[ 'smtp_settings' ][ 'enable_debug' ] ) {
197
+ $phpmailer->Debugoutput = function($str, $level) {
198
+ swpsmtp_write_to_log( $str );
199
+ };
200
+ $phpmailer->SMTPDebug = 1;
 
201
  }
202
+ }
203
 
204
  }
205
 
207
  * Function to test mail sending
208
  * @return text or errors
209
  */
210
+ if ( ! function_exists( 'swpsmtp_test_mail' ) ) {
211
 
212
+ function swpsmtp_test_mail( $to_email, $subject, $message ) {
213
+ if ( ! swpsmtp_credentials_configured() ) {
214
+ return;
215
+ }
216
+ $errors = '';
217
 
218
+ $swpsmtp_options = get_option( 'swpsmtp_options' );
219
 
220
+ require_once( ABSPATH . WPINC . '/class-phpmailer.php' );
221
+ $mail = new PHPMailer();
222
 
223
+ $charset = get_bloginfo( 'charset' );
224
+ $mail->CharSet = $charset;
225
 
226
+ $from_name = $swpsmtp_options[ 'from_name_field' ];
227
+ $from_email = $swpsmtp_options[ 'from_email_field' ];
228
 
229
+ $mail->IsSMTP();
230
 
231
+ /* If using smtp auth, set the username & password */
232
+ if ( 'yes' == $swpsmtp_options[ 'smtp_settings' ][ 'autentication' ] ) {
233
+ $mail->SMTPAuth = true;
234
+ $mail->Username = $swpsmtp_options[ 'smtp_settings' ][ 'username' ];
235
+ $mail->Password = swpsmtp_get_password();
236
+ }
237
 
238
+ /* Set the SMTPSecure value, if set to none, leave this blank */
239
+ if ( $swpsmtp_options[ 'smtp_settings' ][ 'type_encryption' ] !== 'none' ) {
240
+ $mail->SMTPSecure = $swpsmtp_options[ 'smtp_settings' ][ 'type_encryption' ];
241
+ }
242
 
243
+ /* PHPMailer 5.2.10 introduced this option. However, this might cause issues if the server is advertising TLS with an invalid certificate. */
244
+ $mail->SMTPAutoTLS = false;
245
 
246
+ /* Set the other options */
247
+ $mail->Host = $swpsmtp_options[ 'smtp_settings' ][ 'host' ];
248
+ $mail->Port = $swpsmtp_options[ 'smtp_settings' ][ 'port' ];
249
+ if ( ! empty( $swpsmtp_options[ 'reply_to_email' ] ) ) {
250
+ $mail->AddReplyTo( $swpsmtp_options[ 'reply_to_email' ], $from_name );
251
+ }
252
+ $mail->SetFrom( $from_email, $from_name );
253
+ $mail->isHTML( true );
254
+ $mail->Subject = $subject;
255
+ $mail->MsgHTML( $message );
256
+ $mail->AddAddress( $to_email );
257
+ global $debugMSG;
258
+ $debugMSG = '';
259
+ $mail->Debugoutput = function($str, $level) {
260
+ global $debugMSG;
261
+ $debugMSG .= $str;
262
+ };
263
+ $mail->SMTPDebug = 1;
264
+
265
+ /* Send mail and return result */
266
+ if ( ! $mail->Send() )
267
+ $errors = $mail->ErrorInfo;
268
+
269
+ $mail->ClearAddresses();
270
+ $mail->ClearAllRecipients();
271
+
272
+ echo '<div class="swpsmtp-yellow-box"><h3>Debug Info</h3>';
273
+ echo '<textarea rows="20" style="width: 100%;">' . $debugMSG . '</textarea>';
274
+ echo '</div>';
275
+
276
+ if ( ! empty( $errors ) ) {
277
+ return $errors;
278
+ } else {
279
+ return 'Test mail was sent';
 
280
  }
281
+ }
282
 
283
  }
284
 
285
+ if ( ! function_exists( 'swpsmtp_get_password' ) ) {
286
 
287
+ function swpsmtp_get_password() {
288
+ $swpsmtp_options = get_option( 'swpsmtp_options' );
289
+ $temp_password = isset( $swpsmtp_options[ 'smtp_settings' ][ 'password' ] ) ? $swpsmtp_options[ 'smtp_settings' ][ 'password' ] : '';
290
+ if ( $temp_password == '' ) {
291
+ return '';
292
+ }
293
+ $password = "";
294
+ $decoded_pass = base64_decode( $temp_password );
295
+ /* no additional checks for servers that aren't configured with mbstring enabled */
296
+ if ( ! function_exists( 'mb_detect_encoding' ) ) {
297
+ return $decoded_pass;
 
 
 
 
 
 
 
 
 
 
 
 
298
  }
299
+ /* end of mbstring check */
300
+ if ( base64_encode( $decoded_pass ) === $temp_password ) { //it might be encoded
301
+ if ( false === mb_detect_encoding( $decoded_pass ) ) { //could not find character encoding.
302
+ $password = $temp_password;
303
+ } else {
304
+ $password = base64_decode( $temp_password );
305
+ }
306
+ } else { //not encoded
307
+ $password = $temp_password;
308
+ }
309
+ return stripslashes( $password );
310
+ }
311
 
312
  }
313
 
314
+ if ( ! function_exists( 'swpsmtp_admin_notice' ) ) {
315
 
316
+ function swpsmtp_admin_notice() {
317
+ if ( ! swpsmtp_credentials_configured() ) {
318
+ $settings_url = admin_url() . 'options-general.php?page=swpsmtp_settings';
319
+ ?>
320
+ <div class="error">
321
+ <p><?php printf( __( 'Please configure your SMTP credentials in the <a href="%s">settings menu</a> in order to send email using Easy WP SMTP plugin.', 'easy-wp-smtp' ), esc_url( $settings_url ) ); ?></p>
322
+ </div>
323
+ <?php
 
324
  }
325
+ }
326
 
327
  }
328
 
329
+ if ( ! function_exists( 'swpsmtp_credentials_configured' ) ) {
330
 
331
+ function swpsmtp_credentials_configured() {
332
+ $swpsmtp_options = get_option( 'swpsmtp_options' );
333
+ $credentials_configured = true;
334
+ if ( ! isset( $swpsmtp_options[ 'from_email_field' ] ) || empty( $swpsmtp_options[ 'from_email_field' ] ) ) {
335
+ $credentials_configured = false;
 
 
 
 
 
 
336
  }
337
+ if ( ! isset( $swpsmtp_options[ 'from_name_field' ] ) || empty( $swpsmtp_options[ 'from_name_field' ] ) ) {
338
+ $credentials_configured = false;
339
+ ;
340
+ }
341
+ return $credentials_configured;
342
+ }
343
 
344
  }
345
 
347
  * Performed at uninstal.
348
  * @return void
349
  */
350
+ if ( ! function_exists( 'swpsmtp_send_uninstall' ) ) {
351
 
352
+ function swpsmtp_send_uninstall() {
353
+ /* Don't delete plugin options. It is better to retain the options so if someone accidentally deactivates, the configuration is not lost. */
354
 
355
  //delete_site_option('swpsmtp_options');
356
  //delete_option('swpsmtp_options');
357
+ }
358
 
359
  }
360
 
361
  function swpsmtp_activate() {
362
+ $swpsmtp_options_default = array(
363
+ 'from_email_field' => '',
364
+ 'from_name_field' => '',
365
+ 'smtp_settings' => array(
366
+ 'host' => 'smtp.example.com',
367
+ 'type_encryption' => 'none',
368
+ 'port' => 25,
369
+ 'autentication' => 'yes',
370
+ 'username' => 'yourusername',
371
+ 'password' => 'yourpassword'
372
+ )
373
+ );
374
+
375
+ /* install the default plugin options if needed */
376
+ if ( ! get_option( 'swpsmtp_options' ) ) {
377
+ add_option( 'swpsmtp_options', $swpsmtp_options_default, '', 'yes' );
378
+ }
379
+ $swpsmtp_options = get_option( 'swpsmtp_options' );
380
+ //add current domain to allowed domains list
381
+ if ( ! isset( $swpsmtp_options[ 'allowed_domains' ] ) ) {
382
+ $domain = parse_url( get_site_url(), PHP_URL_HOST );
383
+ if ( $domain ) {
384
+ $swpsmtp_options[ 'allowed_domains' ] = base64_encode( $domain );
385
+ update_option( 'swpsmtp_options', $swpsmtp_options );
386
  }
387
+ } else { // let's check if existing value should be base64 encoded
388
+ if ( ! empty( $swpsmtp_options[ 'allowed_domains' ] ) ) {
389
+ if ( base64_decode_maybe( $swpsmtp_options[ 'allowed_domains' ] ) === $swpsmtp_options[ 'allowed_domains' ] ) {
390
+ $swpsmtp_options[ 'allowed_domains' ] = base64_encode( $swpsmtp_options[ 'allowed_domains' ] );
391
+ update_option( 'swpsmtp_options', $swpsmtp_options );
392
+ }
393
+ }
394
+ }
395
  }
396
 
397
  function swpsmtp_is_domain_blocked() {
398
+ $swpsmtp_options = get_option( 'swpsmtp_options' );
399
+ //check if Domain Check enabled
400
+ if ( isset( $swpsmtp_options[ 'enable_domain_check' ] ) && $swpsmtp_options[ 'enable_domain_check' ] ) {
401
+ //check if allowed domains list is not blank
402
+ if ( isset( $swpsmtp_options[ 'allowed_domains' ] ) && ! empty( $swpsmtp_options[ 'allowed_domains' ] ) ) {
403
+ $swpsmtp_options[ 'allowed_domains' ] = base64_decode_maybe( $swpsmtp_options[ 'allowed_domains' ] );
404
+ //let's see if we have one domain or coma-separated domains
405
+ $domains_arr = explode( ',', $swpsmtp_options[ 'allowed_domains' ] );
406
+ if ( is_array( $domains_arr ) && ! empty( $domains_arr ) ) {
407
+ //we have coma-separated list
408
+ } else {
409
+ //it's single domain
410
+ unset( $domains_arr );
411
+ $domains_arr = array( $swpsmtp_options[ 'allowed_domains' ] );
412
+ }
413
+ $site_domain = parse_url( get_site_url(), PHP_URL_HOST );
414
+ $match_found = false;
415
+ foreach ( $domains_arr as $domain ) {
416
+ if ( strtolower( trim( $domain ) ) === strtolower( trim( $site_domain ) ) ) {
417
+ $match_found = true;
418
+ break;
 
 
 
 
 
419
  }
420
+ }
421
+ if ( ! $match_found ) {
422
+ return $site_domain;
423
+ }
424
  }
425
+ }
426
+ return false;
427
  }
428
 
429
  function swpsmtp_wp_mail( $args ) {
430
+ $swpsmtp_options = get_option( 'swpsmtp_options' );
431
+ $domain = swpsmtp_is_domain_blocked();
432
+ if ( $domain !== false && (isset( $swpsmtp_options[ 'block_all_emails' ] ) && $swpsmtp_options[ 'block_all_emails' ] === 1) ) {
433
+ swpsmtp_write_to_log(
434
+ "\r\n------------------------------------------------------------------------------------------------------\r\n" .
435
+ "Domain check failed: website domain (" . $domain . ") is not in allowed domains list.\r\n" .
436
+ "Following email not sent (block all emails option is enabled):\r\n" .
437
+ "To: " . $args[ 'to' ] . "; Subject: " . $args[ 'subject' ] . "\r\n" .
438
+ "------------------------------------------------------------------------------------------------------\r\n\r\n" );
439
+ }
440
+ return $args;
441
  }
442
 
443
  class swpsmtp_gag_mailer extends stdClass {
444
 
445
+ public function Send() {
446
+ return true;
447
+ }
448
 
449
  }
450
 
js/script.js CHANGED
@@ -3,12 +3,6 @@
3
  /*
4
  *add notice about changing in the settings page
5
  */
6
- $('#swpsmtp-mail input').bind("change select", function () {
7
- if ($(this).attr('type') != 'submit') {
8
- $('.updated.fade').css('display', 'none');
9
- $('#swpsmtp-settings-notice').css('display', 'block');
10
- }
11
- ;
12
- });
13
  });
14
  })(jQuery);
3
  /*
4
  *add notice about changing in the settings page
5
  */
6
+
 
 
 
 
 
 
7
  });
8
  })(jQuery);
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: https://wp-ecommerce.net/easy-wordpress-smtp-send-emails-from-your-
4
  Tags: mail, wordpress smtp, phpmailer, smtp, wp_mail, email, gmail, outgoing mail, privacy, security, sendmail, ssl, tls, wp-phpmailer, mail smtp, wp smtp
5
  Requires at least: 4.3
6
  Tested up to: 4.9
7
- Stable tag: 1.3.1
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -77,6 +77,13 @@ Inspired by [WP Mail SMTP](http://wordpress.org/plugins/wp-mail-smtp/) plugin
77
 
78
  == Changelog ==
79
 
 
 
 
 
 
 
 
80
  = 1.3.1 =
81
  * Fixed potential issue with passwords that had special characters.
82
  * Check if variables are set before interacting with them (removes PHP notices when WP debug mode is enabled) (thanks to rubas and matward).
4
  Tags: mail, wordpress smtp, phpmailer, smtp, wp_mail, email, gmail, outgoing mail, privacy, security, sendmail, ssl, tls, wp-phpmailer, mail smtp, wp smtp
5
  Requires at least: 4.3
6
  Tested up to: 4.9
7
+ Stable tag: 1.3.2
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
77
 
78
  == Changelog ==
79
 
80
+ = 1.3.2 =
81
+ * Hopefully fixed inability for plugin to save settings in some circumstances (thanks to all who kept reporting this issue).
82
+ * The plugin is no longer failing if PHP mbstring extension is not installed on the server.
83
+ * Settings page is using tabs now.
84
+ * Fixed default settings were not set upon plugin activation.
85
+ * Fixed some lines that couldn't be translated to other languages (thanks to jranavas).
86
+
87
  = 1.3.1 =
88
  * Fixed potential issue with passwords that had special characters.
89
  * Check if variables are set before interacting with them (removes PHP notices when WP debug mode is enabled) (thanks to rubas and matward).