WP Mail SMTP by WPForms - Version 0.3.1

Version Description

Download this release

Release Info

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

Version 0.3.1

Files changed (3) hide show
  1. readme.txt +55 -0
  2. screenshot-1.png +0 -0
  3. wp-mail-smtp/wp_mail_smtp.php +238 -0
readme.txt ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === Plugin Name ===
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.2.3
7
+ Stable tag: 0.3.1
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
+
13
+ This plugin reconfigures the wp_mail() function to use SMTP instead of mail() and creates an options page that allows you to specify various options.
14
+
15
+ 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
+
22
+ == Installation ==
23
+
24
+ 1. Download the wp_mail_smtp.php file.
25
+ 2. Upload the file to your `/wp-contents/plugins/` directory.
26
+ 3. Activate the plugin through the 'Plugins' menu in WordPress.
27
+
28
+ == Frequently Asked Questions ==
29
+
30
+ = My plugin still sends mail via the mail() function =
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
+
43
+ Short answer: maybe.
44
+
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
+ == Screenshots ==
49
+
50
+ 1. Screenshot of the Options > Email panel.
51
+
52
+ == Support Questions ==
53
+
54
+ If you have support questions not covered in this readme, you can contact me here:
55
+ <http://www.callum-macdonald.com/contact/>
screenshot-1.png ADDED
Binary file
wp-mail-smtp/wp_mail_smtp.php ADDED
@@ -0,0 +1,238 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ Plugin Name: WP-Mail-SMTP
4
+ Version: 0.3.1
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
+ */
10
+
11
+ /**
12
+ * @author Callum Macdonald
13
+ * @copyright Callum Macdonald, 2007, All Rights Reserved
14
+ * This code is released under the GPL licence version 3 or later, available here
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.3.1 - Added readme for WP-Plugins.org compatability
26
+ * 0.3 - Various bugfixes and added From options
27
+ * 0.2 - Reworked approach as suggested by westi, added options page
28
+ * 0.1 - Initial approach, copying the wp_mail function and replacing it
29
+ */
30
+
31
+ // Some simple config
32
+ $wpms_thisfile = "wp-mail-smtp/wp_mail_smtp.php"; // If you rename this file for any reason, change this variable
33
+
34
+ // Array of options and their default values
35
+ $wpms_options = array (
36
+ 'mail_from' => '',
37
+ 'mailer' => 'smtp',
38
+ 'smtp_host' => 'localhost',
39
+ 'smtp_auth' => 'false',
40
+ 'smtp_user' => '',
41
+ 'smtp_pass' => '',
42
+ );
43
+
44
+ /**
45
+ * Activation function. This function creates the required options and defaults.
46
+ */
47
+ if (!function_exists('wp_mail_smtp_activate')) {
48
+
49
+ function wp_mail_smtp_activate() {
50
+
51
+ global $wpms_options;
52
+
53
+ // Create the required options...
54
+ foreach ($wpms_options as $name => $val) {
55
+ add_option($name,$val);
56
+ }
57
+
58
+ }
59
+
60
+ }
61
+
62
+ // To avoid any (very unlikely) clashes, check if the function alredy exists
63
+ if (!function_exists('phpmailer_init_smtp')) {
64
+
65
+ // This code is copied, from wp-includes/pluggable.php as at version 2.2.2
66
+ function phpmailer_init_smtp($phpmailer) {
67
+
68
+ // Are at least the mailer and host set and non-blank?
69
+ if (!is_string(get_option('mailer')) || get_option('mailer') == '' || !is_string(get_option('smtp_host')) || get_option('smtp_host') == "" ) {
70
+ return;
71
+ }
72
+
73
+ // Set the mailer type as per config above, this overrides the already called isMail method
74
+ $phpmailer->Mailer = get_option('mailer');
75
+
76
+ // If we're sending via SMTP, set the host
77
+ if (get_option('mailer') == "smtp") {
78
+ $phpmailer->Host = get_option('smtp_host');
79
+ // If we're using smtp auth, set the username & password
80
+ if (get_option('smtp_auth') == "true") {
81
+ $phpmailer->SMTPAuth = TRUE;
82
+ $phpmailer->Username = get_option('smtp_user');
83
+ $phpmailer->Password = get_option('smtp_pass');
84
+ }
85
+ }
86
+
87
+ // You can add your own options here, see the phpmailer documentation for more info:
88
+ // http://phpmailer.sourceforge.net/docs/
89
+
90
+ // Stop adding options here.
91
+
92
+ } // End of phpmailer_init_smtp() function definition
93
+
94
+ }
95
+
96
+
97
+ /**
98
+ * This function outputs the plugin options page.
99
+ */
100
+ if (!function_exists('wp_mail_smtp_options_page')) {
101
+
102
+ // Define the function
103
+ function wp_mail_smtp_options_page() {
104
+
105
+ // Load the options
106
+ global $wpms_options;
107
+
108
+ ?>
109
+ <div class="wrap">
110
+ <h2><?php _e('Advanced Email Options') ?></h2>
111
+ <form method="post" action="options.php">
112
+ <?php wp_nonce_field('update-options') ?>
113
+ <p class="submit"><input type="submit" name="Submit" value="<?php _e('Update Options &raquo;') ?>" />
114
+ <fieldset class="options">
115
+ <legend>From</legend>
116
+ <table class="optiontable">
117
+ <tr valign="top">
118
+ <th scope="row"><?php _e('From:') ?> </th>
119
+ <td><p><input name="mail_from" type="text" id="mail_from" value="<?php print(get_option('mail_from')); ?>" size="40" class="code" /><br />
120
+ <?php _e('You can specify just an email address or a name and email address in the form &quot;Name&lt;email@example.com&gt;&quot;. If this is left blank or does not contain an @ symbol, the admin email will be used.'); ?></p></td>
121
+ </tr>
122
+ </table>
123
+
124
+ <legend>Mailer</legend>
125
+ <table class="optiontable">
126
+ <tr valign="top">
127
+ <th scope="row"><?php _e('Mailer:') ?> </th>
128
+ <td>
129
+ <p><input id="mailer_smtp" type="radio" name="mailer" value="smtp" <?php checked('smtp', get_option('mailer')); ?> />
130
+ <label for="mailer_smtp"><?php _e('Send all WordPress emails via SMTP.'); ?></label></p>
131
+ <p><input id="mailer_mail" type="radio" name="mailer" value="mail" <?php checked('mail', get_option('mailer')); ?> />
132
+ <label for="mailer_mail"><?php _e('Use the PHP mail() function to send emails.'); ?></label></p>
133
+ </td>
134
+ </tr>
135
+ </table>
136
+
137
+ <legend>SMTP Options</legend>
138
+ <p><?php _e('These options only apply if you have chosen to send mail by SMTP above.'); ?></p>
139
+ <table class="optiontable">
140
+ <tr valign="top">
141
+ <th scope="row"><?php _e('SMTP Host:') ?> </th>
142
+ <td><input name="smtp_host" type="text" id="smtp_host" value="<?php print(get_option('smtp_host')); ?>" size="40" class="code" /></td>
143
+ </tr>
144
+ <tr valign="top">
145
+ <th scope="row"><?php _e('Authentication:') ?> </th>
146
+ <td>
147
+ <p><input id="smtp_auth_false" type="radio" name="smtp_auth" value="false" <?php checked('false', get_option('smtp_auth')); ?> />
148
+ <label for="smtp_auth_false"><?php _e('No: Do not use SMTP authentication.'); ?></label></p>
149
+ <p><input id="smtp_auth_true" type="radio" name="smtp_auth" value="true" <?php checked('true', get_option('smtp_auth')); ?> />
150
+ <label for="smtp_auth_true"><?php _e('Yes: Use SMTP authentication.'); ?></label></p>
151
+ <p><?php _e('If this is set to no, the values below are ignored.'); ?></p>
152
+ </td>
153
+ </tr>
154
+ <tr valign="top">
155
+ <th scope="row"><?php _e('Username:') ?> </th>
156
+ <td><input name="smtp_user" type="text" id="smtp_user" value="<?php print(get_option('smtp_user')); ?>" size="40" class="code" /></td>
157
+ </tr>
158
+ <tr valign="top">
159
+ <th scope="row"><?php _e('Password:') ?> </th>
160
+ <td><input name="smtp_pass" type="text" id="smtp_pass" value="<?php print(get_option('smtp_pass')); ?>" size="40" class="code" /></td>
161
+ </tr>
162
+ </table>
163
+ </fieldset>
164
+
165
+ <p class="submit"><input type="submit" name="Submit" value="<?php _e('Update Options &raquo;') ?>" />
166
+ <input type="hidden" name="action" value="update" />
167
+ </p>
168
+ <input type="hidden" name="page_options" value="<?php print(implode(',',array_keys($wpms_options))); ?>">
169
+ </form>
170
+
171
+ </div>
172
+ <?php
173
+
174
+ } // End of wp_mail_smtp_options_page() function definition
175
+
176
+ }
177
+
178
+ /**
179
+ * This function adds the required page (only 1 at the moment).
180
+ */
181
+ if (!function_exists('wp_mail_smtp_menus')) {
182
+
183
+ function wp_mail_smtp_menus() {
184
+
185
+ if (function_exists('add_submenu_page')) {
186
+ add_options_page(__('Advanced Email Options'),__('Email'),'manage_options',__FILE__,'wp_mail_smtp_options_page');
187
+ }
188
+
189
+ } // End of wp_mail_smtp_menus() function definition
190
+
191
+ }
192
+
193
+ /**
194
+ * This function sets who the mail is from
195
+ */
196
+ if (!function_exists('wp_mail_smtp_mail_from')) {
197
+
198
+ function wp_mail_smtp_mail_from ($orig) {
199
+
200
+ /**
201
+ * //// CHMAC TODO
202
+ * This needs reworked, is_email only checks the email part, so before
203
+ * using it, we'll need to strip the name out. Maybe it's quicker to
204
+ * copy the checks from is_email...
205
+ */
206
+
207
+ // If we can, use the is_email function to verify the email
208
+ if ( function_exists('is_email') ) {
209
+ if ( is_email( get_option('mail_from') ) ) {
210
+ return(get_option('mail_from'));
211
+ }
212
+ else {
213
+ return (get_option('admin_email'));
214
+ }
215
+ }
216
+ // If is_email is not available, check there's an @ symbol
217
+ elseif (strpos(get_option('mail_from'),'@')) {
218
+ return(get_option('mail_from'));
219
+ }
220
+ // If there's no is_email and no @, use the admin email instead
221
+ else {
222
+ return(get_option('admin_email'));
223
+ }
224
+
225
+ } // End of wp_mail_smtp_mail_from() function definition
226
+
227
+ }
228
+
229
+ // Add an action on phpmailer_init
230
+ add_action('phpmailer_init','phpmailer_init_smtp');
231
+ // Add the create pages options
232
+ add_action('admin_menu','wp_mail_smtp_menus');
233
+ // Add an activation hook for this plugin
234
+ add_action('activate_' . $wpms_thisfile,'wp_mail_smtp_activate');
235
+ // Add a filter to replace the mail from address
236
+ add_filter('wp_mail_from','wp_mail_smtp_mail_from');
237
+
238
+ ?>