WP Mail SMTP by WPForms - Version 0.8.2

Version Description

Download this release

Release Info

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

Code changes from version 0.7 to 0.8.2

Files changed (3) hide show
  1. readme.txt +18 -12
  2. screenshot-1.png +0 -0
  3. wp_mail_smtp.php +266 -148
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.2
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,36 @@ 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 +66,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,233 +161,284 @@ 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>
149
  <?php if ($result != true) { ?>
150
- <p><?php _e('The full debugging output is shown below:'); ?></p>
151
  <pre><?php var_dump($phpmailer); ?></pre>
152
  <?php } ?>
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>
168
  <table class="optiontable">
169
  <tr valign="top">
170
- <th scope="row"><?php _e('From Email:'); ?> </th>
171
  <td><p><input name="mail_from" type="text" id="mail_from" value="<?php print(get_option('mail_from')); ?>" size="40" class="code" /><br />
172
- <?php _e('You can specify the email address that emails should be sent from. If you leave this blank, the admin email will be used.'); if(get_option('db_version') < 6124) { print('<br /><span style="color: red;">'); _e('<strong>Please Note:</strong> You appear to be using a version of WordPress prior to 2.3. Please ignore the From Name field and instead enter Name&lt;email@domain.com&gt; in this field.'); print('</span>'); } ?></p></td>
173
  </tr>
174
  <tr valign="top">
175
- <th scope="row"><?php _e('From Name:'); ?> </th>
176
  <td><p><input name="mail_from_name" type="text" id="mail_from_name" value="<?php print(get_option('mail_from_name')); ?>" size="40" class="code" /><br />
177
- <?php _e('You can specify the name that emails should be sent from. If you leave this blank, the emails will be sent from WordPress.'); ?></p></td>
178
  </tr>
179
  </table>
180
 
181
- <legend><?php _e('Mailer'); ?></legend>
182
  <table class="optiontable">
183
  <tr valign="top">
184
- <th scope="row"><?php _e('Mailer:'); ?> </th>
185
  <td>
186
  <p><input id="mailer_smtp" type="radio" name="mailer" value="smtp" <?php checked('smtp', get_option('mailer')); ?> />
187
- <label for="mailer_smtp"><?php _e('Send all WordPress emails via SMTP.'); ?></label></p>
188
  <p><input id="mailer_mail" type="radio" name="mailer" value="mail" <?php checked('mail', get_option('mailer')); ?> />
189
- <label for="mailer_mail"><?php _e('Use the PHP mail() function to send emails.'); ?></label></p>
190
  </td>
191
  </tr>
192
  </table>
193
 
194
- <legend><?php _e('SMTP Options'); ?></legend>
195
- <p><?php _e('These options only apply if you have chosen to send mail by SMTP above.'); ?></p>
196
  <table class="optiontable">
197
  <tr valign="top">
198
- <th scope="row"><?php _e('SMTP Host:'); ?> </th>
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')); ?> />
205
- <label for="smtp_auth_false"><?php _e('No: Do not use SMTP authentication.'); ?></label></p>
206
  <p><input id="smtp_auth_true" type="radio" name="smtp_auth" value="true" <?php checked('true', get_option('smtp_auth')); ?> />
207
- <label for="smtp_auth_true"><?php _e('Yes: Use SMTP authentication.'); ?></label></p>
208
- <p><?php _e('If this is set to no, the values below are ignored.'); ?></p>
209
  </td>
210
  </tr>
211
  <tr valign="top">
212
- <th scope="row"><?php _e('Username:'); ?> </th>
213
  <td><input name="smtp_user" type="text" id="smtp_user" value="<?php print(get_option('smtp_user')); ?>" size="40" class="code" /></td>
214
  </tr>
215
  <tr valign="top">
216
- <th scope="row"><?php _e('Password:'); ?> </th>
217
  <td><input name="smtp_pass" type="text" id="smtp_pass" value="<?php print(get_option('smtp_pass')); ?>" size="40" class="code" /></td>
218
  </tr>
219
  </table>
220
 
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
 
228
  <form method="POST">
229
  <fieldset class="options">
230
- <legend><?php _e('Send a Test Email'); ?></legend>
231
  <table class="optiontable">
232
  <tr valign="top">
233
- <th scope="row"><?php _e('To:'); ?> </th>
234
  <td><p><input name="to" type="text" id="to" value="" size="40" class="code" /><br />
235
- <?php _e('Type an email address here and then click Send Test to generate a test email.'); ?></p></td>
236
  </tr>
237
  </table>
238
- <p class="submit"><input type="submit" name="wpms_action" value="<?php _e('Send Test'); ?>" /></p>
239
  </fieldset>
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.2
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.2 - Bugfix, call phpmailer_init_smtp() correctly, props Sinklar.
46
+ * 0.8.1 - Internationalisation improvements.
47
+ * 0.8 - Added port, SSL/TLS, option whitelisting, validate_email(), and constant options.
48
  * 0.7 - Added checks to only override the default from name / email
49
  * 0.6 - Added additional SMTP debugging output
50
  * 0.5.2 - Fixed a pre 2.3 bug to do with mail from
66
  'mail_from_name' => '',
67
  'mailer' => 'smtp',
68
  'smtp_host' => 'localhost',
69
+ 'smtp_port' => '25',
70
+ 'smtp_ssl' => 'none',
71
  'smtp_auth' => false,
72
  'smtp_user' => '',
73
  'smtp_pass' => ''
74
  );
75
 
76
+
77
  /**
78
  * Activation function. This function creates the required options and defaults.
79
  */
80
+ if (!function_exists('wp_mail_smtp_activate')) :
81
+ function wp_mail_smtp_activate() {
82
 
83
+ global $wpms_options;
84
+
85
+ // Create the required options...
86
+ foreach ($wpms_options as $name => $val) {
87
+ add_option($name,$val);
 
 
 
 
88
  }
89
 
90
  }
91
+ endif;
92
+
93
+ if (!function_exists('wp_mail_smtp_whitelist_options')) :
94
+ function wp_mail_smtp_whitelist_options($whitelist_options) {
95
+
96
+ global $wpms_options;
97
+
98
+ // Add our options to the array
99
+ $whitelist_options['email'] = array_keys($wpms_options);
100
+
101
+ return $whitelist_options;
102
+
103
+ }
104
+ endif;
105
 
106
  // To avoid any (very unlikely) clashes, check if the function alredy exists
107
+ if (!function_exists('phpmailer_init_smtp')) :
108
+ // This code is copied, from wp-includes/pluggable.php as at version 2.2.2
109
+ function phpmailer_init_smtp($phpmailer) {
110
 
111
+ // If constants are defined, apply those options
112
+ if (defined('WPMS_ON') && WPMS_ON) {
113
 
114
+ $phpmailer->Mailer = WPMS_MAILER;
115
+
116
+ if (WPMS_MAILER == 'smtp') {
117
+ $phpmailer->SMTPSecure = WPMS_SSL;
118
+ $phpmailer->Host = WPMS_SMTP_HOST;
119
+ $phpmailer->Port = WPMS_SMTP_PORT;
120
+ if (WPMS_SMTP_AUTH) {
121
+ $phpmailer->SMTPAuth = true;
122
+ $phpmailer->Username = WPMS_SMTP_USER;
123
+ $phpmailer->Password = WPMS_SMTP_PASS;
124
+ }
125
+ }
126
+
127
+ // If you're using contstants, set any custom options here
128
+
129
+ }
130
+ else {
131
+
132
+ // Check that mailer is not blank, and if mailer=smtp, host is not blank
133
+ if ( ! get_option('mailer') || ( get_option('mailer') == 'smtp' && ! get_option('smtp_host') ) ) {
134
  return;
135
  }
136
 
137
  // Set the mailer type as per config above, this overrides the already called isMail method
138
  $phpmailer->Mailer = get_option('mailer');
139
 
140
+ // Set the SMTPSecure value, if set to none, leave this blank
141
+ $phpmailer->SMTPSecure = get_option('smtp_ssl') == 'none' ? '' : get_option('smtp_ssl');
142
+
143
  // If we're sending via SMTP, set the host
144
  if (get_option('mailer') == "smtp") {
145
+
146
+ // Set the SMTPSecure value, if set to none, leave this blank
147
+ $phpmailer->SMTPSecure = get_option('smtp_ssl') == 'none' ? '' : get_option('smtp_ssl');
148
+
149
+ // Set the other options
150
  $phpmailer->Host = get_option('smtp_host');
151
+ $phpmailer->Port = get_option('smtp_port');
152
+
153
  // If we're using smtp auth, set the username & password
154
  if (get_option('smtp_auth') == "true") {
155
  $phpmailer->SMTPAuth = TRUE;
161
  // You can add your own options here, see the phpmailer documentation for more info:
162
  // http://phpmailer.sourceforge.net/docs/
163
 
 
164
 
165
+
166
+ // STOP adding options here.
167
+
168
+ }
169
 
170
+ } // End of phpmailer_init_smtp() function definition
171
+ endif;
172
+
173
 
174
 
175
  /**
176
  * This function outputs the plugin options page.
177
  */
178
+ if (!function_exists('wp_mail_smtp_options_page')) :
179
+ // Define the function
180
+ function wp_mail_smtp_options_page() {
181
 
182
+ // Load the options
183
+ global $wpms_options, $phpmailer;
184
+
185
+ // Make sure the PHPMailer class has been instantiated
186
+ // (copied verbatim from wp-includes/pluggable.php)
187
+ // (Re)create it, if it's gone missing
188
+ if ( !is_object( $phpmailer ) || !is_a( $phpmailer, 'PHPMailer' ) ) {
189
+ require_once ABSPATH . WPINC . '/class-phpmailer.php';
190
+ require_once ABSPATH . WPINC . '/class-smtp.php';
191
+ $phpmailer = new PHPMailer();
192
+ }
193
+
194
+ // Send a test mail if necessary
195
+ if (isset($_POST['wpms_action']) && $_POST['wpms_action'] == __('Send Test', 'wp_mail_smtp') && isset($_POST['to'])) {
196
 
197
+ // Set up the mail variables
198
+ $to = $_POST['to'];
199
+ $subject = 'WP Mail SMTP: ' . __('Test mail to ', 'wp_mail_smtp') . $to;
200
+ $message = __('This is a test email generated by the WP Mail SMTP WordPress plugin.', 'wp_mail_smtp');
201
 
202
+ // Set SMTPDebug to level 2
203
+ $phpmailer->SMTPDebug = 2;
204
+
205
+ // Start output buffering to grab smtp debugging output
206
+ ob_start();
207
+
208
+ // Send the test mail
209
+ $result = wp_mail($to,$subject,$message);
210
+
211
+ // Grab the smtp debugging output
212
+ $smtp_debug = ob_get_clean();
213
+
214
+ // Output the response
215
+ ?>
216
+ <div id="message" class="updated fade"><p><strong><?php _e('Test Message Sent', 'wp_mail_smtp'); ?></strong></p>
217
+ <p><?php _e('The result was:', 'wp_mail_smtp'); ?></p>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
218
  <pre><?php var_dump($result); ?></pre>
219
  <?php if ($result != true) { ?>
220
+ <p><?php _e('The full debugging output is shown below:', 'wp_mail_smtp'); ?></p>
221
  <pre><?php var_dump($phpmailer); ?></pre>
222
  <?php } ?>
223
+ <p><?php _e('The SMTP debugging output is shown below:', 'wp_mail_smtp'); ?></p>
224
  <pre><?php echo $smtp_debug ?></pre>
225
  </div>
226
+ <?php
 
 
227
 
228
+ }
229
+
230
+ ?>
231
  <div class="wrap">
232
+ <h2><?php _e('Advanced Email Options', 'wp_mail_smtp'); ?></h2>
233
  <form method="post" action="options.php">
234
+ <?php wp_nonce_field('email-options'); ?>
235
+ <p class="submit"><input type="submit" name="Submit" value="<?php _e('Update Options &raquo;', 'wp_mail_smtp'); ?>" />
236
  <fieldset class="options">
237
+ <legend><?php _e('From', 'wp_mail_smtp'); ?></legend>
238
  <table class="optiontable">
239
  <tr valign="top">
240
+ <th scope="row"><?php _e('From Email:', 'wp_mail_smtp'); ?> </th>
241
  <td><p><input name="mail_from" type="text" id="mail_from" value="<?php print(get_option('mail_from')); ?>" size="40" class="code" /><br />
242
+ <?php _e('You can specify the email address that emails should be sent from. If you leave this blank, the admin email will be used.', 'wp_mail_smtp'); if(get_option('db_version') < 6124) { print('<br /><span style="color: red;">'); _e('<strong>Please Note:</strong> You appear to be using a version of WordPress prior to 2.3. Please ignore the From Name field and instead enter Name&lt;email@domain.com&gt; in this field.', 'wp_mail_smtp'); print('</span>'); } ?></p></td>
243
  </tr>
244
  <tr valign="top">
245
+ <th scope="row"><?php _e('From Name:', 'wp_mail_smtp'); ?> </th>
246
  <td><p><input name="mail_from_name" type="text" id="mail_from_name" value="<?php print(get_option('mail_from_name')); ?>" size="40" class="code" /><br />
247
+ <?php _e('You can specify the name that emails should be sent from. If you leave this blank, the emails will be sent from WordPress.', 'wp_mail_smtp'); ?></p></td>
248
  </tr>
249
  </table>
250
 
251
+ <legend><?php _e('Mailer', 'wp_mail_smtp'); ?></legend>
252
  <table class="optiontable">
253
  <tr valign="top">
254
+ <th scope="row"><?php _e('Mailer:', 'wp_mail_smtp'); ?> </th>
255
  <td>
256
  <p><input id="mailer_smtp" type="radio" name="mailer" value="smtp" <?php checked('smtp', get_option('mailer')); ?> />
257
+ <label for="mailer_smtp"><?php _e('Send all WordPress emails via SMTP.', 'wp_mail_smtp'); ?></label></p>
258
  <p><input id="mailer_mail" type="radio" name="mailer" value="mail" <?php checked('mail', get_option('mailer')); ?> />
259
+ <label for="mailer_mail"><?php _e('Use the PHP mail() function to send emails.', 'wp_mail_smtp'); ?></label></p>
260
  </td>
261
  </tr>
262
  </table>
263
 
264
+ <legend><?php _e('SMTP Options', 'wp_mail_smtp'); ?></legend>
265
+ <p><?php _e('These options only apply if you have chosen to send mail by SMTP above.', 'wp_mail_smtp'); ?></p>
266
  <table class="optiontable">
267
  <tr valign="top">
268
+ <th scope="row"><?php _e('SMTP Host:', 'wp_mail_smtp'); ?> </th>
269
  <td><input name="smtp_host" type="text" id="smtp_host" value="<?php print(get_option('smtp_host')); ?>" size="40" class="code" /></td>
270
  </tr>
271
  <tr valign="top">
272
+ <th scope="row"><?php _e('SMTP Port:', 'wp_mail_smtp'); ?> </th>
273
+ <td><input name="smtp_port" type="text" id="smtp_port" value="<?php print(get_option('smtp_port')); ?>" size="6" class="code" /></td>
274
+ </tr>
275
+ <tr valign="top">
276
+ <th scope="row"><?php _e('Encryption:', 'wp_mail_smtp'); ?> </th>
277
+ <td>
278
+ <p><input id="smtp_ssl_none" type="radio" name="smtp_ssl" value="none" <?php checked('none', get_option('smtp_ssl')); ?> />
279
+ <label for="smtp_ssl_none"><?php _e('No encryption.', 'wp_mail_smtp'); ?></label></p>
280
+ <p><input id="smtp_ssl_ssl" type="radio" name="smtp_ssl" value="ssl" <?php checked('ssl', get_option('smtp_ssl')); ?> />
281
+ <label for="smtp_ssl_ssl"><?php _e('Use SSL encryption.', 'wp_mail_smtp'); ?></label></p>
282
+ <p><input id="smtp_ssl_tls" type="radio" name="smtp_ssl" value="tls" <?php checked('tls', get_option('smtp_ssl')); ?> />
283
+ <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.', 'wp_mail_smtp'); ?></label></p>
284
+ </td>
285
+ </tr>
286
+ <tr valign="top">
287
+ <th scope="row"><?php _e('Authentication:', 'wp_mail_smtp'); ?> </th>
288
  <td>
289
  <p><input id="smtp_auth_false" type="radio" name="smtp_auth" value="false" <?php checked('false', get_option('smtp_auth')); ?> />
290
+ <label for="smtp_auth_false"><?php _e('No: Do not use SMTP authentication.', 'wp_mail_smtp'); ?></label></p>
291
  <p><input id="smtp_auth_true" type="radio" name="smtp_auth" value="true" <?php checked('true', get_option('smtp_auth')); ?> />
292
+ <label for="smtp_auth_true"><?php _e('Yes: Use SMTP authentication.', 'wp_mail_smtp'); ?></label></p>
293
+ <p><?php _e('If this is set to no, the values below are ignored.', 'wp_mail_smtp'); ?></p>
294
  </td>
295
  </tr>
296
  <tr valign="top">
297
+ <th scope="row"><?php _e('Username:', 'wp_mail_smtp'); ?> </th>
298
  <td><input name="smtp_user" type="text" id="smtp_user" value="<?php print(get_option('smtp_user')); ?>" size="40" class="code" /></td>
299
  </tr>
300
  <tr valign="top">
301
+ <th scope="row"><?php _e('Password:', 'wp_mail_smtp'); ?> </th>
302
  <td><input name="smtp_pass" type="text" id="smtp_pass" value="<?php print(get_option('smtp_pass')); ?>" size="40" class="code" /></td>
303
  </tr>
304
  </table>
305
 
306
+ <p class="submit"><input type="submit" name="Submit" value="<?php _e('Update Options &raquo;', 'wp_mail_smtp'); ?>" />
307
  <input type="hidden" name="action" value="update" />
308
  </p>
309
+ <input type="hidden" name="option_page" value="email">
310
  </fieldset>
311
  </form>
312
 
313
  <form method="POST">
314
  <fieldset class="options">
315
+ <legend><?php _e('Send a Test Email', 'wp_mail_smtp'); ?></legend>
316
  <table class="optiontable">
317
  <tr valign="top">
318
+ <th scope="row"><?php _e('To:', 'wp_mail_smtp'); ?> </th>
319
  <td><p><input name="to" type="text" id="to" value="" size="40" class="code" /><br />
320
+ <?php _e('Type an email address here and then click Send Test to generate a test email.', 'wp_mail_smtp'); ?></p></td>
321
  </tr>
322
  </table>
323
+ <p class="submit"><input type="submit" name="wpms_action" value="<?php _e('Send Test', 'wp_mail_smtp'); ?>" /></p>
324
  </fieldset>
325
  </form>
326
 
327
  </div>
328
+ <?php
 
 
329
 
330
+ } // End of wp_mail_smtp_options_page() function definition
331
+ endif;
332
+
333
 
334
  /**
335
  * This function adds the required page (only 1 at the moment).
336
  */
337
+ if (!function_exists('wp_mail_smtp_menus')) :
338
+ function wp_mail_smtp_menus() {
339
 
340
+ if (function_exists('add_submenu_page')) {
341
+ add_options_page(__('Advanced Email Options', 'wp_mail_smtp'),__('Email', 'wp_mail_smtp'),'manage_options',__FILE__,'wp_mail_smtp_options_page');
342
+ }
 
 
 
 
343
 
344
+ } // End of wp_mail_smtp_menus() function definition
345
+ endif;
346
+
347
+
348
+ /**
349
+ * This is copied directly from WPMU wp-includes/wpmu-functions.php
350
+ */
351
+ if (!function_exists('validate_email')) :
352
+ function validate_email( $email, $check_domain = true) {
353
+ if (ereg('^[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+'.'@'.
354
+ '[-!#$%&\'*+\\/0-9=?A-Z^_`a-z{|}~]+\.'.
355
+ '[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+$', $email))
356
+ {
357
+ if ($check_domain && function_exists('checkdnsrr')) {
358
+ list (, $domain) = explode('@', $email);
359
+
360
+ if (checkdnsrr($domain.'.', 'MX') || checkdnsrr($domain.'.', 'A')) {
361
+ return true;
362
+ }
363
+ return false;
364
+ }
365
+ return true;
366
+ }
367
+ return false;
368
+ } // End of validate_email() function definition
369
+ endif;
370
+
371
 
372
  /**
373
  * This function sets the from email value
374
  */
375
+ if (!function_exists('wp_mail_smtp_mail_from')) :
376
+ function wp_mail_smtp_mail_from ($orig) {
377
 
378
+ // This is copied from pluggable.php lines 348-354 as at revision 10150
379
+ // http://trac.wordpress.org/browser/branches/2.7/wp-includes/pluggable.php#L348
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
380
 
381
+ // Get the site domain and get rid of www.
382
+ $sitename = strtolower( $_SERVER['SERVER_NAME'] );
383
+ if ( substr( $sitename, 0, 4 ) == 'www.' ) {
384
+ $sitename = substr( $sitename, 4 );
385
+ }
386
+
387
+ $default_from = 'wordpress@' . $sitename;
388
+ // End of copied code
389
+
390
+ // If the from email is not the default, return it unchanged
391
+ if ( $orig != $default_from ) {
392
+ return $orig;
393
+ }
394
+
395
+ if (defined('WPMS_ON') && WPMS_ON)
396
+ return WPMS_MAIL_FROM;
397
+ elseif (validate_email(get_option('mail_from'), false))
398
+ return get_option('mail_from');
399
+
400
+ // If in doubt, return the original value
401
+ return $orig;
402
+
403
+ } // End of wp_mail_smtp_mail_from() function definition
404
+ endif;
405
+
406
 
407
  /**
408
  * This function sets the from name value
409
  */
410
+ if (!function_exists('wp_mail_smtp_mail_from_name')) :
411
+ function wp_mail_smtp_mail_from_name ($orig) {
412
 
413
+ // Only filter if the from name is the default
414
+ if ($orig == 'WordPress') {
415
+ if (defined('WPMS_ON') && WPMS_ON)
416
+ return WPMS_MAIL_FROM;
417
+ elseif ( get_option('mail_from_name') != "" && is_string(get_option('mail_from_name')) )
418
  return get_option('mail_from_name');
419
+ }
 
 
 
 
 
420
 
421
+ // If in doubt, return the original value
422
+ return $orig;
423
+
424
+ } // End of wp_mail_smtp_mail_from_name() function definition
425
+ endif;
426
+
427
 
428
  // Add an action on phpmailer_init
429
  add_action('phpmailer_init','phpmailer_init_smtp');
430
+ if (!defined('WPMS_ON') || !WPMS_ON) {
431
+ // Whitelist our options
432
+ add_filter('whitelist_options', 'wp_mail_smtp_whitelist_options');
433
+ // Add the create pages options
434
+ add_action('admin_menu','wp_mail_smtp_menus');
435
+ // Add an activation hook for this plugin
436
+ register_activation_hook(__FILE__,'wp_mail_smtp_activate');
437
+ }
438
  // Add filters to replace the mail from name and emailaddress
439
  add_filter('wp_mail_from','wp_mail_smtp_mail_from');
440
  add_filter('wp_mail_from_name','wp_mail_smtp_mail_from_name');
441
 
442
+ load_plugin_textdomain('wp_mail_smtp', false, dirname(plugin_basename(__FILE__)) . '/langs');
443
+
444
  ?>