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 | 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 +3 -1
- class-easywpsmtp-utils.php +91 -90
- easy-wp-smtp.php +715 -678
- languages/easy-wp-smtp.pot +1 -1
- readme.txt +23 -2
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
|
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", "<\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", "<\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.
|
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 (
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
//
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
}
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
//
|
145 |
-
|
146 |
-
|
147 |
-
}
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
$
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
if (
|
184 |
-
$phpmailer->
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
}
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
if (
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
if (
|
257 |
-
$mail->
|
258 |
-
}
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
$
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
$
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
$
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
|
426 |
-
|
427 |
-
|
428 |
-
|
429 |
-
|
430 |
-
|
431 |
-
|
432 |
-
|
433 |
-
|
434 |
-
|
435 |
-
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
-
|
444 |
-
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
|
452 |
-
|
453 |
-
|
454 |
-
|
455 |
-
|
456 |
-
|
457 |
-
|
458 |
-
|
459 |
-
|
460 |
-
|
461 |
-
|
462 |
-
|
463 |
-
|
464 |
-
|
465 |
-
|
466 |
-
|
467 |
-
|
468 |
-
|
469 |
-
|
470 |
-
|
471 |
-
|
472 |
-
|
473 |
-
|
474 |
-
|
475 |
-
|
476 |
-
|
477 |
-
|
478 |
-
|
479 |
-
|
480 |
-
|
481 |
-
|
482 |
-
|
483 |
-
|
484 |
-
|
485 |
-
|
486 |
-
|
487 |
-
|
488 |
-
|
489 |
-
|
490 |
-
|
491 |
-
|
492 |
-
|
493 |
-
|
494 |
-
|
495 |
-
|
496 |
-
$this->opts['
|
497 |
-
|
498 |
-
|
499 |
-
|
500 |
-
|
501 |
-
|
502 |
-
|
503 |
-
|
504 |
-
|
505 |
-
|
506 |
-
|
507 |
-
|
508 |
-
|
509 |
-
|
510 |
-
|
511 |
-
|
512 |
-
|
513 |
-
|
514 |
-
|
515 |
-
|
516 |
-
|
517 |
-
|
518 |
-
if (
|
519 |
-
|
520 |
-
}
|
521 |
-
|
522 |
-
|
523 |
-
|
524 |
-
|
525 |
-
|
526 |
-
|
527 |
-
|
528 |
-
|
529 |
-
|
530 |
-
|
531 |
-
|
532 |
-
|
533 |
-
|
534 |
-
|
535 |
-
|
536 |
-
|
537 |
-
|
538 |
-
|
539 |
-
|
540 |
-
|
541 |
-
|
542 |
-
|
543 |
-
|
544 |
-
|
545 |
-
|
546 |
-
|
547 |
-
|
548 |
-
|
549 |
-
|
550 |
-
|
551 |
-
|
552 |
-
|
553 |
-
|
554 |
-
|
555 |
-
|
556 |
-
|
557 |
-
}
|
558 |
-
|
559 |
-
|
560 |
-
|
561 |
-
|
562 |
-
|
563 |
-
|
564 |
-
|
565 |
-
|
566 |
-
|
567 |
-
|
568 |
-
|
569 |
-
|
570 |
-
|
571 |
-
|
572 |
-
|
573 |
-
|
574 |
-
|
575 |
-
|
576 |
-
|
577 |
-
|
578 |
-
|
579 |
-
|
580 |
-
|
581 |
-
if ( !
|
582 |
-
$
|
583 |
-
}
|
584 |
-
|
585 |
-
|
586 |
-
|
587 |
-
|
588 |
-
|
589 |
-
|
590 |
-
|
591 |
-
|
592 |
-
|
593 |
-
|
594 |
-
|
595 |
-
|
596 |
-
|
597 |
-
|
598 |
-
|
599 |
-
|
600 |
-
|
601 |
-
|
602 |
-
|
603 |
-
|
604 |
-
|
605 |
-
|
606 |
-
|
607 |
-
|
608 |
-
|
609 |
-
|
610 |
-
|
611 |
-
|
612 |
-
|
613 |
-
|
614 |
-
|
615 |
-
|
616 |
-
|
617 |
-
|
618 |
-
|
619 |
-
|
620 |
-
|
621 |
-
|
622 |
-
|
623 |
-
|
624 |
-
|
625 |
-
|
626 |
-
|
627 |
-
|
628 |
-
|
629 |
-
|
630 |
-
|
631 |
-
|
632 |
-
|
633 |
-
|
634 |
-
|
635 |
-
|
636 |
-
|
637 |
-
|
638 |
-
|
639 |
-
|
640 |
-
|
641 |
-
|
642 |
-
|
643 |
-
|
644 |
-
|
645 |
-
|
646 |
-
|
647 |
-
$
|
648 |
-
|
649 |
-
|
650 |
-
|
651 |
-
|
652 |
-
|
653 |
-
|
654 |
-
|
655 |
-
|
656 |
-
|
657 |
-
|
658 |
-
|
659 |
-
|
660 |
-
|
661 |
-
|
662 |
-
|
663 |
-
|
664 |
-
|
665 |
-
|
666 |
-
|
667 |
-
|
668 |
-
|
669 |
-
|
670 |
-
|
671 |
-
|
672 |
-
|
673 |
-
|
674 |
-
|
675 |
-
|
676 |
-
|
677 |
-
|
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
|
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:
|
7 |
Requires PHP: 5.6
|
8 |
-
Stable tag: 1.
|
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.
|