WP Mail SMTP by WPForms - Version 0.8

Version Description

Download this release

Release Info

Developer chmac
Plugin Icon 128x128 WP Mail SMTP by WPForms
Version 0.8
Comparing to
See all releases

Code changes from version 0.7 to 0.8

Files changed (3) hide show
  1. readme.txt +18 -12
  2. screenshot-1.png +0 -0
  3. wp_mail_smtp.php +238 -121
readme.txt CHANGED
@@ -2,11 +2,11 @@
2
Contributors: chmac
3
Donate link: http://www.callum-macdonald.com/code/donate/
4
Tags: mail, smtp, wp_mail, mailer, phpmailer
5
- Requires at least: 2.0
6
- Tested up to: 2.5.1
7
- Stable tag: 0.7
8
9
- Reconfigures the wp_mail() function to use SMTP instead of mail() and creates an options page to manage host, username, password, etc.
10
11
== Description ==
12
@@ -16,6 +16,8 @@ You can set the following options:
16
* Specify the from name and email address for outgoing email.
17
* Choose to send mail by SMTP or PHP's mail() function.
18
* Specify an SMTP host (defaults to localhost).
19
* Choose to use SMTP authentication or not (defaults to not).
20
* Specify an SMTP username and password.
21
@@ -31,12 +33,20 @@ You can set the following options:
31
32
If other plugins you're using are not coded to use the wp_mail() function but instead call PHP's mail() function directly, they will bypass the settings of this plugin. Normally, you can edit the other plugins and simply replace the `mail(` calls with `wp_mail(` (just adding wp_ in front) and this will work. I've tested this on a couple of plugins and it works, but it may not work on all plugins.
33
34
- = Can I specify an SMTP port number / other setting? =
35
36
- The simple answer is no.
37
38
- However, you're welcome to edit the code of this plugin and add your options directly to the code. See the wp_mail_smtp.php file at line 88. For more information on the options you can add, see the PHP Mailer documentation here:
39
- <http://phpmailer.sourceforge.net/docs/>
40
41
= Can you add feature x, y or z to the plugin? =
42
@@ -45,10 +55,6 @@ Short answer: maybe.
45
By all means please contact me to discuss features or options you'd like to see added to the plugin. I can't guarantee to add all of them, but I will consider all sensible requests. I can be contacted here:
46
<http://www.callum-macdonald.com/contact/>
47
48
- = Will this plugin work with WordPress versions less than 2.3? =
49
-
50
- Yes. On versions of WordPress prior to 2.3, ignore the From Name field, and instead enter both the name and email in the From Email field, in the form Name&lt;email@domain.com&gt;.
51
-
52
== Screenshots ==
53
54
1. Screenshot of the Options > Email panel.
2
Contributors: chmac
3
Donate link: http://www.callum-macdonald.com/code/donate/
4
Tags: mail, smtp, wp_mail, mailer, phpmailer
5
+ Requires at least: 2.7
6
+ Tested up to: 2.7
7
+ Stable tag: 0.8
8
9
+ Reconfigures the wp_mail() function to use SMTP instead of mail() and creates an options page to manage the settings.
10
11
== Description ==
12
16
* Specify the from name and email address for outgoing email.
17
* Choose to send mail by SMTP or PHP's mail() function.
18
* Specify an SMTP host (defaults to localhost).
19
+ * Specify an SMTP port (defaults to 25).
20
+ * Choose SSL / TLS encryption (not the same as STARTTLS).
21
* Choose to use SMTP authentication or not (defaults to not).
22
* Specify an SMTP username and password.
23
33
34
If other plugins you're using are not coded to use the wp_mail() function but instead call PHP's mail() function directly, they will bypass the settings of this plugin. Normally, you can edit the other plugins and simply replace the `mail(` calls with `wp_mail(` (just adding wp_ in front) and this will work. I've tested this on a couple of plugins and it works, but it may not work on all plugins.
35
36
+ = Will this plugin work with WordPress versions less than 2.7? =
37
38
+ No. WordPress 2.7 changed the way options were updated, so the options page will only work on 2.7 or later.
39
40
+ = Can I use this plugin to send email via Gmail / Google Apps =
41
+
42
+ Yes. Use these settings:
43
+ Mailer: SMTP
44
+ SMTP Host: smtp.gmail.com
45
+ SMTP Port: 465
46
+ Encryption: SSL
47
+ Authentication: Yes
48
+ Username: your full gmail address
49
+ Password: your mail password
50
51
= Can you add feature x, y or z to the plugin? =
52
55
By all means please contact me to discuss features or options you'd like to see added to the plugin. I can't guarantee to add all of them, but I will consider all sensible requests. I can be contacted here:
56
<http://www.callum-macdonald.com/contact/>
57
58
== Screenshots ==
59
60
1. Screenshot of the Options > Email panel.
screenshot-1.png CHANGED
Binary file
wp_mail_smtp.php CHANGED
@@ -1,9 +1,9 @@
1
<?php
2
/*
3
Plugin Name: WP-Mail-SMTP
4
- Version: 0.7
5
Plugin URI: http://www.callum-macdonald.com/code/wp-mail-smtp/
6
- Description: Reconfigures the wp_mail() function to use SMTP instead of mail() and creates an options page to manage host, username, password, etc.
7
Author: Callum Macdonald
8
Author URI: http://www.callum-macdonald.com/
9
*/
@@ -15,13 +15,34 @@ Author URI: http://www.callum-macdonald.com/
15
* http://www.gnu.org/licenses/gpl.txt
16
*/
17
18
/**
19
* TODO
20
*
21
- * + Improve email checks for mail_from
22
*
23
* CHANGELOG
24
*
25
* 0.7 - Added checks to only override the default from name / email
26
* 0.6 - Added additional SMTP debugging output
27
* 0.5.2 - Fixed a pre 2.3 bug to do with mail from
@@ -43,46 +64,90 @@ $wpms_options = array (
43
'mail_from_name' => '',
44
'mailer' => 'smtp',
45
'smtp_host' => 'localhost',
46
'smtp_auth' => false,
47
'smtp_user' => '',
48
'smtp_pass' => ''
49
);
50
51
/**
52
* Activation function. This function creates the required options and defaults.
53
*/
54
- if (!function_exists('wp_mail_smtp_activate')) {
55
56
- function wp_mail_smtp_activate() {
57
-
58
- global $wpms_options;
59
-
60
- // Create the required options...
61
- foreach ($wpms_options as $name => $val) {
62
- add_option($name,$val);
63
- }
64
-
65
}
66
67
}
68
69
// To avoid any (very unlikely) clashes, check if the function alredy exists
70
- if (!function_exists('phpmailer_init_smtp')) {
71
72
- // This code is copied, from wp-includes/pluggable.php as at version 2.2.2
73
- function phpmailer_init_smtp($phpmailer) {
74
75
- // Are at least the mailer and host set and non-blank?
76
- if (!is_string(get_option('mailer')) || get_option('mailer') == '' || !is_string(get_option('smtp_host')) || get_option('smtp_host') == "" ) {
77
return;
78
}
79
80
// Set the mailer type as per config above, this overrides the already called isMail method
81
$phpmailer->Mailer = get_option('mailer');
82
83
// If we're sending via SMTP, set the host
84
if (get_option('mailer') == "smtp") {
85
$phpmailer->Host = get_option('smtp_host');
86
// If we're using smtp auth, set the username & password
87
if (get_option('smtp_auth') == "true") {
88
$phpmailer->SMTPAuth = TRUE;
@@ -94,55 +159,58 @@ if (!function_exists('phpmailer_init_smtp')) {
94
// You can add your own options here, see the phpmailer documentation for more info:
95
// http://phpmailer.sourceforge.net/docs/
96
97
- // Stop adding options here.
98
99
- } // End of phpmailer_init_smtp() function definition
100
101
- }
102
103
104
/**
105
* This function outputs the plugin options page.
106
*/
107
- if (!function_exists('wp_mail_smtp_options_page')) {
108
109
- // Define the function
110
- function wp_mail_smtp_options_page() {
111
112
- // Load the options
113
- global $wpms_options, $phpmailer;
114
115
- // Make sure the PHPMailer class has been instantiated
116
- // (copied verbatim from wp-includes/pluggable.php)
117
- // (Re)create it, if it's gone missing
118
- if ( !is_object( $phpmailer ) || !is_a( $phpmailer, 'PHPMailer' ) ) {
119
- require_once ABSPATH . WPINC . '/class-phpmailer.php';
120
- require_once ABSPATH . WPINC . '/class-smtp.php';
121
- $phpmailer = new PHPMailer();
122
- }
123
-
124
- // Send a test mail if necessary
125
- if (isset($_POST['wpms_action']) && $_POST['wpms_action'] == __('Send Test') && isset($_POST['to'])) {
126
-
127
- // Set up the mail variables
128
- $to = $_POST['to'];
129
- $subject = "WP Mail SMTP: Test mail to " . $to;
130
- $message = "This is a test email generated by the WP Mail SMTP WordPress plugin.";
131
-
132
- // Set SMTPDebug to level 2
133
- $phpmailer->SMTPDebug = 2;
134
-
135
- // Start output buffering to grab smtp debugging output
136
- ob_start();
137
-
138
- // Send the test mail
139
- $result = wp_mail($to,$subject,$message);
140
-
141
- // Grab the smtp debugging output
142
- $smtp_debug = ob_get_clean();
143
-
144
- // Output the response
145
- ?>
146
<div id="message" class="updated fade"><p><strong><?php _e('Test Message Sent'); ?></strong></p>
147
<p><?php _e('The result was:'); ?></p>
148
<pre><?php var_dump($result); ?></pre>
@@ -153,15 +221,15 @@ if (!function_exists('wp_mail_smtp_options_page')) {
153
<p><?php _e('The SMTP debugging output is shown below:'); ?></p>
154
<pre><?php echo $smtp_debug ?></pre>
155
</div>
156
- <?php
157
-
158
- }
159
160
- ?>
161
<div class="wrap">
162
<h2><?php _e('Advanced Email Options'); ?></h2>
163
<form method="post" action="options.php">
164
- <?php wp_nonce_field('update-options'); ?>
165
<p class="submit"><input type="submit" name="Submit" value="<?php _e('Update Options &raquo;'); ?>" />
166
<fieldset class="options">
167
<legend><?php _e('From'); ?></legend>
@@ -199,6 +267,21 @@ if (!function_exists('wp_mail_smtp_options_page')) {
199
<td><input name="smtp_host" type="text" id="smtp_host" value="<?php print(get_option('smtp_host')); ?>" size="40" class="code" /></td>
200
</tr>
201
<tr valign="top">
202
<th scope="row"><?php _e('Authentication:'); ?> </th>
203
<td>
204
<p><input id="smtp_auth_false" type="radio" name="smtp_auth" value="false" <?php checked('false', get_option('smtp_auth')); ?> />
@@ -221,7 +304,7 @@ if (!function_exists('wp_mail_smtp_options_page')) {
221
<p class="submit"><input type="submit" name="Submit" value="<?php _e('Update Options &raquo;'); ?>" />
222
<input type="hidden" name="action" value="update" />
223
</p>
224
- <input type="hidden" name="page_options" value="<?php print(implode(',',array_keys($wpms_options))); ?>">
225
</fieldset>
226
</form>
227
@@ -240,87 +323,121 @@ if (!function_exists('wp_mail_smtp_options_page')) {
240
</form>
241
242
</div>
243
- <?php
244
-
245
- } // End of wp_mail_smtp_options_page() function definition
246
247
- }
248
249
/**
250
* This function adds the required page (only 1 at the moment).
251
*/
252
- if (!function_exists('wp_mail_smtp_menus')) {
253
254
- function wp_mail_smtp_menus() {
255
-
256
- if (function_exists('add_submenu_page')) {
257
- add_options_page(__('Advanced Email Options'),__('Email'),'manage_options',__FILE__,'wp_mail_smtp_options_page');
258
- }
259
-
260
- } // End of wp_mail_smtp_menus() function definition
261
262
- }
263
264
/**
265
* This function sets the from email value
266
*/
267
- if (!function_exists('wp_mail_smtp_mail_from')) {
268
269
- function wp_mail_smtp_mail_from ($orig) {
270
-
271
- // If the from email is not the default, return it unchanged
272
- if ( $orig != 'wordpress@' . str_replace('www.','',strtolower($_SERVER['SERVER_NAME'])) ) {
273
- return $orig;
274
- }
275
-
276
- // If we can, use the is_email function to verify the email
277
- if ( function_exists('is_email') && get_option('db_version') >= 6124 ) {
278
- if ( is_email( get_option('mail_from') ) ) {
279
- return(get_option('mail_from'));
280
- }
281
- else {
282
- return ($orig);
283
- }
284
- }
285
- // If is_email is not available, check there's an @ symbol
286
- elseif (strpos(get_option('mail_from'),'@')) {
287
- return(get_option('mail_from'));
288
- }
289
- // If there's no is_email and no @, use the supplied variable
290
- else {
291
- return($orig);
292
- }
293
-
294
- } // End of wp_mail_smtp_mail_from() function definition
295
296
- }
297
298
/**
299
* This function sets the from name value
300
*/
301
- if (!function_exists('wp_mail_smtp_mail_from_name')) {
302
303
- function wp_mail_smtp_mail_from_name ($orig) {
304
-
305
- if ($orig == 'WordPress' && get_option('mail_from_name') != "" && is_string(get_option('mail_from_name'))) {
306
return get_option('mail_from_name');
307
- }
308
- else {
309
- return $orig;
310
- }
311
-
312
- } // End of wp_mail_smtp_mail_from_name() function definition
313
314
- }
315
316
- // Add an action on phpmailer_init
317
- add_action('phpmailer_init','phpmailer_init_smtp');
318
- // Add the create pages options
319
- add_action('admin_menu','wp_mail_smtp_menus');
320
- // Add an activation hook for this plugin
321
- register_activation_hook(__FILE__,'wp_mail_smtp_activate');
322
// Add filters to replace the mail from name and emailaddress
323
add_filter('wp_mail_from','wp_mail_smtp_mail_from');
324
add_filter('wp_mail_from_name','wp_mail_smtp_mail_from_name');
325
326
?>
1
<?php
2
/*
3
Plugin Name: WP-Mail-SMTP
4
+ Version: 0.8
5
Plugin URI: http://www.callum-macdonald.com/code/wp-mail-smtp/
6
+ Description: Reconfigures the wp_mail() function to use SMTP instead of mail() and creates an options page to manage the settings.
7
Author: Callum Macdonald
8
Author URI: http://www.callum-macdonald.com/
9
*/
15
* http://www.gnu.org/licenses/gpl.txt
16
*/
17
18
+ /**
19
+ * Setting options in wp-config.php
20
+ *
21
+ * Specifically aimed at WPMU users, you can set the options for this plugin as
22
+ * constants in wp-config.php. This disables the plugin's admin page and may
23
+ * improve performance very slightly. Copy the code below into wp-config.php.
24
+ */
25
+ /*
26
+ define('WPMS_ON', true);
27
+ define('WPMS_MAIL_FROM', 'From Email');
28
+ define('WPMS_MAIL_FROM_NAME', 'From Name');
29
+ define('WPMS_MAILER', 'smtp'); // Possible values 'smtp', 'mail', or 'sendmail'
30
+ define('WPMS_SMTP_HOST', 'localhost'); // The SMTP mail host
31
+ define('WPMS_SMTP_PORT', 25); // The SMTP server port number
32
+ define('WPMS_SSL', ''); // Possible values '', 'ssl', 'tls' - note TLS is not STARTTLS
33
+ define('WPMS_SMTP_AUTH', true); // True turns on SMTP authentication, false turns it off
34
+ define('WPMS_SMTP_USER', 'username'); // SMTP authentication username, only used if WPMS_SMTP_AUTH is true
35
+ define('WPMS_SMTP_PASS', 'password'); // SMTP authentication password, only used if WPMS_SMTP_AUTH is true
36
+ */
37
+
38
/**
39
* TODO
40
*
41
+ * + Add WPMU compatability options (hardcode values, disable admin page)
42
*
43
* CHANGELOG
44
*
45
+ * 0.8 - Added port, SSL/TLS, option whitelisting, validate_email(), and constant options.
46
* 0.7 - Added checks to only override the default from name / email
47
* 0.6 - Added additional SMTP debugging output
48
* 0.5.2 - Fixed a pre 2.3 bug to do with mail from
64
'mail_from_name' => '',
65
'mailer' => 'smtp',
66
'smtp_host' => 'localhost',
67
+ 'smtp_port' => '25',
68
+ 'smtp_ssl' => 'none',
69
'smtp_auth' => false,
70
'smtp_user' => '',
71
'smtp_pass' => ''
72
);
73
74
+
75
/**
76
* Activation function. This function creates the required options and defaults.
77
*/
78
+ if (!function_exists('wp_mail_smtp_activate')) :
79
+ function wp_mail_smtp_activate() {
80
81
+ global $wpms_options;
82
+
83
+ // Create the required options...
84
+ foreach ($wpms_options as $name => $val) {
85
+ add_option($name,$val);
86
}
87
88
}
89
+ endif;
90
+
91
+ if (!function_exists('wp_mail_smtp_whitelist_options')) :
92
+ function wp_mail_smtp_whitelist_options($whitelist_options) {
93
+
94
+ global $wpms_options;
95
+
96
+ // Add our options to the array
97
+ $whitelist_options['email'] = array_keys($wpms_options);
98
+
99
+ return $whitelist_options;
100
+
101
+ }
102
+ endif;
103
104
// To avoid any (very unlikely) clashes, check if the function alredy exists
105
+ if (!function_exists('phpmailer_init_smtp')) :
106
+ // This code is copied, from wp-includes/pluggable.php as at version 2.2.2
107
+ function phpmailer_init_smtp($phpmailer) {
108
109
+ // If constants are defined, apply those options
110
+ if (defined('WPMS_ON') && WPMS_ON) {
111
112
+ $phpmailer->Mailer = WPMS_MAILER;
113
+
114
+ if (WPMS_MAILER == 'smtp') {
115
+ $phpmailer->SMTPSecure = WPMS_SSL;
116
+ $phpmailer->Host = WPMS_SMTP_HOST;
117
+ $phpmailer->Port = WPMS_SMTP_PORT;
118
+ if (WPMS_SMTP_AUTH) {
119
+ $phpmailer->SMTPAuth = true;
120
+ $phpmailer->Username = WPMS_SMTP_USER;
121
+ $phpmailer->Password = WPMS_SMTP_PASS;
122
+ }
123
+ }
124
+
125
+ // If you're using contstants, set any custom options here
126
+
127
+ }
128
+ else {
129
+
130
+ // Check that mailer is not blank, and if mailer=smtp, host is not blank
131
+ if ( ! get_option('mailer') || ( get_option('mailer') == 'smtp' && ! get_option('smtp_host') ) ) {
132
return;
133
}
134
135
// Set the mailer type as per config above, this overrides the already called isMail method
136
$phpmailer->Mailer = get_option('mailer');
137
138
+ // Set the SMTPSecure value, if set to none, leave this blank
139
+ $phpmailer->SMTPSecure = get_option('smtp_ssl') == 'none' ? '' : get_option('smtp_ssl');
140
+
141
// If we're sending via SMTP, set the host
142
if (get_option('mailer') == "smtp") {
143
+
144
+ // Set the SMTPSecure value, if set to none, leave this blank
145
+ $phpmailer->SMTPSecure = get_option('smtp_ssl') == 'none' ? '' : get_option('smtp_ssl');
146
+
147
+ // Set the other options
148
$phpmailer->Host = get_option('smtp_host');
149
+ $phpmailer->Port = get_option('smtp_port');
150
+
151
// If we're using smtp auth, set the username & password
152
if (get_option('smtp_auth') == "true") {
153
$phpmailer->SMTPAuth = TRUE;
159
// You can add your own options here, see the phpmailer documentation for more info:
160
// http://phpmailer.sourceforge.net/docs/
161
162
163
+
164
+ // STOP adding options here.
165
+
166
+ }
167
168
+ } // End of phpmailer_init_smtp() function definition
169
+ endif;
170
+
171
172
173
/**
174
* This function outputs the plugin options page.
175
*/
176
+ if (!function_exists('wp_mail_smtp_options_page')) :
177
+ // Define the function
178
+ function wp_mail_smtp_options_page() {
179
180
+ // Load the options
181
+ global $wpms_options, $phpmailer;
182
+
183
+ // Make sure the PHPMailer class has been instantiated
184
+ // (copied verbatim from wp-includes/pluggable.php)
185
+ // (Re)create it, if it's gone missing
186
+ if ( !is_object( $phpmailer ) || !is_a( $phpmailer, 'PHPMailer' ) ) {
187
+ require_once ABSPATH . WPINC . '/class-phpmailer.php';
188
+ require_once ABSPATH . WPINC . '/class-smtp.php';
189
+ $phpmailer = new PHPMailer();
190
+ }
191
+
192
+ // Send a test mail if necessary
193
+ if (isset($_POST['wpms_action']) && $_POST['wpms_action'] == __('Send Test') && isset($_POST['to'])) {
194
195
+ // Set up the mail variables
196
+ $to = $_POST['to'];
197
+ $subject = "WP Mail SMTP: Test mail to " . $to;
198
+ $message = "This is a test email generated by the WP Mail SMTP WordPress plugin.";
199
200
+ // Set SMTPDebug to level 2
201
+ $phpmailer->SMTPDebug = 2;
202
+
203
+ // Start output buffering to grab smtp debugging output
204
+ ob_start();
205
+
206
+ // Send the test mail
207
+ $result = wp_mail($to,$subject,$message);
208
+
209
+ // Grab the smtp debugging output
210
+ $smtp_debug = ob_get_clean();
211
+
212
+ // Output the response
213
+ ?>
214
<div id="message" class="updated fade"><p><strong><?php _e('Test Message Sent'); ?></strong></p>
215
<p><?php _e('The result was:'); ?></p>
216
<pre><?php var_dump($result); ?></pre>
221
<p><?php _e('The SMTP debugging output is shown below:'); ?></p>
222
<pre><?php echo $smtp_debug ?></pre>
223
</div>
224
+ <?php
225
226
+ }
227
+
228
+ ?>
229
<div class="wrap">
230
<h2><?php _e('Advanced Email Options'); ?></h2>
231
<form method="post" action="options.php">
232
+ <?php wp_nonce_field('email-options'); ?>
233
<p class="submit"><input type="submit" name="Submit" value="<?php _e('Update Options &raquo;'); ?>" />
234
<fieldset class="options">
235
<legend><?php _e('From'); ?></legend>
267
<td><input name="smtp_host" type="text" id="smtp_host" value="<?php print(get_option('smtp_host')); ?>" size="40" class="code" /></td>
268
</tr>
269
<tr valign="top">
270
+ <th scope="row"><?php _e('SMTP Port:'); ?> </th>
271
+ <td><input name="smtp_port" type="text" id="smtp_port" value="<?php print(get_option('smtp_port')); ?>" size="6" class="code" /></td>
272
+ </tr>
273
+ <tr valign="top">
274
+ <th scope="row"><?php _e('Encryption:'); ?> </th>
275
+ <td>
276
+ <p><input id="smtp_ssl_none" type="radio" name="smtp_ssl" value="none" <?php checked('none', get_option('smtp_ssl')); ?> />
277
+ <label for="smtp_ssl_none"><?php _e('No encryption.'); ?></label></p>
278
+ <p><input id="smtp_ssl_ssl" type="radio" name="smtp_ssl" value="ssl" <?php checked('ssl', get_option('smtp_ssl')); ?> />
279
+ <label for="smtp_ssl_ssl"><?php _e('Use SSL encryption.'); ?></label></p>
280
+ <p><input id="smtp_ssl_tls" type="radio" name="smtp_ssl" value="tls" <?php checked('tls', get_option('smtp_ssl')); ?> />
281
+ <label for="smtp_ssl_tls"><?php _e('Use TLS encryption. This is not the same as STARTTLS. For most servers SSL is the recommended option.'); ?></label></p>
282
+ </td>
283
+ </tr>
284
+ <tr valign="top">
285
<th scope="row"><?php _e('Authentication:'); ?> </th>
286
<td>
287
<p><input id="smtp_auth_false" type="radio" name="smtp_auth" value="false" <?php checked('false', get_option('smtp_auth')); ?> />
304
<p class="submit"><input type="submit" name="Submit" value="<?php _e('Update Options &raquo;'); ?>" />
305
<input type="hidden" name="action" value="update" />
306
</p>
307
+ <input type="hidden" name="option_page" value="email">
308
</fieldset>
309
</form>
310
323
</form>
324
325
</div>
326
+ <?php
327
328
+ } // End of wp_mail_smtp_options_page() function definition
329
+ endif;
330
+
331
332
/**
333
* This function adds the required page (only 1 at the moment).
334
*/
335
+ if (!function_exists('wp_mail_smtp_menus')) :
336
+ function wp_mail_smtp_menus() {
337
338
+ if (function_exists('add_submenu_page')) {
339
+ add_options_page(__('Advanced Email Options'),__('Email'),'manage_options',__FILE__,'wp_mail_smtp_options_page');
340
+ }
341
342
+ } // End of wp_mail_smtp_menus() function definition
343
+ endif;
344
+
345
+
346
+ /**
347
+ * This is copied directly from WPMU wp-includes/wpmu-functions.php
348
+ */
349
+ if (!function_exists('validate_email')) :
350
+ function validate_email( $email, $check_domain = true) {
351
+ if (ereg('^[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+'.'@'.
352
+ '[-!#$%&\'*+\\/0-9=?A-Z^_`a-z{|}~]+\.'.
353
+ '[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+#x27;, $email))
354
+ {
355
+ if ($check_domain && function_exists('checkdnsrr')) {
356
+ list (, $domain) = explode('@', $email);
357
+
358
+ if (checkdnsrr($domain.'.', 'MX') || checkdnsrr($domain.'.', 'A')) {
359
+ return true;
360
+ }
361
+ return false;
362
+ }
363
+ return true;
364
+ }
365
+ return false;
366
+ } // End of validate_email() function definition
367
+ endif;
368
+
369
370
/**
371
* This function sets the from email value
372
*/
373
+ if (!function_exists('wp_mail_smtp_mail_from')) :
374
+ function wp_mail_smtp_mail_from ($orig) {
375
376
+ // This is copied from pluggable.php lines 348-354 as at revision 10150
377
+ // http://trac.wordpress.org/browser/branches/2.7/wp-includes/pluggable.php#L348
378
379
+ // Get the site domain and get rid of www.
380
+ $sitename = strtolower( $_SERVER['SERVER_NAME'] );
381
+ if ( substr( $sitename, 0, 4 ) == 'www.' ) {
382
+ $sitename = substr( $sitename, 4 );
383
+ }
384
+
385
+ $default_from = 'wordpress@' . $sitename;
386
+ // End of copied code
387
+
388
+ // If the from email is not the default, return it unchanged
389
+ if ( $orig != $default_from ) {
390
+ return $orig;
391
+ }
392
+
393
+ if (defined('WPMS_ON') && WPMS_ON)
394
+ return WPMS_MAIL_FROM;
395
+ elseif (validate_email(get_option('mail_from'), false))
396
+ return get_option('mail_from');
397
+
398
+ // If in doubt, return the original value
399
+ return $orig;
400
+
401
+ } // End of wp_mail_smtp_mail_from() function definition
402
+ endif;
403
+
404
405
/**
406
* This function sets the from name value
407
*/
408
+ if (!function_exists('wp_mail_smtp_mail_from_name')) :
409
+ function wp_mail_smtp_mail_from_name ($orig) {
410
411
+ // Only filter if the from name is the default
412
+ if ($orig == 'WordPress') {
413
+ if (defined('WPMS_ON') && WPMS_ON)
414
+ return WPMS_MAIL_FROM;
415
+ elseif ( get_option('mail_from_name') != "" && is_string(get_option('mail_from_name')) )
416
return get_option('mail_from_name');
417
+ }
418
419
+ // If in doubt, return the original value
420
+ return $orig;
421
+
422
+ } // End of wp_mail_smtp_mail_from_name() function definition
423
+ endif;
424
425
+
426
+ add_action('phpmailer_init','phpmailer_init_smtp_constants');
427
+ if (!defined('WPMS_ON') || !WPMS_ON) {
428
+ // Whitelist our options
429
+ add_filter('whitelist_options', 'wp_mail_smtp_whitelist_options');
430
+ // Add an action on phpmailer_init
431
+ add_action('phpmailer_init','phpmailer_init_smtp');
432
+ // Add the create pages options
433
+ add_action('admin_menu','wp_mail_smtp_menus');
434
+ // Add an activation hook for this plugin
435
+ register_activation_hook(__FILE__,'wp_mail_smtp_activate');
436
+ }
437
// Add filters to replace the mail from name and emailaddress
438
add_filter('wp_mail_from','wp_mail_smtp_mail_from');
439
add_filter('wp_mail_from_name','wp_mail_smtp_mail_from_name');
440
441
+ load_plugin_textdomain('wp_mail_smtp', dirname(plugin_basename(__FILE__)) . '/langs');
442
+
443
?>