Easy WP SMTP - Version 1.3.1

Version Description

  • Fixed potential issue with passwords that had special characters.
  • Check if variables are set before interacting with them (removes PHP notices when WP debug mode is enabled) (thanks to rubas and matward).
  • Test email message body is no longer having excess slashes inserted (thanks to tdcsforeveryone).
  • Added option for plugin to block ALL emails if Domain Check option enabled and domain check fails (thanks to erikmolenaar).
Download this release

Release Info

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

Code changes from version 1.3.0 to 1.3.1

Files changed (5) hide show
  1. css/style.css +2 -2
  2. easy-wp-smtp-admin-menu.php +326 -320
  3. easy-wp-smtp.php +353 -308
  4. js/script.js +13 -13
  5. readme.txt +9 -3
css/style.css CHANGED
@@ -4,7 +4,7 @@
4
  #swpsmtp_settings_form input[type='text'],
5
  #swpsmtp_settings_form input[type='password'],
6
  #swpsmtp_settings_form input[type='email'],
7
- #swpsmtp_settings_form input:disabled
8
  {
9
  width: 350px;
10
  }
@@ -19,5 +19,5 @@ textarea#swpsmtp_message{
19
  border-color: #E6DB55;
20
  border-radius: 3px 3px 3px 3px;
21
  border-style: solid;
22
- border-width: 1px;
23
  }
4
  #swpsmtp_settings_form input[type='text'],
5
  #swpsmtp_settings_form input[type='password'],
6
  #swpsmtp_settings_form input[type='email'],
7
+ #swpsmtp_settings_form input[type='text']
8
  {
9
  width: 350px;
10
  }
19
  border-color: #E6DB55;
20
  border-radius: 3px 3px 3px 3px;
21
  border-style: solid;
22
+ border-width: 1px;
23
  }
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,302 +14,308 @@ 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['allowed_domains'] = base64_encode(sanitize_text_field($_POST['swpsmtp_allowed_domains']));
60
- } else if (!isset($swpsmtp_options['allowed_domains'])) {
61
- $swpsmtp_options['allowed_domains'] = '';
62
- }
 
63
 
64
- /* Check value from "SMTP port" option */
65
- if (isset($_POST['swpsmtp_smtp_port'])) {
66
- if (empty($_POST['swpsmtp_smtp_port']) || 1 > intval($_POST['swpsmtp_smtp_port']) || (!preg_match('/^\d+$/', $_POST['swpsmtp_smtp_port']) )) {
67
- $swpsmtp_options['smtp_settings']['port'] = '25';
68
- $error .= " " . __("Please enter a valid port in the 'SMTP Port' field.", 'easy-wp-smtp');
69
- } else {
70
- $swpsmtp_options['smtp_settings']['port'] = sanitize_text_field($_POST['swpsmtp_smtp_port']);
71
- }
72
- }
73
 
74
- /* Update settings in the database */
75
- if (empty($error)) {
76
- update_option('swpsmtp_options', $swpsmtp_options);
77
- $message .= __("Settings saved.", 'easy-wp-smtp');
78
- } else {
79
- $error .= " " . __("Settings are not saved.", 'easy-wp-smtp');
80
- }
81
- }
82
 
83
- /* Send test letter */
84
- $swpsmtp_to = '';
85
- if (isset($_POST['swpsmtp_test_submit']) && check_admin_referer(plugin_basename(__FILE__), 'swpsmtp_nonce_name')) {
86
- if (isset($_POST['swpsmtp_to'])) {
87
- $to_email = sanitize_text_field($_POST['swpsmtp_to']);
88
- if (is_email($to_email)) {
89
- $swpsmtp_to = $to_email;
90
- } else {
91
- $error .= __("Please enter a valid email address in the recipient email field.", 'easy-wp-smtp');
92
- }
93
- }
94
- $swpsmtp_subject = isset($_POST['swpsmtp_subject']) ? sanitize_text_field($_POST['swpsmtp_subject']) : '';
95
- $swpsmtp_message = isset($_POST['swpsmtp_message']) ? sanitize_text_field($_POST['swpsmtp_message']) : '';
96
 
97
- //Save the test mail details so it doesn't need to be filled in everytime.
98
- $smtp_test_mail['swpsmtp_to'] = $swpsmtp_to;
99
- $smtp_test_mail['swpsmtp_subject'] = $swpsmtp_subject;
100
- $smtp_test_mail['swpsmtp_message'] = $swpsmtp_message;
101
- update_option('smtp_test_mail', $smtp_test_mail);
102
 
103
- if (!empty($swpsmtp_to)) {
104
- $result = swpsmtp_test_mail($swpsmtp_to, $swpsmtp_subject, $swpsmtp_message);
105
- }
106
- }
107
- ?>
108
- <div class="swpsmtp-yellow-box">
109
- 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.
110
- </div>
111
 
112
- <div class="updated fade" <?php if (empty($message)) echo "style=\"display:none\""; ?>>
113
- <p><strong><?php echo $message; ?></strong></p>
114
- </div>
115
- <div class="error" <?php if (empty($error)) echo "style=\"display:none\""; ?>>
116
- <p><strong><?php echo $error; ?></strong></p>
117
- </div>
118
- <div id="swpsmtp-settings-notice" class="updated fade" style="display:none">
119
- <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>
120
- </div>
121
- <form id="swpsmtp_settings_form" method="post" action="">
122
 
123
- <div class="postbox">
124
- <h3 class="hndle"><label for="title"><?php _e('SMTP Configuration Settings', 'easy-wp-smtp'); ?></label></h3>
125
- <div class="inside">
126
 
127
- <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>
128
 
129
- <table class="form-table">
130
- <tr valign="top">
131
- <th scope="row"><?php _e("From Email Address", 'easy-wp-smtp'); ?></th>
132
- <td>
133
- <input type="text" name="swpsmtp_from_email" value="<?php echo esc_attr($swpsmtp_options['from_email_field']); ?>"/><br />
134
- <p class="description"><?php _e("This email address will be used in the 'From' field.", 'easy-wp-smtp'); ?></p>
135
- </td>
136
- </tr>
137
- <tr valign="top">
138
- <th scope="row"><?php _e("From Name", 'easy-wp-smtp'); ?></th>
139
- <td>
140
- <input type="text" name="swpsmtp_from_name" value="<?php echo esc_attr($swpsmtp_options['from_name_field']); ?>"/><br />
141
- <p class="description"><?php _e("This text will be used in the 'FROM' field", 'easy-wp-smtp'); ?></p>
142
- </td>
143
- </tr>
144
- <tr valign="top">
145
- <th scope="row"><?php _e("Reply-To Email Address", 'easy-wp-smtp'); ?></th>
146
- <td>
147
- <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 />
148
- <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>
149
- </td>
150
- </tr>
151
- <tr class="ad_opt swpsmtp_smtp_options">
152
- <th><?php _e('SMTP Host', 'easy-wp-smtp'); ?></th>
153
- <td>
154
- <input type='text' name='swpsmtp_smtp_host' value='<?php echo esc_attr($swpsmtp_options['smtp_settings']['host']); ?>' /><br />
155
- <p class="description"><?php _e("Your mail server", 'easy-wp-smtp'); ?></p>
156
- </td>
157
- </tr>
158
- <tr class="ad_opt swpsmtp_smtp_options">
159
- <th><?php _e('Type of Encryption', 'easy-wp-smtp'); ?></th>
160
- <td>
161
- <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 ('none' == $swpsmtp_options['smtp_settings']['type_encryption']) echo 'checked="checked"'; ?> /> <?php _e('None', 'easy-wp-smtp'); ?></label>
162
- <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 ('ssl' == $swpsmtp_options['smtp_settings']['type_encryption']) echo 'checked="checked"'; ?> /> <?php _e('SSL', 'easy-wp-smtp'); ?></label>
163
- <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 ('tls' == $swpsmtp_options['smtp_settings']['type_encryption']) echo 'checked="checked"'; ?> /> <?php _e('TLS', 'easy-wp-smtp'); ?></label><br />
164
- <p class="description"><?php _e("For most servers SSL is the recommended option", 'easy-wp-smtp'); ?></p>
165
- </td>
166
- </tr>
167
- <tr class="ad_opt swpsmtp_smtp_options">
168
- <th><?php _e('SMTP Port', 'easy-wp-smtp'); ?></th>
169
- <td>
170
- <input type='text' name='swpsmtp_smtp_port' value='<?php echo esc_attr($swpsmtp_options['smtp_settings']['port']); ?>' /><br />
171
- <p class="description"><?php _e("The port to your mail server", 'easy-wp-smtp'); ?></p>
172
- </td>
173
- </tr>
174
- <tr class="ad_opt swpsmtp_smtp_options">
175
- <th><?php _e('SMTP Authentication', 'easy-wp-smtp'); ?></th>
176
- <td>
177
- <label for="swpsmtp_smtp_autentication"><input type="radio" id="swpsmtp_smtp_autentication" name="swpsmtp_smtp_autentication" value='no' <?php if ('no' == $swpsmtp_options['smtp_settings']['autentication']) echo 'checked="checked"'; ?> /> <?php _e('No', 'easy-wp-smtp'); ?></label>
178
- <label for="swpsmtp_smtp_autentication"><input type="radio" id="swpsmtp_smtp_autentication" name="swpsmtp_smtp_autentication" value='yes' <?php if ('yes' == $swpsmtp_options['smtp_settings']['autentication']) echo 'checked="checked"'; ?> /> <?php _e('Yes', 'easy-wp-smtp'); ?></label><br />
179
- <p class="description"><?php _e("This options should always be checked 'Yes'", 'easy-wp-smtp'); ?></p>
180
- </td>
181
- </tr>
182
- <tr class="ad_opt swpsmtp_smtp_options">
183
- <th><?php _e('SMTP username', 'easy-wp-smtp'); ?></th>
184
- <td>
185
- <input type='text' name='swpsmtp_smtp_username' value='<?php echo esc_attr($swpsmtp_options['smtp_settings']['username']); ?>' /><br />
186
- <p class="description"><?php _e("The username to login to your mail server", 'easy-wp-smtp'); ?></p>
187
- </td>
188
- </tr>
189
- <tr class="ad_opt swpsmtp_smtp_options">
190
- <th><?php _e('SMTP Password', 'easy-wp-smtp'); ?></th>
191
- <td>
192
- <input type='password' name='swpsmtp_smtp_password' value='<?php echo (swpsmtp_get_password() !== '' ? $gag_password : ''); ?>' /><br />
193
- <p class="description"><?php _e("The password to login to your mail server", 'easy-wp-smtp'); ?></p>
194
- </td>
195
- </tr>
196
- </table>
197
- <p class="submit">
198
- <input type="submit" id="settings-form-submit" class="button-primary" value="<?php _e('Save Changes', 'easy-wp-smtp') ?>" />
199
- </p>
200
- </div><!-- end of inside -->
201
- </div><!-- end of postbox -->
202
 
203
- <div class="postbox">
204
- <h3 class="hndle"><label for="title"><?php _e('Additional Settings (Optional)', 'easy-wp-smtp'); ?></label></h3>
205
- <div class="inside">
206
- <table class="form-table">
207
- <tr valign="top">
208
- <th scope="row"><?php _e("Don't Replace \"From\" Field", 'easy-wp-smtp'); ?></th>
209
- <td>
210
- <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 />
211
- <p class="description"><?php _e("Comma separated emails list. Example value: email1@domain.com, email2@domain.com", "easy-wp-smtp"); ?></p>
212
- <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>
213
- </td>
214
- </tr>
215
- <tr valign="top">
216
- <th scope="row"><?php _e("Enable Domain Check", 'easy-wp-smtp'); ?></th>
217
- <td>
218
- <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' : ''; ?>/>
219
- <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>
220
- <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'; ?>/>
221
- <p class="description"><?php _e("Coma-separated domains list. Example: domain1.com, domain2.com", 'easy-wp-smtp'); ?></p>
222
- </td>
223
- </tr>
224
- <tr valign="top">
225
- <th scope="row"><?php _e("Enable Debug Log", 'easy-wp-smtp'); ?></th>
226
- <td>
227
- <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' : ''; ?>/>
228
- <p class="description"><?php _e("Check this box to enable mail debug log", 'easy-wp-smtp'); ?></p>
229
- <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>
230
- </td>
231
- </tr>
232
- </table>
233
- <p class="submit">
234
- <input type="submit" id="settings-form-submit" class="button-primary" value="<?php _e('Save Changes', 'easy-wp-smtp') ?>" />
235
- <input type="hidden" name="swpsmtp_form_submit" value="submit" />
236
- <?php wp_nonce_field(plugin_basename(__FILE__), 'swpsmtp_nonce_name'); ?>
237
- </p>
 
 
 
 
238
 
239
- <script>
240
- jQuery(function ($) {
241
- $('#swpsmtp_enable_domain_check').change(function () {
242
- $('input[name="swpsmtp_allowed_domains"]').prop('disabled', !$(this).is(':checked'));
243
- });
244
- $('#swpsmtp_clear_log_btn').click(function (e) {
245
- e.preventDefault();
246
- if (confirm("<?php _e('Are you sure want to clear log?', 'easy-wp-smtp'); ?>")) {
247
- var req = jQuery.ajax({
248
- url: ajaxurl,
249
- type: "post",
250
- data: {action: "swpsmtp_clear_log"}
251
- });
252
- req.done(function (data) {
253
- if (data === '1') {
254
- alert("<?php _e('Log cleared.', 'easy-wp-smtp'); ?>");
255
- } else {
256
- alert("Error occured: " + data);
257
- }
258
- });
259
- }
260
- });
261
- });
262
- </script>
263
- </div><!-- end of inside -->
264
- </div><!-- end of postbox -->
265
- </form>
266
- <div class="postbox">
267
- <h3 class="hndle"><label for="title"><?php _e('Test Email', 'easy-wp-smtp'); ?></label></h3>
268
- <div class="inside">
 
269
 
270
- <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>
271
- <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>
272
 
273
- <form id="swpsmtp_settings_form" method="post" action="">
274
- <table class="form-table">
275
- <tr valign="top">
276
- <th scope="row"><?php _e("To", 'easy-wp-smtp'); ?>:</th>
277
- <td>
278
- <input type="text" name="swpsmtp_to" value="<?php echo esc_html($smtp_test_mail['swpsmtp_to']); ?>" /><br />
279
- <p class="description"><?php _e("Enter the recipient's email address", 'easy-wp-smtp'); ?></p>
280
- </td>
281
- </tr>
282
- <tr valign="top">
283
- <th scope="row"><?php _e("Subject", 'easy-wp-smtp'); ?>:</th>
284
- <td>
285
- <input type="text" name="swpsmtp_subject" value="<?php echo esc_html($smtp_test_mail['swpsmtp_subject']); ?>" /><br />
286
- <p class="description"><?php _e("Enter a subject for your message", 'easy-wp-smtp'); ?></p>
287
- </td>
288
- </tr>
289
- <tr valign="top">
290
- <th scope="row"><?php _e("Message", 'easy-wp-smtp'); ?>:</th>
291
- <td>
292
- <textarea name="swpsmtp_message" id="swpsmtp_message" rows="5"><?php echo esc_textarea($smtp_test_mail['swpsmtp_message']); ?></textarea><br />
293
- <p class="description"><?php _e("Write your email message", 'easy-wp-smtp'); ?></p>
294
- </td>
295
- </tr>
296
- </table>
297
- <p class="submit">
298
- <input type="submit" id="settings-form-submit" class="button-primary" value="<?php _e('Send Test Email', 'easy-wp-smtp') ?>" />
299
- <input type="hidden" name="swpsmtp_test_submit" value="submit" />
300
- <?php wp_nonce_field(plugin_basename(__FILE__), 'swpsmtp_nonce_name'); ?>
301
- </p>
302
- </form>
303
- </div><!-- end of inside -->
304
- </div><!-- end of postbox -->
305
 
306
- <div class="swpsmtp-yellow-box">
307
- 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.
308
- </div>
309
 
310
- <?php
311
- echo '</div></div>'; //<!-- end of #poststuff and #post-body -->
312
- echo '</div>'; //<!-- end of .wrap #swpsmtp-mail .swpsmtp-mail -->
313
  }
314
 
315
  /**
@@ -317,33 +323,33 @@ function swpsmtp_settings() {
317
  * @return void
318
  */
319
  function swpsmtp_admin_init() {
320
- /* Internationalization, first(!) */
321
- load_plugin_textdomain('easy-wp-smtp', false, dirname(plugin_basename(__FILE__)) . '/languages/');
322
 
323
- if (isset($_REQUEST['page']) && 'swpsmtp_settings' == $_REQUEST['page']) {
324
- /* register plugin settings */
325
- swpsmtp_register_settings();
326
- }
327
- add_action('wp_ajax_swpsmtp_clear_log', 'swpsmtp_clear_log');
328
- //view log file
329
- if (isset($_GET['swpsmtp_action'])) {
330
- if ($_GET['swpsmtp_action'] === 'view_log') {
331
- $swpsmtp_options = get_option('swpsmtp_options');
332
- $log_file_name = $swpsmtp_options['smtp_settings']['log_file_name'];
333
- if (!file_exists(plugin_dir_path(__FILE__) . $log_file_name)) {
334
- if (swpsmtp_write_to_log("Easy WP SMTP debug log file\r\n\r\n") === false) {
335
- wp_die('Can\'t write to log file. Check if plugin directory (' . plugin_dir_path(__FILE__) . ') is writeable.');
336
- };
337
- }
338
- $logfile = fopen(plugin_dir_path(__FILE__) . $log_file_name, 'rb');
339
- if (!$logfile) {
340
- wp_die('Can\'t open log file.');
341
- }
342
- header('Content-Type: text/plain');
343
- fpassthru($logfile);
344
- die;
345
- }
346
- }
347
  }
348
 
349
  /**
@@ -351,21 +357,21 @@ function swpsmtp_admin_init() {
351
  * @return void
352
  */
353
  function swpsmtp_register_settings() {
354
- $swpsmtp_options_default = array(
355
- 'from_email_field' => '',
356
- 'from_name_field' => '',
357
- 'smtp_settings' => array(
358
- 'host' => 'smtp.example.com',
359
- 'type_encryption' => 'none',
360
- 'port' => 25,
361
- 'autentication' => 'yes',
362
- 'username' => 'yourusername',
363
- 'password' => 'yourpassword'
364
- )
365
- );
366
 
367
- /* install the default plugin options */
368
- if (!get_option('swpsmtp_options')) {
369
- add_option('swpsmtp_options', $swpsmtp_options_default, '', 'yes');
370
- }
371
  }
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'] ) && 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
  /**
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
  /**
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
  }
easy-wp-smtp.php CHANGED
@@ -1,7 +1,7 @@
1
  <?php
2
  /*
3
  Plugin Name: Easy WP SMTP
4
- Version: 1.3.0
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,151 +69,138 @@ 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
- if (isset($swpsmtp_options['enable_domain_check']) && $swpsmtp_options['enable_domain_check']) {
128
- //check if allowed domains list is not blank
129
- if (isset($swpsmtp_options['allowed_domains']) && !empty($swpsmtp_options['allowed_domains'])) {
130
- $swpsmtp_options['allowed_domains'] = base64_decode_maybe($swpsmtp_options['allowed_domains']);
131
- //let's see if we have one domain or coma-separated domains
132
- $domains_arr = explode(',', $swpsmtp_options['allowed_domains']);
133
- if (is_array($domains_arr) && !empty($domains_arr)) {
134
- //we have coma-separated list
135
- } else {
136
- //it's single domain
137
- unset($domains_arr);
138
- $domains_arr = array($swpsmtp_options['allowed_domains']);
139
- }
140
- $site_domain = parse_url(get_site_url(), PHP_URL_HOST);
141
- $match_found = false;
142
- foreach ($domains_arr as $domain) {
143
- if (strtolower(trim($domain)) === strtolower(trim($site_domain))) {
144
- $match_found = true;
145
- break;
146
- }
147
- }
148
- if (!$match_found) {
149
- swpsmtp_write_to_log(
150
- "\r\n-------------------------------------------------------------------------------------------------------\r\n" .
151
- "Domain check failed: website domain (" . $site_domain . ") is not in allowed domains list.\r\n" .
152
- "-------------------------------------------------------------------------------------------------------\r\n\r\n");
153
- return;
154
- }
155
- }
156
- }
157
- /* Set the mailer type as per config above, this overrides the already called isMail method */
158
- $phpmailer->IsSMTP();
159
- $from_name = $swpsmtp_options['from_name_field'];
160
- $from_email = $swpsmtp_options['from_email_field'];
161
- //set ReplyTo option if needed
162
- //this should be set before SetFrom, otherwise might be ignored
163
- if (!empty($swpsmtp_options['reply_to_email'])) {
164
- $phpmailer->AddReplyTo($swpsmtp_options['reply_to_email'], $from_name);
165
- }
166
- // let's see if we have email ignore list populated
167
- if (isset($swpsmtp_options['email_ignore_list']) && !empty($swpsmtp_options['email_ignore_list'])) {
168
- $emails_arr = explode(',', $swpsmtp_options['email_ignore_list']);
169
- if (is_array($emails_arr) && !empty($emails_arr)) {
170
- //we have coma-separated list
171
- } else {
172
- //it's single email
173
- unset($emails_arr);
174
- $emails_arr = array($swpsmtp_options['email_ignore_list']);
175
- }
176
- $from = $phpmailer->From;
177
- $match_found = false;
178
- foreach ($emails_arr as $email) {
179
- if (strtolower(trim($email)) === strtolower(trim($from))) {
180
- $match_found = true;
181
- break;
182
- }
183
- }
184
- if ($match_found) {
185
- //we should not override From and Fromname
186
- $from_email = $phpmailer->From;
187
- $from_name = $phpmailer->FromName;
188
- }
189
- }
190
- $phpmailer->From = $from_email;
191
- $phpmailer->FromName = $from_name;
192
- $phpmailer->SetFrom($phpmailer->From, $phpmailer->FromName);
193
- /* Set the SMTPSecure value */
194
- if ($swpsmtp_options['smtp_settings']['type_encryption'] !== 'none') {
195
- $phpmailer->SMTPSecure = $swpsmtp_options['smtp_settings']['type_encryption'];
196
- }
197
-
198
- /* Set the other options */
199
- $phpmailer->Host = $swpsmtp_options['smtp_settings']['host'];
200
- $phpmailer->Port = $swpsmtp_options['smtp_settings']['port'];
201
-
202
- /* If we're using smtp auth, set the username & password */
203
- if ('yes' == $swpsmtp_options['smtp_settings']['autentication']) {
204
- $phpmailer->SMTPAuth = true;
205
- $phpmailer->Username = $swpsmtp_options['smtp_settings']['username'];
206
- $phpmailer->Password = swpsmtp_get_password();
207
- }
208
- //PHPMailer 5.2.10 introduced this option. However, this might cause issues if the server is advertising TLS with an invalid certificate.
209
- $phpmailer->SMTPAutoTLS = false;
210
- if (isset($swpsmtp_options['smtp_settings']['enable_debug']) && $swpsmtp_options['smtp_settings']['enable_debug']) {
211
- $phpmailer->Debugoutput = function($str, $level) {
212
- swpsmtp_write_to_log($str);
213
- };
214
- $phpmailer->SMTPDebug = 1;
215
- }
216
- }
217
 
218
  }
219
 
@@ -221,136 +208,139 @@ if (!function_exists('swpsmtp_init_smtp')) {
221
  * Function to test mail sending
222
  * @return text or errors
223
  */
224
- if (!function_exists('swpsmtp_test_mail')) {
225
-
226
- function swpsmtp_test_mail($to_email, $subject, $message) {
227
- if (!swpsmtp_credentials_configured()) {
228
- return;
229
- }
230
- $errors = '';
231
-
232
- $swpsmtp_options = get_option('swpsmtp_options');
233
-
234
- require_once( ABSPATH . WPINC . '/class-phpmailer.php' );
235
- $mail = new PHPMailer();
236
-
237
- $charset = get_bloginfo('charset');
238
- $mail->CharSet = $charset;
239
-
240
- $from_name = $swpsmtp_options['from_name_field'];
241
- $from_email = $swpsmtp_options['from_email_field'];
242
-
243
- $mail->IsSMTP();
244
-
245
- /* If using smtp auth, set the username & password */
246
- if ('yes' == $swpsmtp_options['smtp_settings']['autentication']) {
247
- $mail->SMTPAuth = true;
248
- $mail->Username = $swpsmtp_options['smtp_settings']['username'];
249
- $mail->Password = swpsmtp_get_password();
250
- }
251
-
252
- /* Set the SMTPSecure value, if set to none, leave this blank */
253
- if ($swpsmtp_options['smtp_settings']['type_encryption'] !== 'none') {
254
- $mail->SMTPSecure = $swpsmtp_options['smtp_settings']['type_encryption'];
255
- }
256
-
257
- /* PHPMailer 5.2.10 introduced this option. However, this might cause issues if the server is advertising TLS with an invalid certificate. */
258
- $mail->SMTPAutoTLS = false;
259
-
260
- /* Set the other options */
261
- $mail->Host = $swpsmtp_options['smtp_settings']['host'];
262
- $mail->Port = $swpsmtp_options['smtp_settings']['port'];
263
- if (!empty($swpsmtp_options['reply_to_email'])) {
264
- $mail->AddReplyTo($swpsmtp_options['reply_to_email'], $from_name);
265
- }
266
- $mail->SetFrom($from_email, $from_name);
267
- $mail->isHTML(true);
268
- $mail->Subject = $subject;
269
- $mail->MsgHTML($message);
270
- $mail->AddAddress($to_email);
271
- global $debugMSG;
272
- $debugMSG = '';
273
- $mail->Debugoutput = function($str, $level) {
274
- global $debugMSG;
275
- $debugMSG .= $str;
276
- };
277
- $mail->SMTPDebug = 1;
278
-
279
- /* Send mail and return result */
280
- if (!$mail->Send())
281
- $errors = $mail->ErrorInfo;
282
-
283
- $mail->ClearAddresses();
284
- $mail->ClearAllRecipients();
285
-
286
- echo '<div class="swpsmtp-yellow-box"><h3>Debug Info</h3>';
287
- echo '<textarea rows="20" style="width: 100%;">' . $debugMSG . '</textarea>';
288
- echo '</div>';
289
-
290
- if (!empty($errors)) {
291
- return $errors;
292
- } else {
293
- return 'Test mail was sent';
294
- }
295
- }
296
 
297
  }
298
 
299
- if (!function_exists('swpsmtp_get_password')) {
300
-
301
- function swpsmtp_get_password() {
302
- $swpsmtp_options = get_option('swpsmtp_options');
303
- $temp_password = $swpsmtp_options['smtp_settings']['password'];
304
- $password = "";
305
- $decoded_pass = base64_decode($temp_password);
306
- /* no additional checks for servers that aren't configured with mbstring enabled */
307
- if (!function_exists('mb_detect_encoding')) {
308
- return $decoded_pass;
309
- }
310
- /* end of mbstring check */
311
- if (base64_encode($decoded_pass) === $temp_password) { //it might be encoded
312
- if (false === mb_detect_encoding($decoded_pass)) { //could not find character encoding.
313
- $password = $temp_password;
314
- } else {
315
- $password = base64_decode($temp_password);
316
- }
317
- } else { //not encoded
318
- $password = $temp_password;
319
- }
320
- return $password;
321
- }
 
 
 
322
 
323
  }
324
 
325
- if (!function_exists('swpsmtp_admin_notice')) {
326
 
327
- function swpsmtp_admin_notice() {
328
- if (!swpsmtp_credentials_configured()) {
329
- $settings_url = admin_url() . 'options-general.php?page=swpsmtp_settings';
330
- ?>
331
- <div class="error">
332
- <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>
333
- </div>
334
- <?php
335
- }
336
- }
337
 
338
  }
339
 
340
- if (!function_exists('swpsmtp_credentials_configured')) {
341
-
342
- function swpsmtp_credentials_configured() {
343
- $swpsmtp_options = get_option('swpsmtp_options');
344
- $credentials_configured = true;
345
- if (!isset($swpsmtp_options['from_email_field']) || empty($swpsmtp_options['from_email_field'])) {
346
- $credentials_configured = false;
347
- }
348
- if (!isset($swpsmtp_options['from_name_field']) || empty($swpsmtp_options['from_name_field'])) {
349
- $credentials_configured = false;
350
- ;
351
- }
352
- return $credentials_configured;
353
- }
354
 
355
  }
356
 
@@ -358,50 +348,105 @@ if (!function_exists('swpsmtp_credentials_configured')) {
358
  * Performed at uninstal.
359
  * @return void
360
  */
361
- if (!function_exists('swpsmtp_send_uninstall')) {
362
 
363
- function swpsmtp_send_uninstall() {
364
- /* Don't delete plugin options. It is better to retain the options so if someone accidentally deactivates, the configuration is not lost. */
365
 
366
- //delete_site_option('swpsmtp_options');
367
- //delete_option('swpsmtp_options');
368
- }
369
 
370
  }
371
 
372
  function swpsmtp_activate() {
373
- $swpsmtp_options = get_option('swpsmtp_options');
374
- //add current domain to allowed domains list
375
- if (!isset($swpsmtp_options['allowed_domains'])) {
376
- $domain = parse_url(get_site_url(), PHP_URL_HOST);
377
- if ($domain) {
378
- $swpsmtp_options['allowed_domains'] = base64_encode($domain);
379
- update_option('swpsmtp_options', $swpsmtp_options);
380
- }
381
- } else { // let's check if existing value should be base64 encoded
382
- if (!empty($swpsmtp_options['allowed_domains'])) {
383
- if (base64_decode_maybe($swpsmtp_options['allowed_domains']) === $swpsmtp_options['allowed_domains']) {
384
- $swpsmtp_options['allowed_domains'] = base64_encode($swpsmtp_options['allowed_domains']);
385
- update_option('swpsmtp_options', $swpsmtp_options);
386
- }
387
- }
388
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
389
  }
390
 
391
  /**
392
  * Add all hooks
393
  */
394
- add_filter('plugin_action_links', 'swpsmtp_plugin_action_links', 10, 2);
395
- add_action('plugins_loaded', 'swpsmtp_plugins_loaded_handler');
396
- add_filter('plugin_row_meta', 'swpsmtp_register_plugin_links', 10, 2);
 
397
 
398
- add_action('phpmailer_init', 'swpsmtp_init_smtp', 999);
399
 
400
- add_action('admin_menu', 'swpsmtp_admin_default_setup');
401
 
402
- add_action('admin_init', 'swpsmtp_admin_init');
403
- add_action('admin_enqueue_scripts', 'swpsmtp_admin_head');
404
- add_action('admin_notices', 'swpsmtp_admin_notice');
405
 
406
- register_activation_hook(__FILE__, 'swpsmtp_activate');
407
- register_uninstall_hook(plugin_basename(__FILE__), 'swpsmtp_send_uninstall');
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
  * @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
+ 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
  * 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
  * 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
 
435
  /**
436
  * Add all hooks
437
  */
438
+ add_filter( 'plugin_action_links', 'swpsmtp_plugin_action_links', 10, 2 );
439
+ add_action( 'plugins_loaded', 'swpsmtp_plugins_loaded_handler' );
440
+ add_filter( 'plugin_row_meta', 'swpsmtp_register_plugin_links', 10, 2 );
441
+ add_filter( 'wp_mail', 'swpsmtp_wp_mail', 2147483647 );
442
 
443
+ add_action( 'phpmailer_init', 'swpsmtp_init_smtp', 999 );
444
 
445
+ add_action( 'admin_menu', 'swpsmtp_admin_default_setup' );
446
 
447
+ add_action( 'admin_init', 'swpsmtp_admin_init' );
448
+ add_action( 'admin_enqueue_scripts', 'swpsmtp_admin_head' );
449
+ add_action( 'admin_notices', 'swpsmtp_admin_notice' );
450
 
451
+ register_activation_hook( __FILE__, 'swpsmtp_activate' );
452
+ register_uninstall_hook( plugin_basename( __FILE__ ), 'swpsmtp_send_uninstall' );
js/script.js CHANGED
@@ -1,14 +1,14 @@
1
- (function($) {
2
- $(document).ready(function() {
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);
1
+ (function ($) {
2
+ $(document).ready(function () {
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);
readme.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: wpecommerce, wp.insider, alexanderfoxc
3
  Donate link: https://wp-ecommerce.net/easy-wordpress-smtp-send-emails-from-your-wordpress-site-using-a-smtp-server-2197
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.8
7
- Stable tag: 1.3.0
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -77,9 +77,15 @@ Inspired by [WP Mail SMTP](http://wordpress.org/plugins/wp-mail-smtp/) plugin
77
 
78
  == Changelog ==
79
 
 
 
 
 
 
 
80
  = 1.3.0 =
81
  * Plugin will display an error message if log file is not writeable when "Clear Log" is clicked.
82
- * Actual SMTP password is replaced by a gag on the settings page.
83
  * Fixed minor bug in Reply-To option handling (thanks to arildur).
84
  * Some improvements in developers-related options (thanks to erikmolenaar).
85
 
3
  Donate link: https://wp-ecommerce.net/easy-wordpress-smtp-send-emails-from-your-wordpress-site-using-a-smtp-server-2197
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
 
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).
83
+ * Test email message body is no longer having excess slashes inserted (thanks to tdcsforeveryone).
84
+ * Added option for plugin to block ALL emails if Domain Check option enabled and domain check fails (thanks to erikmolenaar).
85
+
86
  = 1.3.0 =
87
  * Plugin will display an error message if log file is not writeable when "Clear Log" is clicked.
88
+ * Actual SMTP password is replaced by a gag on the settings page.
89
  * Fixed minor bug in Reply-To option handling (thanks to arildur).
90
  * Some improvements in developers-related options (thanks to erikmolenaar).
91