Configure SMTP - Version 2.6

Version Description

Download this release

Release Info

Developer coffee2code
Plugin Icon wp plugin Configure SMTP
Version 2.6
Comparing to
See all releases

Version 2.6

Files changed (4) hide show
  1. c2c_minilogo.png +0 -0
  2. configure-smtp.php +418 -0
  3. readme.txt +56 -0
  4. screenshot-1.png +0 -0
c2c_minilogo.png ADDED
Binary file
configure-smtp.php ADDED
@@ -0,0 +1,418 @@
1
+ <?php
2
+ /*
3
+ Plugin Name: Configure SMTP
4
+ Version: 2.6
5
+ Plugin URI: http://coffee2code.com/wp-plugins/configure-smtp
6
+ Author: Scott Reilly
7
+ Author URI: http://coffee2code.com
8
+ Description: Configure SMTP mailing in WordPress, including support for sending e-mail via SSL/TLS (such as GMail).
9
+
10
+ This plugin is the renamed, rewritten, and updated version of the wpPHPMailer plugin.
11
+
12
+ Use this plugin to customize the SMTP mailing system used by default by WordPress to handle *outgoing* e-mails.
13
+ It offers you the ability to specify:
14
+
15
+ * SMTP host name
16
+ * SMTP port number
17
+ * If SMTPAuth (authentication) should be used.
18
+ * SMTP username
19
+ * SMTP password
20
+ * If the SMTP connection needs to occur over ssl or tls
21
+
22
+ In addition, you can instead indicate that you wish to use GMail to handle outgoing e-mail, in which case the above
23
+ settings are automatically configured to values appropriate for GMail, though you'll need to specify your GMail
24
+ e-mail (included the "@gmail.com") and password.
25
+
26
+ Regardless of whether SMTP is enabled or configured, the plugin provides you the ability to define the name and
27
+ email of the 'From:' field for all outgoing e-mails.
28
+
29
+ A simple test button is also available that allows you to send a test e-mail to yourself to check if sending
30
+ e-mail has been properly configured for your blog.
31
+
32
+ Compatible with WordPress 2.6+, 2.7+, 2.8+.
33
+
34
+ =>> Read the accompanying readme.txt file for more information. Also, visit the plugin's homepage
35
+ =>> for more information and the latest updates
36
+
37
+ Installation:
38
+
39
+ 1. Download the file http://coffee2code.com/wp-plugins/configure-smtp.zip and unzip it into your
40
+ /wp-content/plugins/ directory.
41
+ 2. Activate the plugin through the 'Plugins' admin menu in WordPress.
42
+ 3. Click the plugin's 'Settings' link next to its 'Deactivate' link (still on the Plugins page), or click on the
43
+ Settings -> SMTP link, to go to the plugin's admin settings page. Optionally customize the settings (to configure it
44
+ if the defaults aren't valid for your situation).
45
+ 4. (optional) Use the built-in test to see if your blog can properly send out e-mails.
46
+
47
+ */
48
+
49
+ /*
50
+ Copyright (c) 2004-2009 by Scott Reilly (aka coffee2code)
51
+
52
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
53
+ files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy,
54
+ modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
55
+ Software is furnished to do so, subject to the following conditions:
56
+
57
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
58
+
59
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
60
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
61
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
62
+ IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
63
+ */
64
+
65
+ if ( !class_exists('ConfigureSMTP') ) :
66
+
67
+ class ConfigureSMTP {
68
+ var $plugin_name = '';
69
+ var $admin_options_name = 'c2c_configure_smtp';
70
+ var $nonce_field = 'update-configure_smtp';
71
+ var $show_admin = true; // Change this to false if you don't want the plugin's admin page shown.
72
+ var $config = array(
73
+ // input can be 'checkbox', 'short_text', 'text', 'textarea', 'inline_textarea', 'select', 'hidden', 'password', or 'none'
74
+ // an input type of 'select' must then have an 'options' value (an array) specified
75
+ // datatype can be 'array' or 'hash'
76
+ // can also specify input_attributes
77
+ 'use_gmail' => array('input' => 'checkbox', 'default' => false,
78
+ 'label' => 'Send e-mail via GMail?',
79
+ 'help' => 'Clicking this will override many of the settings defined below. You will need to input your GMail username and password below.',
80
+ 'input_attributes' => 'onclick="return configure_gmail();"'),
81
+ 'host' => array('input' => 'text', 'default' => 'localhost',
82
+ 'label' => 'SMTP host',
83
+ 'help' => 'If "localhost" doesn\'t work for you, check with your host for the SMTP hostname.'),
84
+ 'port' => array('input' => 'short_text', 'default' => 25,
85
+ 'label' => 'SMTP port',
86
+ 'help' => "This is generally 25."),
87
+ 'smtp_secure' => array('input' => 'select', 'default' => 'None',
88
+ 'label' => 'Secure connection prefix',
89
+ 'options' => array('', 'ssl', 'tls'),
90
+ 'help' => 'Sets connection prefix for secure connections (prefix method must be supported by your PHP install and your SMTP host)'),
91
+ 'smtp_auth' => array('input' => 'checkbox', 'default' => false,
92
+ 'label' => 'Use SMTPAuth?',
93
+ 'help' => 'If checked, you must provide the SMTP username and password below'),
94
+ 'smtp_user' => array('input' => 'text', 'default' => '',
95
+ 'label' => 'SMTP username',
96
+ 'help' => ''),
97
+ 'smtp_pass' => array('input' => 'password', 'default' => '',
98
+ 'label' => 'SMTP password',
99
+ 'help' => ''),
100
+ 'wordwrap' => array('input' => 'short_text', 'default' => '',
101
+ 'label' => 'Wordwrap length',
102
+ 'help' => 'Sets word wrapping on the body of the message to a given number of characters.'),
103
+ 'from_email' => array('input' => 'text', 'default' => '',
104
+ 'label' => 'Sender e-mail',
105
+ 'help' => 'Sets the From email address for all outgoing messages. Leave blank to use the
106
+ WordPress default. This value will be used even if you don\'t enable SMTP.'),
107
+ 'from_name' => array('input' => 'text', 'default' => '',
108
+ 'label' => 'Sender name',
109
+ 'help' => 'Sets the From name for all outgoing messages. Leave blank to use the WordPress default.
110
+ This value will be used even if you don\'t enable SMTP.')
111
+ );
112
+ var $gmail_config = array(
113
+ 'host' => 'smtp.gmail.com',
114
+ 'port' => '465',
115
+ 'smtp_auth' => true,
116
+ 'smtp_secure' => 'ssl'
117
+ );
118
+ var $options = array(); // Don't use this directly
119
+
120
+ function ConfigureSMTP() {
121
+ global $pagenow;
122
+ $this->plugin_name = __('Configure SMTP');
123
+ if ( 'options-general.php' == $pagenow )
124
+ add_action('admin_footer', array(&$this, 'add_js'));
125
+ add_action('admin_menu', array(&$this, 'admin_menu'));
126
+ add_action('phpmailer_init', array(&$this, 'phpmailer_init'));
127
+ add_action('wp_mail_from', array(&$this, 'wp_mail_from'));
128
+ add_action('wp_mail_from_name', array(&$this, 'wp_mail_from_name'));
129
+ }
130
+
131
+ function install() {
132
+ $this->options = $this->get_options();
133
+ update_option($this->admin_options_name, $this->options);
134
+ }
135
+
136
+ function add_js() {
137
+ echo <<<JS
138
+ <script type="text/javascript">
139
+ function configure_gmail() {
140
+ if (jQuery('#use_gmail').attr('checked') == true) {
141
+ jQuery('#host').val('{$this->gmail_config['host']}');
142
+ jQuery('#port').val('{$this->gmail_config['port']}');
143
+ jQuery('#smtp_auth').attr('checked', {$this->gmail_config['smtp_auth']});
144
+ jQuery('#smtp_secure').val('{$this->gmail_config['smtp_secure']}');
145
+ if (!jQuery('#smtp_user').val().match(/.+@gmail.com#x2F;) ) {
146
+ jQuery('#smtp_user').val('USERNAME@gmail.com').focus().get(0).setSelectionRange(0,8);
147
+ }
148
+ alert('Be sure to specify your GMail email address (with the @gmail.com) as the SMTP username, and your GMail password as the SMTP password.');
149
+ return true;
150
+ }
151
+ }
152
+ </script>
153
+
154
+ JS;
155
+ }
156
+
157
+ function admin_menu() {
158
+ static $plugin_basename;
159
+ if ( $this->show_admin ) {
160
+ global $wp_version;
161
+ if ( current_user_can('manage_options') ) {
162
+ $plugin_basename = plugin_basename(__FILE__);
163
+ if ( version_compare( $wp_version, '2.6.999', '>' ) )
164
+ add_filter( 'plugin_action_links_' . $plugin_basename, array(&$this, 'plugin_action_links') );
165
+ add_options_page($this->plugin_name, 'SMTP', 9, $plugin_basename, array(&$this, 'options_page'));
166
+ }
167
+ }
168
+ }
169
+
170
+ function plugin_action_links($action_links) {
171
+ static $plugin_basename;
172
+ if ( !$plugin_basename ) $plugin_basename = plugin_basename(__FILE__);
173
+ $settings_link = '<a href="options-general.php?page='.$plugin_basename.'">' . __('Settings') . '</a>';
174
+ array_unshift( $action_links, $settings_link );
175
+
176
+ return $action_links;
177
+ }
178
+
179
+ function phpmailer_init($phpmailer) {
180
+ $options = $this->get_options();
181
+ $phpmailer->IsSMTP();
182
+ $phpmailer->Host = $options['host'];
183
+ $phpmailer->Port = $options['port'] ? $options['port'] : 25;
184
+ $phpmailer->SMTPAuth = $options['smtp_auth'] ? $options['smtp_auth'] : false;
185
+ if ( $phpmailer->SMTPAuth ) {
186
+ $phpmailer->Username = $options['smtp_user'];
187
+ $phpmailer->Password = $options['smtp_pass'];
188
+ }
189
+ if ( $options['smtp_secure'] != '' )
190
+ $phpmailer->SMTPSecure = $options['smtp_secure'];
191
+ if ( $options['wordwrap'] > 0 )
192
+ $phpmailer->WordWrap = $options['wordwrap'];
193
+ return $phpmailer;
194
+ }
195
+
196
+ function wp_mail_from($from) {
197
+ $options = $this->get_options();
198
+ if ( $options['from_email'] )
199
+ $from = $options['from_email'];
200
+ return $from;
201
+ }
202
+
203
+ function wp_mail_from_name($from_name) {
204
+ $options = $this->get_options();
205
+ if ( $options['from_name'] )
206
+ $from_name = $options['from_name'];
207
+ return $from_name;
208
+ }
209
+
210
+ function get_options() {
211
+ if ( !empty($this->options) ) return $this->options;
212
+ // Derive options from the config
213
+ $options = array();
214
+ foreach (array_keys($this->config) as $opt) {
215
+ $options[$opt] = $this->config[$opt]['default'];
216
+ }
217
+ $existing_options = get_option($this->admin_options_name);
218
+ if ( !empty($existing_options) ) {
219
+ foreach ($existing_options as $key => $value)
220
+ $options[$key] = $value;
221
+ }
222
+ $this->options = $options;
223
+ return $options;
224
+ }
225
+
226
+ function options_page() {
227
+ static $plugin_basename;
228
+ if ( !$plugin_basename ) $plugin_basename = plugin_basename(__FILE__);
229
+ $options = $this->get_options();
230
+ // See if user has submitted form
231
+ if ( isset($_POST['submitted']) ) {
232
+ check_admin_referer($this->nonce_field);
233
+
234
+ foreach (array_keys($options) AS $opt) {
235
+ $options[$opt] = htmlspecialchars(stripslashes($_POST[$opt]));
236
+ $input = $this->config[$opt]['input'];
237
+ if ( ($input == 'checkbox') && !$options[$opt] )
238
+ $options[$opt] = 0;
239
+ if ( $this->config[$opt]['datatype'] == 'array' ) {
240
+ if ( $input == 'text' )
241
+ $options[$opt] = explode(',', str_replace(array(', ', ' ', ','), ',', $options[$opt]));
242
+ else
243
+ $options[$opt] = array_map('trim', explode("\n", trim($options[$opt])));
244
+ }
245
+ elseif ( $this->config[$opt]['datatype'] == 'hash' ) {
246
+ if ( !empty($options[$opt]) ) {
247
+ $new_values = array();
248
+ foreach (explode("\n", $options[$opt]) AS $line) {
249
+ list($shortcut, $text) = array_map('trim', explode("=>", $line, 2));
250
+ if ( !empty($shortcut) ) $new_values[str_replace('\\', '', $shortcut)] = str_replace('\\', '', $text);
251
+ }
252
+ $options[$opt] = $new_values;
253
+ }
254
+ }
255
+ }
256
+ // If GMail is to be used, those settings take precendence
257
+ if ( $options['use_gmail'] )
258
+ $options = wp_parse_args($this->gmail_config, $options);
259
+
260
+ // Remember to put all the other options into the array or they'll get lost!
261
+ update_option($this->admin_options_name, $options);
262
+
263
+ echo "<div id='message' class='updated fade'><p><strong>" . __('Settings saved') . '</strong></p></div>';
264
+ }
265
+ elseif ( isset($_POST['submit_test_email']) ) {
266
+ check_admin_referer($this->nonce_field);
267
+ $user = wp_get_current_user();
268
+ $email = $user->user_email;
269
+ $timestamp = current_time('mysql');
270
+ $message = <<<END
271
+ Hi, this is the {$this->plugin_name} plugin e-mailing you a test message from your WordPress blog.
272
+
273
+ This message was sent with this time-stamp: $timestamp
274
+
275
+ Congratulations! Your blog is properly configured to send e-mail.
276
+ END;
277
+ wp_mail($email, "Test message from your WordPress blog", $message);
278
+ //echo "<div class='updated'>I would have sent $email this message:<br />$message</div>";
279
+ echo "<div class='updated'><p>Test e-mail sent.</p><p>The body of the e-mail includes this time-stamp: $timestamp.</p></div>";
280
+ }
281
+
282
+ $action_url = $_SERVER[PHP_SELF] . '?page=' . $plugin_basename;
283
+ $logo = plugins_url() . '/' . basename($_GET['page'], '.php') . '/c2c_minilogo.png';
284
+
285
+ echo <<<END
286
+ <div class='wrap'>
287
+ <div class="icon32" style="width:44px;"><img src='$logo' alt='A plugin by coffee2code' /><br /></div>
288
+ <h2>{$this->plugin_name} Settings</h2>
289
+ <p>After you've configured your SMTP settings, use the <a href="#test">test</a> to send a test message to yourself.</p>
290
+
291
+ <form name="configure_smtp" action="$action_url" method="post">
292
+ END;
293
+ wp_nonce_field($this->nonce_field);
294
+ echo '<table width="100%" cellspacing="2" cellpadding="5" class="optiontable editform form-table">';
295
+ foreach (array_keys($options) as $opt) {
296
+ $input = $this->config[$opt]['input'];
297
+ if ($input == 'none') continue;
298
+ $label = $this->config[$opt]['label'];
299
+ $value = $options[$opt];
300
+ if ($input == 'checkbox') {
301
+ $checked = ($value == 1) ? 'checked=checked ' : '';
302
+ $value = 1;
303
+ } else {
304
+ $checked = '';
305
+ };
306
+ if ($this->config[$opt]['datatype'] == 'array') {
307
+ if ($input == 'textarea' || $input == 'inline_textarea')
308
+ $value = implode("\n", $value);
309
+ else
310
+ $value = implode(', ', $value);
311
+ } elseif ($this->config[$opt]['datatype'] == 'hash') {
312
+ $new_value = '';
313
+ foreach ($value AS $shortcut => $replacement) {
314
+ $new_value .= "$shortcut => $replacement\n";
315
+ }
316
+ $value = $new_value;
317
+ }
318
+ echo "<tr valign='top'>";
319
+ if ($input == 'textarea') {
320
+ echo "<td colspan='2'>";
321
+ if ($label) echo "<strong>$label</strong><br />";
322
+ echo "<textarea name='$opt' id='$opt' {$this->config[$opt]['input_attributes']}>" . $value . '</textarea>';
323
+ } else {
324
+ echo "<th scope='row'>$label</th><td>";
325
+ if ($input == "inline_textarea")
326
+ echo "<textarea name='$opt' id='$opt' {$this->config[$opt]['input_attributes']}>" . $value . '</textarea>';
327
+ elseif ($input == 'select') {
328
+ echo "<select name='$opt' id='$opt'>";
329
+ foreach ($this->config[$opt]['options'] as $sopt) {
330
+ $selected = $value == $sopt ? " selected='selected'" : '';
331
+ echo "<option value='$sopt'$selected>$sopt</option>";
332
+ }
333
+ echo "</select>";
334
+ } else {
335
+ $tclass = ($input == 'short_text') ? 'small-text' : 'regular-text';
336
+ if ($input == 'short_text') $input = 'text';
337
+ echo "<input name='$opt' type='$input' id='$opt' value='$value' class='$tclass' $checked {$this->config[$opt]['input_attributes']} />";
338
+ }
339
+ }
340
+ if ($this->config[$opt]['help']) {
341
+ echo "<br /><span style='color:#777; font-size:x-small;'>";
342
+ echo $this->config[$opt]['help'];
343
+ echo "</span>";
344
+ }
345
+ echo "</td></tr>";
346
+ }
347
+ echo <<<END
348
+ </table>
349
+ <input type="hidden" name="submitted" value="1" />
350
+ <div class="submit"><input type="submit" name="Submit" class="button-primary" value="Save Changes" /></div>
351
+ </form>
352
+ </div>
353
+ END;
354
+ echo <<<END
355
+ <style type="text/css">
356
+ #c2c {
357
+ text-align:center;
358
+ color:#888;
359
+ background-color:#ffffef;
360
+ padding:5px 0 0;
361
+ margin-top:12px;
362
+ border-style:solid;
363
+ border-color:#dadada;
364
+ border-width:1px 0;
365
+ }
366
+ #c2c div {
367
+ margin:0 auto;
368
+ padding:5px 40px 0 0;
369
+ width:45%;
370
+ min-height:40px;
371
+ background:url('$logo') no-repeat top right;
372
+ }
373
+ #c2c span {
374
+ display:block;
375
+ font-size:x-small;
376
+ }
377
+ </style>
378
+ <div id='c2c' class='wrap'>
379
+ <div>
380
+ This plugin brought to you by <a href="http://coffee2code.com" title="coffee2code.com">Scott Reilly, aka coffee2code</a>.
381
+ <span><a href="http://coffee2code.com/donate" title="Please consider a donation">Did you find this plugin useful?</a></span>
382
+ </div>
383
+ </div>
384
+ END;
385
+ $user = wp_get_current_user();
386
+ $email = $user->user_email;
387
+ echo <<<END
388
+ <div class='wrap'>
389
+ <h2><a name="test"></a>Send A Test</h2>
390
+ <p>Click the button below to send a test email to yourself to see if things are working. Be sure to save
391
+ any changes you made to the form above before sending the test e-mail. Bear in mind it may take a few
392
+ minutes for the e-mail to wind its way through the internet.</p>
393
+
394
+ <p>This e-mail will be sent to your e-mail address, $email.</p>
395
+
396
+ <form name="configure_smtp" action="$action_url" method="post">
397
+ END;
398
+ wp_nonce_field($this->nonce_field);
399
+ echo <<<END
400
+ <input type="hidden" name="submit_test_email" value="1" />
401
+ <div class="submit"><input type="submit" name="Submit" value="Send test e-mail" /></div>
402
+ </form>
403
+ </div>
404
+ END;
405
+ }
406
+
407
+ } // end ConfigureSMTP
408
+
409
+ endif; // end if !class_exists()
410
+
411
+ if ( class_exists('ConfigureSMTP') ) :
412
+ $configure_smtp = new ConfigureSMTP();
413
+ // Actions and filters
414
+ if ( isset($configure_smtp) )
415
+ register_activation_hook( __FILE__, array(&$configure_smtp, 'install') );
416
+ endif;
417
+
418
+ ?>
readme.txt ADDED
@@ -0,0 +1,56 @@
1
+ === Configure SMTP ===
2
+ Contributors: coffee2code
3
+ Donate link: http://coffee2code.com/donate
4
+ Tags: email, smtp, gmail, sendmail, wp_mail, phpmailer, outgoing mail, tls, ssl, security, privacy, coffee2code
5
+ Requires at least: 2.6
6
+ Tested up to: 2.8
7
+ Stable tag: 2.6
8
+ Version: 2.6
9
+
10
+ Configure SMTP mailing in WordPress, including support for sending e-mail via SSL/TLS (such as GMail).
11
+
12
+ == Description ==
13
+
14
+ Configure SMTP mailing in WordPress, including support for sending e-mail via SSL/TLS (such as GMail).
15
+
16
+ This plugin is the renamed, rewritten, and updated version of the wpPHPMailer plugin.
17
+
18
+ Use this plugin to customize the SMTP mailing system used by default by WordPress to handle *outgoing* e-mails. It offers you the ability to specify:
19
+
20
+ * SMTP host name
21
+ * SMTP port number
22
+ * If SMTPAuth (authentication) should be used.
23
+ * SMTP username
24
+ * SMTP password
25
+ * If the SMTP connection needs to occur over ssl or tls
26
+
27
+ In addition, you can instead indicate that you wish to use GMail to handle outgoing e-mail, in which case the above settings are automatically configured to values appropriate for GMail, though you'll need to specify your GMail e-mail (including the "@gmail.com") and password.
28
+
29
+ Regardless of whether SMTP is enabled, the plugin provides you the ability to define the name and email of the 'From:' field for all outgoing e-mails.
30
+
31
+ A simple test button is also available that allows you to send a test e-mail to yourself to check if sending e-mail has been properly configured for your blog.
32
+
33
+ == Installation ==
34
+
35
+ 1. Unzip `configure-smtp.zip` inside the `/wp-content/plugins/` directory
36
+ 1. Activate the plugin through the 'Plugins' admin menu in WordPress
37
+ 1. Click the plugin's `Settings` link next to its `Deactivate` link (still on the Plugins page), or click on the `Settings` -> `SMTP` link, to go to the plugin's admin settings page. Optionally customize the settings (to configure it if the defaults aren't valid for your situation).
38
+ 1. (optional) Use the built-in test to see if your blog can properly send out e-mails.
39
+
40
+ == Frequently Asked Questions =
41
+
42
+ = I am already able to receive e-mail sent by my blog, so would I have any use or need for this plugin? =
43
+
44
+ Most likely, no. Not unless you have a preference for having your mail sent out via a different SMTP server, such as GMail.
45
+
46
+ = How do I find out my SMTP host, and/or if I need to use SMTPAuth and what my username and password for that are? =
47
+
48
+ Check out the settings for your local e-mail program. More than likely that is configured to use an outgoing SMTP server. Otherwise, contact your host or someone more intimately knowledgeable about your situation.
49
+
50
+ = I've sent out a few test e-mails using the test button after having tried different values for some of the settings; how do I know which one worked? =
51
+
52
+ If your settings worked, you should receive the test e-mail at e-mail address associated with your WordPress blog user account. That e-mail contains a time-stamp which was reported to you by the plugin when the e-mail was sent. If you are trying out various setting values, be sure to record what your settings were and what the time-stamp was when sending with those settings.
53
+
54
+ == Screenshots ==
55
+
56
+ 1. A screenshot of the plugin's admin settings page.
screenshot-1.png ADDED
Binary file