Easy WP SMTP - Version 1.5.0

Version Description

  • Removed the usage of serialize() / unserialize() functions. Replaced it with json_encode() and json_decode() where applicable.
Download this release

Release Info

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

Code changes from version 1.4.4 to 1.5.0

class-easywpsmtp-admin.php CHANGED
@@ -219,6 +219,7 @@ function swpsmtp_settings() {
219
  <a href="#smtp" data-tab-name="smtp" class="nav-tab"><?php esc_html_e( 'SMTP Settings', 'easy-wp-smtp' ); ?></a>
220
  <a href="#additional" data-tab-name="additional" class="nav-tab"><?php esc_html_e( 'Additional Settings', 'easy-wp-smtp' ); ?></a>
221
  <a href="#testemail" data-tab-name="testemail" class="nav-tab"><?php esc_html_e( 'Test Email', 'easy-wp-smtp' ); ?></a>
 
222
  </div>
223
 
224
  <div class="swpsmtp-settings-container">
@@ -381,7 +382,7 @@ function swpsmtp_settings() {
381
  <p>
382
  <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 esc_html_e( 'Block all emails', 'easy-wp-smtp' ); ?></label>
383
  </p>
384
- <p class="description"><?php esc_html_e( 'When enabled, plugin attempts to block ALL emails from being sent out if domain mismtach.', 'easy-wp-smtp' ); ?></p>
385
  </td>
386
  </tr>
387
  <tr valign="top">
@@ -554,6 +555,7 @@ function swpsmtp_settings() {
554
  </div><!-- end of postbox -->
555
 
556
  </div>
 
557
  </div>
558
  <div class="swpsmtp-settings-grid swpsmtp-settings-sidebar-cont">
559
  <div class="postbox" style="min-width: inherit;">
219
  <a href="#smtp" data-tab-name="smtp" class="nav-tab"><?php esc_html_e( 'SMTP Settings', 'easy-wp-smtp' ); ?></a>
220
  <a href="#additional" data-tab-name="additional" class="nav-tab"><?php esc_html_e( 'Additional Settings', 'easy-wp-smtp' ); ?></a>
221
  <a href="#testemail" data-tab-name="testemail" class="nav-tab"><?php esc_html_e( 'Test Email', 'easy-wp-smtp' ); ?></a>
222
+ <?php do_action( 'easy_wp_smtp_admin_settings_tabs_menu' ); ?>
223
  </div>
224
 
225
  <div class="swpsmtp-settings-container">
382
  <p>
383
  <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 esc_html_e( 'Block all emails', 'easy-wp-smtp' ); ?></label>
384
  </p>
385
+ <p class="description"><?php esc_html_e( 'When enabled, plugin attempts to block ALL emails from being sent out if domain mismatch.', 'easy-wp-smtp' ); ?></p>
386
  </td>
387
  </tr>
388
  <tr valign="top">
555
  </div><!-- end of postbox -->
556
 
557
  </div>
558
+ <?php do_action( 'easy_wp_smtp_admin_settings_tabs_content' ); ?>
559
  </div>
560
  <div class="swpsmtp-settings-grid swpsmtp-settings-sidebar-cont">
561
  <div class="postbox" style="min-width: inherit;">
class-easywpsmtp-utils.php CHANGED
@@ -1,90 +1,91 @@
1
- <?php
2
-
3
- use ioncube\phpOpensslCryptor\Cryptor;
4
-
5
- class EasyWPSMTP_Utils {
6
-
7
- public $enc_key;
8
- protected static $instance = null;
9
-
10
- public function __construct() {
11
- require_once 'inc/Cryptor.php';
12
- $key = get_option( 'swpsmtp_enc_key', false );
13
- if ( empty( $key ) ) {
14
- $key = wp_salt();
15
- update_option( 'swpsmtp_enc_key', $key );
16
- }
17
- $this->enc_key = $key;
18
- }
19
-
20
- public static function get_instance() {
21
-
22
- // If the single instance hasn't been set, set it now.
23
- if ( null === self::$instance ) {
24
- self::$instance = new self();
25
- }
26
-
27
- return self::$instance;
28
- }
29
-
30
- public static function base64_decode_maybe( $str ) {
31
- if ( ! function_exists( 'mb_detect_encoding' ) ) {
32
- return base64_decode( $str ); //phpcs:ignore
33
- }
34
- if ( mb_detect_encoding( $str ) === mb_detect_encoding( base64_decode( base64_encode( base64_decode( $str ) ) ) ) ) { //phpcs:ignore
35
- $str = base64_decode( $str ); //phpcs:ignore
36
- }
37
- return $str;
38
- }
39
-
40
- public function encrypt_password( $pass ) {
41
- if ( '' === $pass ) {
42
- return '';
43
- }
44
-
45
- $password = Cryptor::Encrypt( $pass, $this->enc_key );
46
- return $password;
47
- }
48
-
49
- public function decrypt_password( $pass ) {
50
- $password = Cryptor::Decrypt( $pass, $this->enc_key );
51
- return $password;
52
- }
53
-
54
- /**
55
- * Sanitizes textarea. Tries to use wp sanitize_textarea_field() function. If that's not available, uses its own methods
56
- * @return string
57
- */
58
- public static function sanitize_textarea( $str ) {
59
- if ( function_exists( 'sanitize_textarea_field' ) ) {
60
- return sanitize_textarea_field( $str );
61
- }
62
- $filtered = wp_check_invalid_utf8( $str );
63
-
64
- if ( strpos( $filtered, '<' ) !== false ) {
65
- $filtered = wp_pre_kses_less_than( $filtered );
66
- // This will strip extra whitespace for us.
67
- $filtered = wp_strip_all_tags( $filtered, false );
68
-
69
- // Use html entities in a special case to make sure no later
70
- // newline stripping stage could lead to a functional tag
71
- $filtered = str_replace( "<\n", "&lt;\n", $filtered );
72
- }
73
-
74
- $filtered = trim( $filtered );
75
-
76
- $found = false;
77
- while ( preg_match( '/%[a-f0-9]{2}/i', $filtered, $match ) ) {
78
- $filtered = str_replace( $match[0], '', $filtered );
79
- $found = true;
80
- }
81
-
82
- if ( $found ) {
83
- // Strip out the whitespace that may now exist after removing the octets.
84
- $filtered = trim( preg_replace( '/ +/', ' ', $filtered ) );
85
- }
86
-
87
- return $filtered;
88
- }
89
-
90
- }
 
1
+ <?php
2
+
3
+ use ioncube\phpOpensslCryptor\Cryptor;
4
+
5
+ class EasyWPSMTP_Utils {
6
+
7
+ public $enc_key;
8
+ protected static $instance = null;
9
+
10
+ public function __construct() {
11
+ require_once 'inc/Cryptor.php';
12
+ $key = get_option( 'swpsmtp_enc_key', false );
13
+ if ( empty( $key ) ) {
14
+ $key = wp_salt();
15
+ update_option( 'swpsmtp_enc_key', $key );
16
+ }
17
+ $this->enc_key = $key;
18
+ }
19
+
20
+ public static function get_instance() {
21
+
22
+ // If the single instance hasn't been set, set it now.
23
+ if ( null === self::$instance ) {
24
+ self::$instance = new self();
25
+ }
26
+
27
+ return self::$instance;
28
+ }
29
+
30
+ public static function base64_decode_maybe( $str ) {
31
+ if ( ! function_exists( 'mb_detect_encoding' ) ) {
32
+ return base64_decode( $str ); //phpcs:ignore
33
+ }
34
+ if ( mb_detect_encoding( $str ) === mb_detect_encoding( base64_decode( base64_encode( base64_decode( $str ) ) ) ) ) { //phpcs:ignore
35
+ $str = base64_decode( $str ); //phpcs:ignore
36
+ }
37
+ return $str;
38
+ }
39
+
40
+ public function encrypt_password( $pass ) {
41
+ if ( '' === $pass ) {
42
+ return '';
43
+ }
44
+
45
+ $password = Cryptor::Encrypt( $pass, $this->enc_key );
46
+ return $password;
47
+ }
48
+
49
+ public function decrypt_password( $pass ) {
50
+ $password = Cryptor::Decrypt( $pass, $this->enc_key );
51
+ return $password;
52
+ }
53
+
54
+ /**
55
+ * Sanitizes textarea. Tries to use wp sanitize_textarea_field() function. If that's not available, uses its own methods
56
+ * @return string
57
+ */
58
+ public static function sanitize_textarea( $str ) {
59
+ if ( function_exists( 'sanitize_textarea_field' ) ) {
60
+ return sanitize_textarea_field( $str );
61
+ }
62
+ $filtered = wp_check_invalid_utf8( $str );
63
+
64
+ if ( strpos( $filtered, '<' ) !== false ) {
65
+ $filtered = wp_pre_kses_less_than( $filtered );
66
+ // This will strip extra whitespace for us.
67
+ $filtered = wp_strip_all_tags( $filtered, false );
68
+
69
+ // Use html entities in a special case to make sure no later
70
+ // newline stripping stage could lead to a functional tag
71
+ $filtered = str_replace( "<\n", "&lt;\n", $filtered );
72
+ }
73
+
74
+ $filtered = trim( $filtered );
75
+
76
+ $found = false;
77
+ while ( preg_match( '/%[a-f0-9]{2}/i', $filtered, $match ) ) {
78
+ $filtered = str_replace( $match[0], '', $filtered );
79
+ $found = true;
80
+ }
81
+
82
+ if ( $found ) {
83
+ // Strip out the whitespace that may now exist after removing the octets.
84
+ $filtered = trim( preg_replace( '/ +/', ' ', $filtered ) );
85
+ }
86
+
87
+ return $filtered;
88
+ }
89
+
90
+
91
+ }
easy-wp-smtp.php CHANGED
@@ -1,678 +1,715 @@
1
- <?php
2
- use PHPMailer\PHPMailer\PHPMailer;
3
- use PHPMailer\PHPMailer\Exception;
4
- /*
5
- Plugin Name: Easy WP SMTP
6
- Version: 1.4.4
7
- Plugin URI: https://wp-ecommerce.net/easy-wordpress-smtp-send-emails-from-your-wordpress-site-using-a-smtp-server-2197
8
- Author: wpecommerce, alexanderfoxc
9
- Author URI: https://wp-ecommerce.net/
10
- Description: Send email via SMTP from your WordPress Blog
11
- Text Domain: easy-wp-smtp
12
- Domain Path: /languages
13
- */
14
-
15
- //Prefix/Slug - swpsmtp
16
-
17
- class EasyWPSMTP {
18
-
19
- public $opts;
20
- public $plugin_file;
21
- protected static $instance = null;
22
- public static $reset_log_str = "Easy WP SMTP debug log file\r\n\r\n";
23
-
24
- public function __construct() {
25
- $this->opts = get_option( 'swpsmtp_options' );
26
- $this->opts = ! is_array( $this->opts ) ? array() : $this->opts;
27
- $this->plugin_file = __FILE__;
28
- require_once 'class-easywpsmtp-utils.php';
29
-
30
- add_action( 'plugins_loaded', array( $this, 'plugins_loaded_handler' ) );
31
- add_filter( 'wp_mail', array( $this, 'wp_mail' ), 2147483647 );
32
- add_action( 'phpmailer_init', array( $this, 'init_smtp' ), 999 );
33
- add_action( 'admin_init', array( $this, 'admin_init' ) );
34
-
35
- if ( is_admin() && ! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
36
- require_once 'class-easywpsmtp-admin.php';
37
- register_activation_hook( __FILE__, array( $this, 'activate' ) );
38
- register_deactivation_hook( __FILE__, array( $this, 'deactivate' ) );
39
- register_uninstall_hook( __FILE__, 'swpsmtp_uninstall' );
40
- add_filter( 'plugin_action_links', array( $this, 'plugin_action_links' ), 10, 2 );
41
- add_filter( 'plugin_row_meta', array( $this, 'register_plugin_links' ), 10, 2 );
42
- add_action( 'admin_notices', array( $this, 'admin_notices' ) );
43
- }
44
- }
45
-
46
- public static function get_instance() {
47
- if ( null === self::$instance ) {
48
- self::$instance = new self();
49
- }
50
- return self::$instance;
51
- }
52
-
53
- public function wp_mail( $args ) {
54
- $domain = $this->is_domain_blocked();
55
- if ( false !== $domain && ( isset( $this->opts['block_all_emails'] ) && 1 === $this->opts['block_all_emails'] ) ) {
56
- $this->log(
57
- "\r\n------------------------------------------------------------------------------------------------------\r\n" .
58
- 'Domain check failed: website domain (' . $domain . ") is not in allowed domains list.\r\n" .
59
- "Following email not sent (block all emails option is enabled):\r\n" .
60
- 'To: ' . $args['to'] . '; Subject: ' . $args['subject'] . "\r\n" .
61
- "------------------------------------------------------------------------------------------------------\r\n\r\n"
62
- );
63
- }
64
- return $args;
65
- }
66
-
67
- public function init_smtp( &$phpmailer ) {
68
- //check if SMTP credentials have been configured.
69
- if ( ! $this->credentials_configured() ) {
70
- return;
71
- }
72
- //check if Domain Check enabled
73
- $domain = $this->is_domain_blocked();
74
- if ( false !== $domain ) {
75
- //domain check failed
76
- //let's check if we have block all emails option enabled
77
- if ( isset( $this->opts['block_all_emails'] ) && 1 === $this->opts['block_all_emails'] ) {
78
- // it's enabled. Let's use gag mailer class that would prevent emails from being sent out.
79
- require_once 'class-easywpsmtp-gag-mailer.php';
80
- $phpmailer = new EasyWPSMTP_Gag_Mailer();
81
- } else {
82
- // it's disabled. Let's write some info to the log
83
- $this->log(
84
- "\r\n------------------------------------------------------------------------------------------------------\r\n" .
85
- 'Domain check failed: website domain (' . $domain . ") is not in allowed domains list.\r\n" .
86
- "SMTP settings won't be used.\r\n" .
87
- "------------------------------------------------------------------------------------------------------\r\n\r\n"
88
- );
89
- }
90
- return;
91
- }
92
-
93
- /* Set the mailer type as per config above, this overrides the already called isMail method */
94
- $phpmailer->IsSMTP();
95
- if ( isset( $this->opts['force_from_name_replace'] ) && 1 === $this->opts['force_from_name_replace'] ) {
96
- $from_name = $this->opts['from_name_field'];
97
- } else {
98
- $from_name = ! empty( $phpmailer->FromName ) ? $phpmailer->FromName : $this->opts['from_name_field'];
99
- }
100
- $from_email = $this->opts['from_email_field'];
101
- //set ReplyTo option if needed
102
- //this should be set before SetFrom, otherwise might be ignored
103
- if ( ! empty( $this->opts['reply_to_email'] ) ) {
104
- if ( isset( $this->opts['sub_mode'] ) && 1 === $this->opts['sub_mode'] ) {
105
- if ( count( $phpmailer->getReplyToAddresses() ) >= 1 ) {
106
- // Substitute from_email_field with reply_to_email
107
- if ( array_key_exists( $this->opts['from_email_field'], $phpmailer->getReplyToAddresses() ) ) {
108
- $reply_to_emails = $phpmailer->getReplyToAddresses();
109
- unset( $reply_to_emails[ $this->opts['from_email_field'] ] );
110
- $phpmailer->clearReplyTos();
111
- foreach ( $reply_to_emails as $reply_to_email => $reply_to_name ) {
112
- $phpmailer->AddReplyTo( $reply_to_email, $reply_to_name );
113
- }
114
- $phpmailer->AddReplyTo( $this->opts['reply_to_email'], $from_name );
115
- }
116
- } else { // Reply-to array is empty so add reply_to_email
117
- $phpmailer->AddReplyTo( $this->opts['reply_to_email'], $from_name );
118
- }
119
- } else { // Default behaviour
120
- $phpmailer->AddReplyTo( $this->opts['reply_to_email'], $from_name );
121
- }
122
- }
123
-
124
- if ( ! empty( $this->opts['bcc_email'] ) ) {
125
- $bcc_emails = explode( ',', $this->opts['bcc_email'] );
126
- foreach ( $bcc_emails as $bcc_email ) {
127
- $bcc_email = trim( $bcc_email );
128
- $phpmailer->AddBcc( $bcc_email );
129
- }
130
- }
131
-
132
- // let's see if we have email ignore list populated
133
- if ( isset( $this->opts['email_ignore_list'] ) && ! empty( $this->opts['email_ignore_list'] ) ) {
134
- $emails_arr = explode( ',', $this->opts['email_ignore_list'] );
135
- $from = $phpmailer->From;
136
- $match_found = false;
137
- foreach ( $emails_arr as $email ) {
138
- if ( strtolower( trim( $email ) ) === strtolower( trim( $from ) ) ) {
139
- $match_found = true;
140
- break;
141
- }
142
- }
143
- if ( $match_found ) {
144
- //we should not override From and Fromname
145
- $from_email = $phpmailer->From;
146
- $from_name = $phpmailer->FromName;
147
- }
148
- }
149
- $phpmailer->From = $from_email;
150
- $phpmailer->FromName = $from_name;
151
- $phpmailer->SetFrom( $phpmailer->From, $phpmailer->FromName );
152
- //This should set Return-Path header for servers that are not properly handling it, but needs testing first
153
- //$phpmailer->Sender = $phpmailer->From;
154
- /* Set the SMTPSecure value */
155
- if ( 'none' !== $this->opts['smtp_settings']['type_encryption'] ) {
156
- $phpmailer->SMTPSecure = $this->opts['smtp_settings']['type_encryption'];
157
- }
158
-
159
- /* Set the other options */
160
- $phpmailer->Host = $this->opts['smtp_settings']['host'];
161
- $phpmailer->Port = $this->opts['smtp_settings']['port'];
162
-
163
- /* If we're using smtp auth, set the username & password */
164
- if ( 'yes' === $this->opts['smtp_settings']['autentication'] ) {
165
- $phpmailer->SMTPAuth = true;
166
- $phpmailer->Username = $this->opts['smtp_settings']['username'];
167
- $phpmailer->Password = $this->get_password();
168
- }
169
- //PHPMailer 5.2.10 introduced this option. However, this might cause issues if the server is advertising TLS with an invalid certificate.
170
- $phpmailer->SMTPAutoTLS = false;
171
-
172
- if ( isset( $this->opts['smtp_settings']['insecure_ssl'] ) && false !== $this->opts['smtp_settings']['insecure_ssl'] ) {
173
- // Insecure SSL option enabled
174
- $phpmailer->SMTPOptions = array(
175
- 'ssl' => array(
176
- 'verify_peer' => false,
177
- 'verify_peer_name' => false,
178
- 'allow_self_signed' => true,
179
- ),
180
- );
181
- }
182
-
183
- if ( isset( $this->opts['smtp_settings']['enable_debug'] ) && $this->opts['smtp_settings']['enable_debug'] ) {
184
- $phpmailer->Debugoutput = function ( $str, $level ) {
185
- $this->log( $str );
186
- };
187
- $phpmailer->SMTPDebug = 1;
188
- }
189
- //set reasonable timeout
190
- $phpmailer->Timeout = 10;
191
- }
192
-
193
- public function test_mail( $to_email, $subject, $message ) {
194
- $ret = array();
195
- if ( ! $this->credentials_configured() ) {
196
- return false;
197
- }
198
-
199
- global $wp_version;
200
-
201
- if ( version_compare( $wp_version, '5.4.99' ) > 0 ) {
202
- require_once ABSPATH . WPINC . '/PHPMailer/PHPMailer.php';
203
- require_once ABSPATH . WPINC . '/PHPMailer/SMTP.php';
204
- require_once ABSPATH . WPINC . '/PHPMailer/Exception.php';
205
- $mail = new PHPMailer( true );
206
- } else {
207
- require_once ABSPATH . WPINC . '/class-phpmailer.php';
208
- $mail = new \PHPMailer( true );
209
- }
210
-
211
- try {
212
-
213
- $charset = get_bloginfo( 'charset' );
214
- $mail->CharSet = $charset;
215
-
216
- $from_name = $this->opts['from_name_field'];
217
- $from_email = $this->opts['from_email_field'];
218
-
219
- $mail->IsSMTP();
220
-
221
- // send plain text test email
222
- $mail->ContentType = 'text/plain';
223
- $mail->IsHTML( false );
224
-
225
- /* If using smtp auth, set the username & password */
226
- if ( 'yes' === $this->opts['smtp_settings']['autentication'] ) {
227
- $mail->SMTPAuth = true;
228
- $mail->Username = $this->opts['smtp_settings']['username'];
229
- $mail->Password = $this->get_password();
230
- }
231
-
232
- /* Set the SMTPSecure value, if set to none, leave this blank */
233
- if ( 'none' !== $this->opts['smtp_settings']['type_encryption'] ) {
234
- $mail->SMTPSecure = $this->opts['smtp_settings']['type_encryption'];
235
- }
236
-
237
- /* PHPMailer 5.2.10 introduced this option. However, this might cause issues if the server is advertising TLS with an invalid certificate. */
238
- $mail->SMTPAutoTLS = false;
239
-
240
- if ( isset( $this->opts['smtp_settings']['insecure_ssl'] ) && false !== $this->opts['smtp_settings']['insecure_ssl'] ) {
241
- // Insecure SSL option enabled
242
- $mail->SMTPOptions = array(
243
- 'ssl' => array(
244
- 'verify_peer' => false,
245
- 'verify_peer_name' => false,
246
- 'allow_self_signed' => true,
247
- ),
248
- );
249
- }
250
-
251
- /* Set the other options */
252
- $mail->Host = $this->opts['smtp_settings']['host'];
253
- $mail->Port = $this->opts['smtp_settings']['port'];
254
-
255
- //Add reply-to if set in settings.
256
- if ( ! empty( $this->opts['reply_to_email'] ) ) {
257
- $mail->AddReplyTo( $this->opts['reply_to_email'], $from_name );
258
- }
259
-
260
- //Add BCC if set in settings.
261
- if ( ! empty( $this->opts['bcc_email'] ) ) {
262
- $bcc_emails = explode( ',', $this->opts['bcc_email'] );
263
- foreach ( $bcc_emails as $bcc_email ) {
264
- $bcc_email = trim( $bcc_email );
265
- $mail->AddBcc( $bcc_email );
266
- }
267
- }
268
-
269
- $mail->SetFrom( $from_email, $from_name );
270
- //This should set Return-Path header for servers that are not properly handling it, but needs testing first
271
- //$mail->Sender = $mail->From;
272
- $mail->Subject = $subject;
273
- $mail->Body = $message;
274
- $mail->AddAddress( $to_email );
275
- global $debug_msg;
276
- $debug_msg = '';
277
- $mail->Debugoutput = function ( $str, $level ) {
278
- global $debug_msg;
279
- $debug_msg .= $str;
280
- };
281
- $mail->SMTPDebug = 1;
282
- //set reasonable timeout
283
- $mail->Timeout = 10;
284
-
285
- /* Send mail and return result */
286
- $mail->Send();
287
- $mail->ClearAddresses();
288
- $mail->ClearAllRecipients();
289
- } catch ( \Exception $e ) {
290
- $ret['error'] = $mail->ErrorInfo;
291
- } catch ( \Throwable $e ) {
292
- $ret['error'] = $mail->ErrorInfo;
293
- }
294
-
295
- $ret['debug_log'] = $debug_msg;
296
-
297
- return $ret;
298
- }
299
-
300
- public function admin_init() {
301
- if ( current_user_can( 'manage_options' ) ) {
302
- if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
303
- add_action( 'wp_ajax_swpsmtp_clear_log', array( $this, 'clear_log' ) );
304
- add_action( 'wp_ajax_swpsmtp_self_destruct', array( $this, 'self_destruct_handler' ) );
305
- }
306
- //view log file
307
- if ( isset( $_GET['swpsmtp_action'] ) ) {
308
- if ( 'view_log' === $_GET['swpsmtp_action'] ) {
309
- $log_file_name = isset( $this->opts['smtp_settings']['log_file_name'] ) ? $this->opts['smtp_settings']['log_file_name'] : '';
310
-
311
- if ( empty( $log_file_name ) ) {
312
- //Nothing in the log file yet so nothing to show.
313
- wp_die( 'Nothing in the log file yet.' );
314
- }
315
-
316
- if ( ! file_exists( plugin_dir_path( __FILE__ ) . $log_file_name ) ) {
317
- if ( $this->log( self::$reset_log_str ) === false ) {
318
- wp_die( esc_html( sprintf( 'Can\'t write to log file. Check if plugin directory (%s) is writeable.', plugin_dir_path( __FILE__ ) ) ) );
319
- };
320
- }
321
- $logfile = fopen( plugin_dir_path( __FILE__ ) . $log_file_name, 'rb' ); //phpcs:ignore
322
- if ( ! $logfile ) {
323
- wp_die( 'Can\'t open log file.' );
324
- }
325
- header( 'Content-Type: text/plain' );
326
- fpassthru( $logfile );
327
- die;
328
- }
329
- }
330
-
331
- //check if this is export settings request
332
- $is_export_settings = filter_input( INPUT_POST, 'swpsmtp_export_settings', FILTER_SANITIZE_NUMBER_INT );
333
- if ( $is_export_settings ) {
334
- check_admin_referer( 'easy_wp_smtp_export_settings', 'easy_wp_smtp_export_settings_nonce' );
335
- $data = array();
336
- $opts = get_option( 'swpsmtp_options', array() );
337
- $data['swpsmtp_options'] = $opts;
338
- $swpsmtp_pass_encrypted = get_option( 'swpsmtp_pass_encrypted', false );
339
- $data['swpsmtp_pass_encrypted'] = $swpsmtp_pass_encrypted;
340
- if ( $swpsmtp_pass_encrypted ) {
341
- $swpsmtp_enc_key = get_option( 'swpsmtp_enc_key', false );
342
- $data['swpsmtp_enc_key'] = $swpsmtp_enc_key;
343
- }
344
- $smtp_test_mail = get_option( 'smtp_test_mail', array() );
345
- $data['smtp_test_mail'] = $smtp_test_mail;
346
- $out = array();
347
- $out['data'] = wp_json_encode( $data );
348
- $out['ver'] = 2;
349
- $out['checksum'] = md5( $out['data'] );
350
-
351
- $filename = 'easy_wp_smtp_settings.json';
352
- header( 'Content-Disposition: attachment; filename="' . $filename . '"' );
353
- header( 'Content-Type: application/json' );
354
- echo wp_json_encode( $out );
355
- exit;
356
- }
357
-
358
- $is_import_settings = filter_input( INPUT_POST, 'swpsmtp_import_settings', FILTER_SANITIZE_NUMBER_INT );
359
- if ( $is_import_settings ) {
360
- check_admin_referer( 'easy_wp_smtp_import_settings', 'easy_wp_smtp_import_settings_nonce' );
361
- $err_msg = __( 'Error occurred during settings import', 'easy-wp-smtp' );
362
- if ( empty( $_FILES['swpsmtp_import_settings_file'] ) ) {
363
- echo esc_html( $err_msg );
364
- wp_die();
365
- }
366
- $in_raw = file_get_contents( $_FILES['swpsmtp_import_settings_file']['tmp_name'] ); //phpcs:ignore
367
- try {
368
- $in = json_decode( $in_raw, true );
369
- if ( json_last_error() !== 0 ) {
370
- $in = unserialize( $in_raw ); //phpcs:ignore
371
- }
372
- if ( empty( $in['data'] ) ) {
373
- echo esc_html( $err_msg );
374
- wp_die();
375
- }
376
- if ( empty( $in['checksum'] ) ) {
377
- echo esc_html( $err_msg );
378
- wp_die();
379
- }
380
- if ( md5( $in['data'] ) !== $in['checksum'] ) {
381
- echo esc_html( $err_msg );
382
- wp_die();
383
- }
384
- $data = json_decode( $in['data'], true );
385
- if ( json_last_error() !== 0 ) {
386
- $data = unserialize( $in['data'] ); //phpcs:ignore
387
- }
388
- update_option( 'swpsmtp_options', $data['swpsmtp_options'] );
389
- update_option( 'swpsmtp_pass_encrypted', $data['swpsmtp_pass_encrypted'] );
390
- if ( $data['swpsmtp_pass_encrypted'] ) {
391
- update_option( 'swpsmtp_enc_key', $data['swpsmtp_enc_key'] );
392
- }
393
- update_option( 'smtp_test_mail', $data['smtp_test_mail'] );
394
- set_transient( 'easy_wp_smtp_settings_import_success', true, 60 * 60 );
395
- $url = admin_url() . 'options-general.php?page=swpsmtp_settings';
396
- wp_safe_redirect( $url );
397
- exit;
398
- } catch ( Exception $ex ) {
399
- echo esc_html( $err_msg );
400
- wp_die();
401
- }
402
- }
403
- }
404
- }
405
-
406
- public function admin_notices() {
407
- if ( ! $this->credentials_configured() ) {
408
- $settings_url = admin_url() . 'options-general.php?page=swpsmtp_settings';
409
- ?>
410
- <div class="error">
411
- <p>
412
- <?php
413
- 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 ) );
414
- ?>
415
- </p>
416
- </div>
417
- <?php
418
- }
419
-
420
- $settings_import_notice = get_transient( 'easy_wp_smtp_settings_import_success' );
421
- if ( $settings_import_notice ) {
422
- delete_transient( 'easy_wp_smtp_settings_import_success' );
423
- ?>
424
- <div class="updated">
425
- <p><?php echo esc_html( __( 'Settings have been imported successfully.', 'easy-wp-smtp' ) ); ?></p>
426
- </div>
427
- <?php
428
- }
429
- }
430
-
431
- public function get_log_file_path() {
432
- $log_file_name = 'logs' . DIRECTORY_SEPARATOR . '.' . uniqid( '', true ) . '.txt';
433
- $log_file_name = apply_filters( 'swpsmtp_log_file_path_override', $log_file_name );
434
- return $log_file_name;
435
- }
436
-
437
- public function clear_log() {
438
- if ( ! check_ajax_referer( 'easy-wp-smtp-clear-log', 'nonce', false ) ) {
439
- echo esc_html( __( 'Nonce check failed.', 'easy-wp-smtp' ) );
440
- exit;
441
- };
442
- if ( $this->log( self::$reset_log_str, true ) !== false ) {
443
- echo '1';
444
- } else {
445
- echo esc_html( __( "Can't clear log - file is not writeable.", 'easy-wp-smtp' ) );
446
- }
447
- die;
448
- }
449
-
450
- public function log( $str, $overwrite = false ) {
451
- try {
452
- $log_file_name = '';
453
- if ( isset( $this->opts['smtp_settings']['log_file_name'] ) ) {
454
- $log_file_name = $this->opts['smtp_settings']['log_file_name'];
455
- }
456
- if ( empty( $log_file_name ) || $overwrite ) {
457
- if ( ! empty( $log_file_name ) && file_exists( plugin_dir_path( __FILE__ ) . $log_file_name ) ) {
458
- unlink( plugin_dir_path( __FILE__ ) . $log_file_name );
459
- }
460
- $log_file_name = $this->get_log_file_path();
461
-
462
- $this->opts['smtp_settings']['log_file_name'] = $log_file_name;
463
- update_option( 'swpsmtp_options', $this->opts );
464
- file_put_contents( plugin_dir_path( __FILE__ ) . $log_file_name, self::$reset_log_str ); //phpcs:ignore
465
- }
466
- return ( file_put_contents( plugin_dir_path( __FILE__ ) . $log_file_name, $str, ( ! $overwrite ? FILE_APPEND : 0 ) ) ); //phpcs:ignore
467
- } catch ( \Exception $e ) {
468
- return false;
469
- }
470
- }
471
-
472
- public function plugin_action_links( $links, $file ) {
473
- if ( plugin_basename( $this->plugin_file ) === $file ) {
474
- $settings_link = '<a href="options-general.php?page=swpsmtp_settings">' . __( 'Settings', 'easy-wp-smtp' ) . '</a>';
475
- array_unshift( $links, $settings_link );
476
- }
477
- return $links;
478
- }
479
-
480
- public function register_plugin_links( $links, $file ) {
481
- if ( plugin_basename( $this->plugin_file ) === $file ) {
482
- $links[] = '<a href="options-general.php?page=swpsmtp_settings">' . __( 'Settings', 'easy-wp-smtp' ) . '</a>';
483
- }
484
- return $links;
485
- }
486
-
487
- public function plugins_loaded_handler() {
488
- load_plugin_textdomain( 'easy-wp-smtp', false, dirname( plugin_basename( $this->plugin_file ) ) . '/languages/' );
489
- }
490
-
491
- public function is_domain_blocked() {
492
- //check if Domain Check enabled
493
- if ( isset( $this->opts['enable_domain_check'] ) && $this->opts['enable_domain_check'] ) {
494
- //check if allowed domains list is not blank
495
- if ( isset( $this->opts['allowed_domains'] ) && ! empty( $this->opts['allowed_domains'] ) ) {
496
- $this->opts['allowed_domains'] = EasyWPSMTP_Utils::base64_decode_maybe( $this->opts['allowed_domains'] );
497
- //let's see if we have one domain or coma-separated domains
498
- $domains_arr = explode( ',', $this->opts['allowed_domains'] );
499
- //TODO: Change parse_url() to wp_parse_url() and bump required WP version to 4.4.0
500
- $site_domain = parse_url( get_site_url(), PHP_URL_HOST ); //phpcs:ignore
501
- $match_found = false;
502
- foreach ( $domains_arr as $domain ) {
503
- if ( strtolower( trim( $domain ) ) === strtolower( trim( $site_domain ) ) ) {
504
- $match_found = true;
505
- break;
506
- }
507
- }
508
- if ( ! $match_found ) {
509
- return $site_domain;
510
- }
511
- }
512
- }
513
- return false;
514
- }
515
-
516
- public function get_password() {
517
- $temp_password = isset( $this->opts['smtp_settings']['password'] ) ? $this->opts['smtp_settings']['password'] : '';
518
- if ( '' === $temp_password ) {
519
- return '';
520
- }
521
-
522
- try {
523
-
524
- if ( get_option( 'swpsmtp_pass_encrypted' ) ) {
525
- //this is encrypted password
526
- $cryptor = EasyWPSMTP_Utils::get_instance();
527
- $decrypted = $cryptor->decrypt_password( $temp_password );
528
- //check if encryption option is disabled
529
- if ( empty( $this->opts['smtp_settings']['encrypt_pass'] ) ) {
530
- //it is. let's save decrypted password
531
- $this->opts['smtp_settings']['password'] = $this->encrypt_password( addslashes( $decrypted ) );
532
- update_option( 'swpsmtp_options', $this->opts );
533
- }
534
- return $decrypted;
535
- }
536
- } catch ( Exception $e ) {
537
- $this->log( $e->getMessage() );
538
- return '';
539
- }
540
-
541
- $password = '';
542
- $decoded_pass = base64_decode( $temp_password ); //phpcs:ignore
543
- /* no additional checks for servers that aren't configured with mbstring enabled */
544
- if ( ! function_exists( 'mb_detect_encoding' ) ) {
545
- return $decoded_pass;
546
- }
547
- /* end of mbstring check */
548
- if ( base64_encode( $decoded_pass ) === $temp_password ) { //phpcs:ignore
549
- //it might be encoded
550
- if ( false === mb_detect_encoding( $decoded_pass ) ) { //could not find character encoding.
551
- $password = $temp_password;
552
- } else {
553
- $password = base64_decode( $temp_password ); //phpcs:ignore
554
- }
555
- } else { //not encoded
556
- $password = $temp_password;
557
- }
558
- return stripslashes( $password );
559
- }
560
-
561
- public function encrypt_password( $pass ) {
562
- if ( '' === $pass ) {
563
- return '';
564
- }
565
-
566
- if ( empty( $this->opts['smtp_settings']['encrypt_pass'] ) || ! extension_loaded( 'openssl' ) ) {
567
- // no openssl extension loaded - we can't encrypt the password
568
- $password = base64_encode( $pass ); //phpcs:ignore
569
- update_option( 'swpsmtp_pass_encrypted', false );
570
- } else {
571
- // let's encrypt password
572
- $cryptor = EasyWPSMTP_Utils::get_instance();
573
- $password = $cryptor->encrypt_password( $pass );
574
- update_option( 'swpsmtp_pass_encrypted', true );
575
- }
576
- return $password;
577
- }
578
-
579
- public function credentials_configured() {
580
- $credentials_configured = true;
581
- if ( ! isset( $this->opts['from_email_field'] ) || empty( $this->opts['from_email_field'] ) ) {
582
- $credentials_configured = false;
583
- }
584
- if ( ! isset( $this->opts['from_name_field'] ) || empty( $this->opts['from_name_field'] ) ) {
585
- $credentials_configured = false;
586
- }
587
- return $credentials_configured;
588
- }
589
-
590
- public function activate() {
591
- $swpsmtp_options_default = array(
592
- 'from_email_field' => '',
593
- 'from_name_field' => '',
594
- 'force_from_name_replace' => 0,
595
- 'sub_mode' => 0,
596
- 'smtp_settings' => array(
597
- 'host' => 'smtp.example.com',
598
- 'type_encryption' => 'none',
599
- 'port' => 25,
600
- 'autentication' => 'yes',
601
- 'username' => '',
602
- 'password' => '',
603
- ),
604
- );
605
-
606
- /* install the default plugin options if needed */
607
- if ( empty( $this->opts ) ) {
608
- $this->opts = $swpsmtp_options_default;
609
- }
610
- $this->opts = array_merge( $swpsmtp_options_default, $this->opts );
611
- // reset log file
612
- $this->log( self::$reset_log_str, true );
613
- update_option( 'swpsmtp_options', $this->opts, 'yes' );
614
- //add current domain to allowed domains list
615
- if ( ! isset( $this->opts['allowed_domains'] ) ) {
616
- //TODO: Change parse_url() to wp_parse_url() and bump required WP version to 4.4.0
617
- $domain = parse_url( get_site_url(), PHP_URL_HOST ); //phpcs:ignore
618
- if ( $domain ) {
619
- $this->opts['allowed_domains'] = base64_encode( $domain ); //phpcs:ignore
620
- update_option( 'swpsmtp_options', $this->opts );
621
- }
622
- } else { // let's check if existing value should be base64 encoded
623
- if ( ! empty( $this->opts['allowed_domains'] ) ) {
624
- if ( EasyWPSMTP_Utils::base64_decode_maybe( $this->opts['allowed_domains'] ) === $this->opts['allowed_domains'] ) {
625
- $this->opts['allowed_domains'] = base64_encode( $this->opts['allowed_domains'] ); //phpcs:ignore
626
- update_option( 'swpsmtp_options', $this->opts );
627
- }
628
- }
629
- }
630
- // Encrypt password if needed
631
- if ( ! get_option( 'swpsmtp_pass_encrypted' ) ) {
632
- if ( extension_loaded( 'openssl' ) ) {
633
- if ( '' !== $this->opts['smtp_settings']['password'] ) {
634
- $this->opts['smtp_settings']['password'] = $this->encrypt_password( $this->get_password() );
635
- update_option( 'swpsmtp_options', $this->opts );
636
- }
637
- }
638
- }
639
- }
640
-
641
- public function deactivate() {
642
- // reset log file
643
- $this->log( self::$reset_log_str, true );
644
- }
645
-
646
- public function self_destruct_handler() {
647
- $err_msg = __( 'Please refresh the page and try again.', 'easy-wp-smtp' );
648
- $trans = get_transient( 'easy_wp_smtp_sd_code' );
649
- if ( empty( $trans ) ) {
650
- echo esc_html( $err_msg );
651
- exit;
652
- }
653
- $sd_code = filter_input( INPUT_POST, 'sd_code', FILTER_SANITIZE_STRING );
654
- if ( $trans !== $sd_code ) {
655
- echo esc_html( $err_msg );
656
- exit;
657
- }
658
- $this->log( self::$reset_log_str, true );
659
- delete_site_option( 'swpsmtp_options' );
660
- delete_option( 'swpsmtp_options' );
661
- delete_site_option( 'smtp_test_mail' );
662
- delete_option( 'smtp_test_mail' );
663
- delete_site_option( 'swpsmtp_pass_encrypted' );
664
- delete_option( 'swpsmtp_pass_encrypted' );
665
- delete_option( 'swpsmtp_enc_key' );
666
- echo 1;
667
- deactivate_plugins( __FILE__ );
668
- exit;
669
- }
670
- }
671
-
672
- EasyWPSMTP::get_instance();
673
-
674
- function swpsmtp_uninstall() {
675
- // Don't delete plugin options. It is better to retain the options so if someone accidentally deactivates, the configuration is not lost.
676
- //delete_site_option('swpsmtp_options');
677
- //delete_option('swpsmtp_options');
678
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ use PHPMailer\PHPMailer\PHPMailer;
3
+ use PHPMailer\PHPMailer\Exception;
4
+ /*
5
+ Plugin Name: Easy WP SMTP
6
+ Version: 1.5.0
7
+ Plugin URI: https://wp-ecommerce.net/easy-wordpress-smtp-send-emails-from-your-wordpress-site-using-a-smtp-server-2197
8
+ Author: wpecommerce, alexanderfoxc
9
+ Author URI: https://wp-ecommerce.net/
10
+ Description: Send email via SMTP from your WordPress Blog
11
+ Text Domain: easy-wp-smtp
12
+ Domain Path: /languages
13
+ */
14
+
15
+ //Prefix/Slug - swpsmtp
16
+
17
+ class EasyWPSMTP {
18
+
19
+ public $opts;
20
+ public $plugin_file;
21
+ protected static $instance = null;
22
+ public static $reset_log_str = "Easy WP SMTP debug log file\r\n\r\n";
23
+
24
+ public function __construct() {
25
+ $this->opts = get_option( 'swpsmtp_options' );
26
+ $this->opts = ! is_array( $this->opts ) ? array() : $this->opts;
27
+ $this->plugin_file = __FILE__;
28
+ require_once 'class-easywpsmtp-utils.php';
29
+
30
+ add_action( 'plugins_loaded', array( $this, 'plugins_loaded_handler' ) );
31
+ add_filter( 'wp_mail', array( $this, 'wp_mail' ), 2147483647 );
32
+ add_action( 'phpmailer_init', array( $this, 'init_smtp' ), 999 );
33
+ add_action( 'admin_init', array( $this, 'admin_init' ) );
34
+
35
+ if ( ! empty( $this->opts['smtp_settings']['enable_debug'] ) ) {
36
+ add_action( 'wp_mail_failed', array( $this, 'wp_mail_failed' ) );
37
+ }
38
+
39
+ if ( is_admin() && ! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
40
+ require_once 'class-easywpsmtp-admin.php';
41
+ register_activation_hook( __FILE__, array( $this, 'activate' ) );
42
+ register_deactivation_hook( __FILE__, array( $this, 'deactivate' ) );
43
+ register_uninstall_hook( __FILE__, 'swpsmtp_uninstall' );
44
+ add_filter( 'plugin_action_links', array( $this, 'plugin_action_links' ), 10, 2 );
45
+ add_filter( 'plugin_row_meta', array( $this, 'register_plugin_links' ), 10, 2 );
46
+ add_action( 'admin_notices', array( $this, 'admin_notices' ) );
47
+ }
48
+ }
49
+
50
+ public static function get_instance() {
51
+ if ( null === self::$instance ) {
52
+ self::$instance = new self();
53
+ }
54
+ return self::$instance;
55
+ }
56
+
57
+ public function wp_mail( $args ) {
58
+ $domain = $this->is_domain_blocked();
59
+ if ( false !== $domain && ( isset( $this->opts['block_all_emails'] ) && 1 === $this->opts['block_all_emails'] ) ) {
60
+ $this->log(
61
+ "\r\n------------------------------------------------------------------------------------------------------\r\n" .
62
+ 'Domain check failed: website domain (' . $domain . ") is not in allowed domains list.\r\n" .
63
+ "Following email not sent (block all emails option is enabled):\r\n" .
64
+ 'To: ' . $args['to'] . '; Subject: ' . $args['subject'] . "\r\n" .
65
+ "------------------------------------------------------------------------------------------------------\r\n\r\n"
66
+ );
67
+ return $args;
68
+ }
69
+
70
+ if ( ! empty( $this->opts['smtp_settings']['enable_debug'] ) ) {
71
+ //Check if the "to" field has multiple emails in an array.
72
+ $to_address = "";
73
+ if ( !empty( $args['to'] ) ) {
74
+ $to_address = is_array( $args['to'] ) ? implode( ' ; ', $args['to'] ) : $args['to'];
75
+ }
76
+ //Prepare the debug logging line
77
+ $line = sprintf(
78
+ 'Headers: %s, To: %s, Subject: %s',
79
+ ! empty( $args['headers'] && is_array( $args['headers'] ) ) ? implode( ' | ', $args['headers'] ) : '',
80
+ ! empty( $args['to'] ) ? $to_address : '',
81
+ ! empty( $args['subject'] ) ? $args['subject'] : ''
82
+ );
83
+ $this->log( $line . "\r\n" );
84
+ }
85
+
86
+ return $args;
87
+ }
88
+
89
+ public function wp_mail_failed( $wp_error ) {
90
+ if ( ! empty( $wp_error->errors ) && ! empty( $wp_error->errors['wp_mail_failed'] ) && is_array( $wp_error->errors['wp_mail_failed'] ) ) {
91
+ $this->log( '*** ' . implode( ' | ', $wp_error->errors['wp_mail_failed'] ) . " ***\r\n" );
92
+ }
93
+ }
94
+
95
+ public function init_smtp( &$phpmailer ) {
96
+ //check if SMTP credentials have been configured.
97
+ if ( ! $this->credentials_configured() ) {
98
+ return;
99
+ }
100
+ //check if Domain Check enabled
101
+ $domain = $this->is_domain_blocked();
102
+ if ( false !== $domain ) {
103
+ //domain check failed
104
+ //let's check if we have block all emails option enabled
105
+ if ( isset( $this->opts['block_all_emails'] ) && 1 === $this->opts['block_all_emails'] ) {
106
+ // it's enabled. Let's use gag mailer class that would prevent emails from being sent out.
107
+ require_once 'class-easywpsmtp-gag-mailer.php';
108
+ $phpmailer = new EasyWPSMTP_Gag_Mailer();
109
+ } else {
110
+ // it's disabled. Let's write some info to the log
111
+ $this->log(
112
+ "\r\n------------------------------------------------------------------------------------------------------\r\n" .
113
+ 'Domain check failed: website domain (' . $domain . ") is not in allowed domains list.\r\n" .
114
+ "SMTP settings won't be used.\r\n" .
115
+ "------------------------------------------------------------------------------------------------------\r\n\r\n"
116
+ );
117
+ }
118
+ return;
119
+ }
120
+
121
+ /* Set the mailer type as per config above, this overrides the already called isMail method */
122
+ $phpmailer->IsSMTP();
123
+ if ( isset( $this->opts['force_from_name_replace'] ) && 1 === $this->opts['force_from_name_replace'] ) {
124
+ $from_name = $this->opts['from_name_field'];
125
+ } else {
126
+ $from_name = ! empty( $phpmailer->FromName ) ? $phpmailer->FromName : $this->opts['from_name_field'];
127
+ }
128
+ $from_email = $this->opts['from_email_field'];
129
+ //set ReplyTo option if needed
130
+ //this should be set before SetFrom, otherwise might be ignored
131
+ if ( ! empty( $this->opts['reply_to_email'] ) ) {
132
+ if ( isset( $this->opts['sub_mode'] ) && 1 === $this->opts['sub_mode'] ) {
133
+ if ( count( $phpmailer->getReplyToAddresses() ) >= 1 ) {
134
+ // Substitute from_email_field with reply_to_email
135
+ if ( array_key_exists( $this->opts['from_email_field'], $phpmailer->getReplyToAddresses() ) ) {
136
+ $reply_to_emails = $phpmailer->getReplyToAddresses();
137
+ unset( $reply_to_emails[ $this->opts['from_email_field'] ] );
138
+ $phpmailer->clearReplyTos();
139
+ foreach ( $reply_to_emails as $reply_to_email => $reply_to_name ) {
140
+ $phpmailer->AddReplyTo( $reply_to_email, $reply_to_name );
141
+ }
142
+ $phpmailer->AddReplyTo( $this->opts['reply_to_email'], $from_name );
143
+ }
144
+ } else { // Reply-to array is empty so add reply_to_email
145
+ $phpmailer->AddReplyTo( $this->opts['reply_to_email'], $from_name );
146
+ }
147
+ } else { // Default behaviour
148
+ $phpmailer->AddReplyTo( $this->opts['reply_to_email'], $from_name );
149
+ }
150
+ }
151
+
152
+ if ( ! empty( $this->opts['bcc_email'] ) ) {
153
+ $bcc_emails = explode( ',', $this->opts['bcc_email'] );
154
+ foreach ( $bcc_emails as $bcc_email ) {
155
+ $bcc_email = trim( $bcc_email );
156
+ $phpmailer->AddBcc( $bcc_email );
157
+ }
158
+ }
159
+
160
+ // let's see if we have email ignore list populated
161
+ if ( isset( $this->opts['email_ignore_list'] ) && ! empty( $this->opts['email_ignore_list'] ) ) {
162
+ $emails_arr = explode( ',', $this->opts['email_ignore_list'] );
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
+ //This should set Return-Path header for servers that are not properly handling it, but needs testing first
181
+ //$phpmailer->Sender = $phpmailer->From;
182
+ /* Set the SMTPSecure value */
183
+ if ( 'none' !== $this->opts['smtp_settings']['type_encryption'] ) {
184
+ $phpmailer->SMTPSecure = $this->opts['smtp_settings']['type_encryption'];
185
+ }
186
+
187
+ /* Set the other options */
188
+ $phpmailer->Host = $this->opts['smtp_settings']['host'];
189
+ $phpmailer->Port = $this->opts['smtp_settings']['port'];
190
+
191
+ /* If we're using smtp auth, set the username & password */
192
+ $phpmailer->SMTPAuth = false;
193
+ if ( 'yes' === $this->opts['smtp_settings']['autentication'] ) {
194
+ $phpmailer->SMTPAuth = true;
195
+ $phpmailer->Username = $this->opts['smtp_settings']['username'];
196
+ $phpmailer->Password = $this->get_password();
197
+ }
198
+ //PHPMailer 5.2.10 introduced this option. However, this might cause issues if the server is advertising TLS with an invalid certificate.
199
+ $phpmailer->SMTPAutoTLS = false;
200
+
201
+ if ( isset( $this->opts['smtp_settings']['insecure_ssl'] ) && false !== $this->opts['smtp_settings']['insecure_ssl'] ) {
202
+ // Insecure SSL option enabled
203
+ $phpmailer->SMTPOptions = array(
204
+ 'ssl' => array(
205
+ 'verify_peer' => false,
206
+ 'verify_peer_name' => false,
207
+ 'allow_self_signed' => true,
208
+ ),
209
+ );
210
+ }
211
+
212
+ //set reasonable timeout
213
+ $phpmailer->Timeout = 10;
214
+ }
215
+
216
+ public function test_mail( $to_email, $subject, $message ) {
217
+ $ret = array();
218
+ if ( ! $this->credentials_configured() ) {
219
+ return false;
220
+ }
221
+
222
+ global $wp_version;
223
+
224
+ if ( version_compare( $wp_version, '5.4.99' ) > 0 ) {
225
+ require_once ABSPATH . WPINC . '/PHPMailer/PHPMailer.php';
226
+ require_once ABSPATH . WPINC . '/PHPMailer/SMTP.php';
227
+ require_once ABSPATH . WPINC . '/PHPMailer/Exception.php';
228
+ $mail = new PHPMailer( true );
229
+ } else {
230
+ require_once ABSPATH . WPINC . '/class-phpmailer.php';
231
+ $mail = new \PHPMailer( true );
232
+ }
233
+
234
+ try {
235
+
236
+ $charset = get_bloginfo( 'charset' );
237
+ $mail->CharSet = $charset;
238
+
239
+ $from_name = $this->opts['from_name_field'];
240
+ $from_email = $this->opts['from_email_field'];
241
+
242
+ $mail->IsSMTP();
243
+
244
+ // send plain text test email
245
+ $mail->ContentType = 'text/plain';
246
+ $mail->IsHTML( false );
247
+
248
+ /* If using smtp auth, set the username & password */
249
+ if ( 'yes' === $this->opts['smtp_settings']['autentication'] ) {
250
+ $mail->SMTPAuth = true;
251
+ $mail->Username = $this->opts['smtp_settings']['username'];
252
+ $mail->Password = $this->get_password();
253
+ }
254
+
255
+ /* Set the SMTPSecure value, if set to none, leave this blank */
256
+ if ( 'none' !== $this->opts['smtp_settings']['type_encryption'] ) {
257
+ $mail->SMTPSecure = $this->opts['smtp_settings']['type_encryption'];
258
+ }
259
+
260
+ /* PHPMailer 5.2.10 introduced this option. However, this might cause issues if the server is advertising TLS with an invalid certificate. */
261
+ $mail->SMTPAutoTLS = false;
262
+
263
+ if ( isset( $this->opts['smtp_settings']['insecure_ssl'] ) && false !== $this->opts['smtp_settings']['insecure_ssl'] ) {
264
+ // Insecure SSL option enabled
265
+ $mail->SMTPOptions = array(
266
+ 'ssl' => array(
267
+ 'verify_peer' => false,
268
+ 'verify_peer_name' => false,
269
+ 'allow_self_signed' => true,
270
+ ),
271
+ );
272
+ }
273
+
274
+ /* Set the other options */
275
+ $mail->Host = $this->opts['smtp_settings']['host'];
276
+ $mail->Port = $this->opts['smtp_settings']['port'];
277
+
278
+ //Add reply-to if set in settings.
279
+ if ( ! empty( $this->opts['reply_to_email'] ) ) {
280
+ $mail->AddReplyTo( $this->opts['reply_to_email'], $from_name );
281
+ }
282
+
283
+ //Add BCC if set in settings.
284
+ if ( ! empty( $this->opts['bcc_email'] ) ) {
285
+ $bcc_emails = explode( ',', $this->opts['bcc_email'] );
286
+ foreach ( $bcc_emails as $bcc_email ) {
287
+ $bcc_email = trim( $bcc_email );
288
+ $mail->AddBcc( $bcc_email );
289
+ }
290
+ }
291
+
292
+ $mail->SetFrom( $from_email, $from_name );
293
+ //This should set Return-Path header for servers that are not properly handling it, but needs testing first
294
+ //$mail->Sender = $mail->From;
295
+ $mail->Subject = $subject;
296
+ $mail->Body = $message;
297
+ $mail->AddAddress( $to_email );
298
+ global $debug_msg;
299
+ $debug_msg = '';
300
+ $mail->Debugoutput = function ( $str, $level ) {
301
+ global $debug_msg;
302
+ $debug_msg .= $str;
303
+ };
304
+ $mail->SMTPDebug = 1;
305
+ //set reasonable timeout
306
+ $mail->Timeout = 10;
307
+
308
+ /* Send mail and return result */
309
+ $mail->Send();
310
+ $mail->ClearAddresses();
311
+ $mail->ClearAllRecipients();
312
+ } catch ( \Exception $e ) {
313
+ $ret['error'] = $mail->ErrorInfo;
314
+ } catch ( \Throwable $e ) {
315
+ $ret['error'] = $mail->ErrorInfo;
316
+ }
317
+
318
+ $ret['debug_log'] = $debug_msg;
319
+
320
+ return $ret;
321
+ }
322
+
323
+ public function admin_init() {
324
+ if ( current_user_can( 'manage_options' ) ) {
325
+ if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
326
+ add_action( 'wp_ajax_swpsmtp_clear_log', array( $this, 'clear_log' ) );
327
+ add_action( 'wp_ajax_swpsmtp_self_destruct', array( $this, 'self_destruct_handler' ) );
328
+ }
329
+ //view log file
330
+ if ( isset( $_GET['swpsmtp_action'] ) ) {
331
+ if ( 'view_log' === $_GET['swpsmtp_action'] ) {
332
+ $log_file_name = isset( $this->opts['smtp_settings']['log_file_name'] ) ? $this->opts['smtp_settings']['log_file_name'] : '';
333
+
334
+ if ( empty( $log_file_name ) ) {
335
+ //Nothing in the log file yet so nothing to show.
336
+ wp_die( 'Nothing in the log file yet.' );
337
+ }
338
+
339
+ if ( ! file_exists( plugin_dir_path( __FILE__ ) . $log_file_name ) ) {
340
+ if ( $this->log( self::$reset_log_str ) === false ) {
341
+ wp_die( esc_html( sprintf( 'Can\'t write to log file. Check if plugin directory (%s) is writeable.', plugin_dir_path( __FILE__ ) ) ) );
342
+ };
343
+ }
344
+ $logfile = fopen( plugin_dir_path( __FILE__ ) . $log_file_name, 'rb' ); //phpcs:ignore
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
+ //check if this is export settings request
355
+ $is_export_settings = filter_input( INPUT_POST, 'swpsmtp_export_settings', FILTER_SANITIZE_NUMBER_INT );
356
+ if ( $is_export_settings ) {
357
+ check_admin_referer( 'easy_wp_smtp_export_settings', 'easy_wp_smtp_export_settings_nonce' );
358
+ $data = array();
359
+ $opts = get_option( 'swpsmtp_options', array() );
360
+ $data['swpsmtp_options'] = $opts;
361
+ $swpsmtp_pass_encrypted = get_option( 'swpsmtp_pass_encrypted', false );
362
+ $data['swpsmtp_pass_encrypted'] = $swpsmtp_pass_encrypted;
363
+ if ( $swpsmtp_pass_encrypted ) {
364
+ $swpsmtp_enc_key = get_option( 'swpsmtp_enc_key', false );
365
+ $data['swpsmtp_enc_key'] = $swpsmtp_enc_key;
366
+ }
367
+ $smtp_test_mail = get_option( 'smtp_test_mail', array() );
368
+ $data['smtp_test_mail'] = $smtp_test_mail;
369
+ $out = array();
370
+ $out['data'] = wp_json_encode( $data );
371
+ $out['ver'] = 2;
372
+ $out['checksum'] = md5( $out['data'] );
373
+
374
+ $filename = 'easy_wp_smtp_settings.json';
375
+ header( 'Content-Disposition: attachment; filename="' . $filename . '"' );
376
+ header( 'Content-Type: application/json' );
377
+ echo wp_json_encode( $out );
378
+ exit;
379
+ }
380
+
381
+ $is_import_settings = filter_input( INPUT_POST, 'swpsmtp_import_settings', FILTER_SANITIZE_NUMBER_INT );
382
+ if ( $is_import_settings ) {
383
+ check_admin_referer( 'easy_wp_smtp_import_settings', 'easy_wp_smtp_import_settings_nonce' );
384
+ $err_msg = __( 'Error occurred during settings import', 'easy-wp-smtp' );
385
+ if ( empty( $_FILES['swpsmtp_import_settings_file'] ) ) {
386
+ echo esc_html( $err_msg );
387
+ wp_die();
388
+ }
389
+ $in_raw = file_get_contents( $_FILES['swpsmtp_import_settings_file']['tmp_name'] ); //phpcs:ignore
390
+
391
+
392
+ try {
393
+
394
+ $in = json_decode( $in_raw, true );
395
+
396
+ //if json_decode has errors
397
+ if ( json_last_error() !== 0 ) {
398
+
399
+ echo __("Error importing the settings file. Please re-export the file",'easy-wp-smtp');
400
+ wp_die();
401
+ }
402
+ if ( empty( $in['data'] ) ) {
403
+ echo esc_html( $err_msg );
404
+ wp_die();
405
+ }
406
+ if ( empty( $in['checksum'] ) ) {
407
+ echo esc_html( $err_msg );
408
+ wp_die();
409
+ }
410
+ if ( md5( $in['data'] ) !== $in['checksum'] ) {
411
+ echo esc_html( $err_msg );
412
+ wp_die();
413
+ }
414
+ $data = json_decode( $in['data'], true );
415
+
416
+ //if json_decode has errors
417
+ if ( json_last_error() !== 0 ) {
418
+ echo __("Error importing the settings file. Please re-export the file",'easy-wp-smtp');
419
+ wp_die();
420
+ }
421
+
422
+ update_option( 'swpsmtp_options', $data['swpsmtp_options'] );
423
+ update_option( 'swpsmtp_pass_encrypted', $data['swpsmtp_pass_encrypted'] );
424
+ if ( $data['swpsmtp_pass_encrypted'] ) {
425
+ update_option( 'swpsmtp_enc_key', $data['swpsmtp_enc_key'] );
426
+ }
427
+ update_option( 'smtp_test_mail', $data['smtp_test_mail'] );
428
+ set_transient( 'easy_wp_smtp_settings_import_success', true, 60 * 60 );
429
+ $url = admin_url() . 'options-general.php?page=swpsmtp_settings';
430
+ wp_safe_redirect( $url );
431
+ exit;
432
+ } catch ( Exception $ex ) {
433
+ echo esc_html( $err_msg );
434
+ wp_die();
435
+ }
436
+ }
437
+ }
438
+ }
439
+
440
+ public function admin_notices() {
441
+ if ( ! $this->credentials_configured() ) {
442
+ $settings_url = admin_url() . 'options-general.php?page=swpsmtp_settings';
443
+ ?>
444
+ <div class="error">
445
+ <p>
446
+ <?php
447
+ 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 ) );
448
+ ?>
449
+ </p>
450
+ </div>
451
+ <?php
452
+ }
453
+
454
+ $settings_import_notice = get_transient( 'easy_wp_smtp_settings_import_success' );
455
+ if ( $settings_import_notice ) {
456
+ delete_transient( 'easy_wp_smtp_settings_import_success' );
457
+ ?>
458
+ <div class="updated">
459
+ <p><?php echo esc_html( __( 'Settings have been imported successfully.', 'easy-wp-smtp' ) ); ?></p>
460
+ </div>
461
+ <?php
462
+ }
463
+ }
464
+
465
+ public function get_log_file_path() {
466
+ $log_file_name = 'logs' . DIRECTORY_SEPARATOR . '.' . uniqid( '', true ) . '.txt';
467
+ $log_file_name = apply_filters( 'swpsmtp_log_file_path_override', $log_file_name );
468
+ return $log_file_name;
469
+ }
470
+
471
+ public function clear_log() {
472
+ if ( ! check_ajax_referer( 'easy-wp-smtp-clear-log', 'nonce', false ) ) {
473
+ echo esc_html( __( 'Nonce check failed.', 'easy-wp-smtp' ) );
474
+ exit;
475
+ };
476
+ if ( $this->log( self::$reset_log_str, true ) !== false ) {
477
+ echo '1';
478
+ } else {
479
+ echo esc_html( __( "Can't clear log - file is not writeable.", 'easy-wp-smtp' ) );
480
+ }
481
+ die;
482
+ }
483
+
484
+ public function log( $str, $overwrite = false ) {
485
+ try {
486
+ $log_file_name = '';
487
+ if ( isset( $this->opts['smtp_settings']['log_file_name'] ) ) {
488
+ $log_file_name = $this->opts['smtp_settings']['log_file_name'];
489
+ }
490
+ if ( empty( $log_file_name ) || $overwrite ) {
491
+ if ( ! empty( $log_file_name ) && file_exists( plugin_dir_path( __FILE__ ) . $log_file_name ) ) {
492
+ unlink( plugin_dir_path( __FILE__ ) . $log_file_name );
493
+ }
494
+ $log_file_name = $this->get_log_file_path();
495
+
496
+ $this->opts['smtp_settings']['log_file_name'] = $log_file_name;
497
+ update_option( 'swpsmtp_options', $this->opts );
498
+ file_put_contents( plugin_dir_path( __FILE__ ) . $log_file_name, self::$reset_log_str ); //phpcs:ignore
499
+ }
500
+ //Timestamp the log output
501
+ $str = '[' . date( 'm/d/Y g:i:s A' ) . '] - ' . $str;
502
+ //Write to the log file
503
+ return ( file_put_contents( plugin_dir_path( __FILE__ ) . $log_file_name, $str, ( ! $overwrite ? FILE_APPEND : 0 ) ) ); //phpcs:ignore
504
+ } catch ( \Exception $e ) {
505
+ return false;
506
+ }
507
+ }
508
+
509
+ public function plugin_action_links( $links, $file ) {
510
+ if ( plugin_basename( $this->plugin_file ) === $file ) {
511
+ $settings_link = '<a href="options-general.php?page=swpsmtp_settings">' . __( 'Settings', 'easy-wp-smtp' ) . '</a>';
512
+ array_unshift( $links, $settings_link );
513
+ }
514
+ return $links;
515
+ }
516
+
517
+ public function register_plugin_links( $links, $file ) {
518
+ if ( plugin_basename( $this->plugin_file ) === $file ) {
519
+ $links[] = '<a href="options-general.php?page=swpsmtp_settings">' . __( 'Settings', 'easy-wp-smtp' ) . '</a>';
520
+ }
521
+ return $links;
522
+ }
523
+
524
+ public function plugins_loaded_handler() {
525
+ load_plugin_textdomain( 'easy-wp-smtp', false, dirname( plugin_basename( $this->plugin_file ) ) . '/languages/' );
526
+ }
527
+
528
+ public function is_domain_blocked() {
529
+ //check if Domain Check enabled
530
+ if ( isset( $this->opts['enable_domain_check'] ) && $this->opts['enable_domain_check'] ) {
531
+ //check if allowed domains list is not blank
532
+ if ( isset( $this->opts['allowed_domains'] ) && ! empty( $this->opts['allowed_domains'] ) ) {
533
+ $this->opts['allowed_domains'] = EasyWPSMTP_Utils::base64_decode_maybe( $this->opts['allowed_domains'] );
534
+ //let's see if we have one domain or coma-separated domains
535
+ $domains_arr = explode( ',', $this->opts['allowed_domains'] );
536
+ //TODO: Change parse_url() to wp_parse_url() and bump required WP version to 4.4.0
537
+ $site_domain = parse_url( get_site_url(), PHP_URL_HOST ); //phpcs:ignore
538
+ $match_found = false;
539
+ foreach ( $domains_arr as $domain ) {
540
+ if ( strtolower( trim( $domain ) ) === strtolower( trim( $site_domain ) ) ) {
541
+ $match_found = true;
542
+ break;
543
+ }
544
+ }
545
+ if ( ! $match_found ) {
546
+ return $site_domain;
547
+ }
548
+ }
549
+ }
550
+ return false;
551
+ }
552
+
553
+ public function get_password() {
554
+ $temp_password = isset( $this->opts['smtp_settings']['password'] ) ? $this->opts['smtp_settings']['password'] : '';
555
+ if ( '' === $temp_password ) {
556
+ return '';
557
+ }
558
+
559
+ try {
560
+
561
+ if ( get_option( 'swpsmtp_pass_encrypted' ) ) {
562
+ //this is encrypted password
563
+ $cryptor = EasyWPSMTP_Utils::get_instance();
564
+ $decrypted = $cryptor->decrypt_password( $temp_password );
565
+ //check if encryption option is disabled
566
+ if ( empty( $this->opts['smtp_settings']['encrypt_pass'] ) ) {
567
+ //it is. let's save decrypted password
568
+ $this->opts['smtp_settings']['password'] = $this->encrypt_password( addslashes( $decrypted ) );
569
+ update_option( 'swpsmtp_options', $this->opts );
570
+ }
571
+ return $decrypted;
572
+ }
573
+ } catch ( Exception $e ) {
574
+ $this->log( $e->getMessage() );
575
+ return '';
576
+ }
577
+
578
+ $password = '';
579
+ $decoded_pass = base64_decode( $temp_password ); //phpcs:ignore
580
+ /* no additional checks for servers that aren't configured with mbstring enabled */
581
+ if ( ! function_exists( 'mb_detect_encoding' ) ) {
582
+ return $decoded_pass;
583
+ }
584
+ /* end of mbstring check */
585
+ if ( base64_encode( $decoded_pass ) === $temp_password ) { //phpcs:ignore
586
+ //it might be encoded
587
+ if ( false === mb_detect_encoding( $decoded_pass ) ) { //could not find character encoding.
588
+ $password = $temp_password;
589
+ } else {
590
+ $password = base64_decode( $temp_password ); //phpcs:ignore
591
+ }
592
+ } else { //not encoded
593
+ $password = $temp_password;
594
+ }
595
+ return stripslashes( $password );
596
+ }
597
+
598
+ public function encrypt_password( $pass ) {
599
+ if ( '' === $pass ) {
600
+ return '';
601
+ }
602
+
603
+ if ( empty( $this->opts['smtp_settings']['encrypt_pass'] ) || ! extension_loaded( 'openssl' ) ) {
604
+ // no openssl extension loaded - we can't encrypt the password
605
+ $password = base64_encode( $pass ); //phpcs:ignore
606
+ update_option( 'swpsmtp_pass_encrypted', false );
607
+ } else {
608
+ // let's encrypt password
609
+ $cryptor = EasyWPSMTP_Utils::get_instance();
610
+ $password = $cryptor->encrypt_password( $pass );
611
+ update_option( 'swpsmtp_pass_encrypted', true );
612
+ }
613
+ return $password;
614
+ }
615
+
616
+ public function credentials_configured() {
617
+ $credentials_configured = true;
618
+ if ( ! isset( $this->opts['from_email_field'] ) || empty( $this->opts['from_email_field'] ) ) {
619
+ $credentials_configured = false;
620
+ }
621
+ if ( ! isset( $this->opts['from_name_field'] ) || empty( $this->opts['from_name_field'] ) ) {
622
+ $credentials_configured = false;
623
+ }
624
+ return $credentials_configured;
625
+ }
626
+
627
+ public function activate() {
628
+ $swpsmtp_options_default = array(
629
+ 'from_email_field' => '',
630
+ 'from_name_field' => '',
631
+ 'force_from_name_replace' => 0,
632
+ 'sub_mode' => 0,
633
+ 'smtp_settings' => array(
634
+ 'host' => 'smtp.example.com',
635
+ 'type_encryption' => 'none',
636
+ 'port' => 25,
637
+ 'autentication' => 'yes',
638
+ 'username' => '',
639
+ 'password' => '',
640
+ ),
641
+ );
642
+
643
+ /* install the default plugin options if needed */
644
+ if ( empty( $this->opts ) ) {
645
+ $this->opts = $swpsmtp_options_default;
646
+ }
647
+ $this->opts = array_merge( $swpsmtp_options_default, $this->opts );
648
+ // reset log file
649
+ $this->log( self::$reset_log_str, true );
650
+ update_option( 'swpsmtp_options', $this->opts, 'yes' );
651
+ //add current domain to allowed domains list
652
+ if ( ! isset( $this->opts['allowed_domains'] ) ) {
653
+ //TODO: Change parse_url() to wp_parse_url() and bump required WP version to 4.4.0
654
+ $domain = parse_url( get_site_url(), PHP_URL_HOST ); //phpcs:ignore
655
+ if ( $domain ) {
656
+ $this->opts['allowed_domains'] = base64_encode( $domain ); //phpcs:ignore
657
+ update_option( 'swpsmtp_options', $this->opts );
658
+ }
659
+ } else { // let's check if existing value should be base64 encoded
660
+ if ( ! empty( $this->opts['allowed_domains'] ) ) {
661
+ if ( EasyWPSMTP_Utils::base64_decode_maybe( $this->opts['allowed_domains'] ) === $this->opts['allowed_domains'] ) {
662
+ $this->opts['allowed_domains'] = base64_encode( $this->opts['allowed_domains'] ); //phpcs:ignore
663
+ update_option( 'swpsmtp_options', $this->opts );
664
+ }
665
+ }
666
+ }
667
+ // Encrypt password if needed
668
+ if ( ! get_option( 'swpsmtp_pass_encrypted' ) ) {
669
+ if ( extension_loaded( 'openssl' ) ) {
670
+ if ( '' !== $this->opts['smtp_settings']['password'] ) {
671
+ $this->opts['smtp_settings']['password'] = $this->encrypt_password( $this->get_password() );
672
+ update_option( 'swpsmtp_options', $this->opts );
673
+ }
674
+ }
675
+ }
676
+ }
677
+
678
+ public function deactivate() {
679
+ // reset log file
680
+ $this->log( self::$reset_log_str, true );
681
+ }
682
+
683
+ public function self_destruct_handler() {
684
+ $err_msg = __( 'Please refresh the page and try again.', 'easy-wp-smtp' );
685
+ $trans = get_transient( 'easy_wp_smtp_sd_code' );
686
+ if ( empty( $trans ) ) {
687
+ echo esc_html( $err_msg );
688
+ exit;
689
+ }
690
+ $sd_code = filter_input( INPUT_POST, 'sd_code', FILTER_SANITIZE_STRING );
691
+ if ( $trans !== $sd_code ) {
692
+ echo esc_html( $err_msg );
693
+ exit;
694
+ }
695
+ $this->log( self::$reset_log_str, true );
696
+ delete_site_option( 'swpsmtp_options' );
697
+ delete_option( 'swpsmtp_options' );
698
+ delete_site_option( 'smtp_test_mail' );
699
+ delete_option( 'smtp_test_mail' );
700
+ delete_site_option( 'swpsmtp_pass_encrypted' );
701
+ delete_option( 'swpsmtp_pass_encrypted' );
702
+ delete_option( 'swpsmtp_enc_key' );
703
+ echo 1;
704
+ deactivate_plugins( __FILE__ );
705
+ exit;
706
+ }
707
+ }
708
+
709
+ EasyWPSMTP::get_instance();
710
+
711
+ function swpsmtp_uninstall() {
712
+ // Don't delete plugin options. It is better to retain the options so if someone accidentally deactivates, the configuration is not lost.
713
+ //delete_site_option('swpsmtp_options');
714
+ //delete_option('swpsmtp_options');
715
+ }
languages/easy-wp-smtp.pot CHANGED
@@ -292,7 +292,7 @@ msgid "Block all emails"
292
  msgstr ""
293
 
294
  #: class-easywpsmtp-admin.php:384
295
- msgid "When enabled, plugin attempts to block ALL emails from being sent out if domain mismtach."
296
  msgstr ""
297
 
298
  #: class-easywpsmtp-admin.php:388
292
  msgstr ""
293
 
294
  #: class-easywpsmtp-admin.php:384
295
+ msgid "When enabled, plugin attempts to block ALL emails from being sent out if domain mismatch."
296
  msgstr ""
297
 
298
  #: class-easywpsmtp-admin.php:388
readme.txt CHANGED
@@ -3,9 +3,9 @@ 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: 5.0
6
- Tested up to: 5.6
7
  Requires PHP: 5.6
8
- Stable tag: 1.4.4
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
@@ -79,6 +79,27 @@ Inspired by [WP Mail SMTP](http://wordpress.org/plugins/wp-mail-smtp/) plugin
79
 
80
  == Changelog ==
81
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
82
  = 1.4.4 =
83
  * Debug log is now reset when plugin is activated or deactivated.
84
  * Debug log file is now in the `logs` folder and is hidden (it's name starts with `.`). It is additionally protected from public access by the .htaccess file. Thanks to @mathieg2, @burkingman and @shadowdao for their reports and input.
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: 5.0
6
+ Tested up to: 6.0
7
  Requires PHP: 5.6
8
+ Stable tag: 1.5.0
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
79
 
80
  == Changelog ==
81
 
82
+ = 1.5.0 =
83
+ * Removed the usage of serialize() / unserialize() functions. Replaced it with json_encode() and json_decode() where applicable.
84
+
85
+ = 1.4.9 =
86
+ * Two new action hooks regarding settings menu tabs for addon support.
87
+ * Fixed error on SMTP with no AUTH.
88
+ * Fixed a possible PHP object injection issue while importing a file.
89
+
90
+ = 1.4.8 =
91
+ * Debug option can now handle multiple "to" email addresses in an array.
92
+
93
+ = 1.4.7 =
94
+ * A timestamp is now added to the debug log file output.
95
+
96
+ = 1.4.6 =
97
+ * Fixed a typo in the description of a settings option.
98
+
99
+ = 1.4.5 =
100
+ * Made another change to the debug logging functionality to only output the email header (instead of the full email).
101
+ * We understand that having the full email in the log file (when debug logging is enabled) to do troubleshooting is helpful but some users can forget to disable the logging feature afterwards. This change was necessary to ensure that sensitive info cannot be exposed unintentionally in the future.
102
+
103
  = 1.4.4 =
104
  * Debug log is now reset when plugin is activated or deactivated.
105
  * Debug log file is now in the `logs` folder and is hidden (it's name starts with `.`). It is additionally protected from public access by the .htaccess file. Thanks to @mathieg2, @burkingman and @shadowdao for their reports and input.