├── README.md
├── composer.json
├── options-form.php
├── readme.txt
├── screenshot-1.png
└── wds-smtp-mail.php
/README.md:
--------------------------------------------------------------------------------
1 | # WDS SMTP Mail Plugin
2 |
3 | **Contributors:** chmac, webdevstudios
4 | **Donate link:** http://webdevstudios.com
5 | **Tags:** mail, smtp, wp_mail, mailer, phpmailer
6 | **Requires at least:** 2.7
7 | **Tested up to:** 4.2.2
8 | **Stable tag:** 1.0.0
9 |
10 | Reconfigures the wp_mail() function to use SMTP instead of mail() and creates an options page to manage the settings. Based on WP Mail SMTP.
11 |
12 | ## Description
13 |
14 | 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.
15 |
16 | You can set the following options:
17 |
18 | * Specify the from name and email address for outgoing email.
19 | * Choose to send mail by SMTP or PHP's mail() function.
20 | * Specify an SMTP host (defaults to localhost).
21 | * Specify an SMTP port (defaults to 25).
22 | * Choose SSL / TLS encryption (not the same as STARTTLS).
23 | * Choose to use SMTP authentication or not (defaults to not).
24 | * Specify an SMTP username and password.
25 |
26 | ## Installation
27 |
28 | 1. Download
29 | 2. Upload to your `/wp-contents/plugins/` directory.
30 | 3. Activate the plugin through the 'Plugins' menu in WordPress.
31 |
32 | ### Using Composer
33 |
34 | Update `composer.json` with something similar to:
35 |
36 | ```json
37 | {
38 | "repositories": [
39 | {
40 | "type": "git",
41 | "url": "git@github.com:WebDevStudios/WDS-SMTP-Mail-Plugin.git"
42 | }
43 | ],
44 | "require": {
45 | "WebDevStudios/WDS-SMTP-Mail-Plugin": "dev-master"
46 | },
47 | "extra": {
48 | "installer-paths": {
49 | "plugins/{$name}": ["type:wordpress-plugin"]
50 | }
51 | }
52 | }
53 | ```
54 |
55 | ...and run `composer install` or `composer update`.
56 |
57 | #### Parent Repos
58 |
59 | If you do not intend to commit changes to the parent repository, make sure and add `/plugins/WDS-SMTP-Mail-Plugin` to your `.gitignore`.
60 |
61 | ## Frequently Asked Questions
62 |
63 | ### My plugin still sends mail via the mail() function
64 |
65 | 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.
66 |
67 | ### Will this plugin work with WordPress versions less than 2.7?
68 |
69 | No. WordPress 2.7 changed the way options were updated, so the options page will only work on 2.7 or later.
70 |
71 | ### Can I use this plugin to send email via Gmail / Google Apps
72 |
73 | Yes. Use these settings:
74 | Mailer: SMTP
75 | SMTP Host: smtp.gmail.com
76 | SMTP Port: 465
77 | Encryption: SSL
78 | Authentication: Yes
79 | Username: your full gmail address
80 | Password: your mail password
81 |
82 | ## Screenshots
83 |
84 | 
85 | Screenshot of the Options > Email Options page.
86 |
87 | ## Changelog
88 |
89 | ### 1.0.0
90 | * Forked and revamped by WebDevStudios
91 | * Composerified
92 |
93 | ### 0.9.5
94 | * Minor security fix, hat tip JD Grimes.
95 |
96 | ### 0.9.4
97 | * Improvement to the test email function, very low priority update.
98 |
99 | ### 0.9.3
100 | * Fixing reported issue with passing by reference. props Adam Conway
101 |
102 | ### 0.9.2
103 | * Removing the deprecation notice.
104 |
105 | ### 0.9.1
106 | * $phpmailer->language became protected in WP 3.2, no longer unset on debug output.
107 |
108 | ### 0.9.0
109 | * Typo in the From email description.
110 | * Removed changelog from plugin file, no need to duplicate it.
111 | * Optionally set $phpmailer->Sender from from email, helps with sendmail / mail().
112 |
113 | ### 0.8.7
114 | * Fix for a long standing bug that caused an error during plugin activation.
115 |
116 | ### 0.8.6
117 | * The Settings link really does work this time, promise. Apologies for the unnecessary updates.
118 |
119 | ### 0.8.5
120 | * Bugfix, the settings link on the Plugin page was broken by 0.8.4.
121 |
122 | ### 0.8.4
123 | * Minor bugfix, remove use of esc_html() to improve backwards compatibility.
124 | * Removed second options page menu props ovidiu.
125 |
126 | ### 0.8.3
127 | * Bugfix, return WPMS_MAIL_FROM_NAME, props nacin.
128 | * Add Settings link, props Mike Challis http://profiles.wordpress.org/MikeChallis/
129 |
130 | ### 0.8.2
131 | * Bugfix, call phpmailer_init_smtp() correctly, props Sinklar.
132 |
133 | ### 0.8.1
134 | * Internationalisation improvements.
135 |
136 | ### 0.8
137 | * Added port, SSL/TLS, option whitelisting, validate_email(), and constant options.
138 |
139 | ### 0.7
140 | * Added checks to only override the default from name / email
141 |
142 | ### 0.6
143 | * Added additional SMTP debugging output
144 |
145 | ### 0.5.2
146 | * Fixed a pre 2.3 bug to do with mail from
147 |
148 | ### 0.5.1
149 | * Added a check to display a warning on versions prior to 2.3
150 |
151 | ### 0.5.0
152 | * Upgraded to match 2.3 filters which add a second filter for from name
153 |
154 | ### 0.4.2
155 | * Fixed a bug in 0.4.1 and added more debugging output
156 |
157 | ### 0.4.1
158 | * Added $phpmailer->ErroInfo to the test mail output
159 |
160 | ### 0.4
161 | * Added the test email feature and cleaned up some other bits and pieces
162 |
163 | ### 0.3.2
164 | * Changed to use register_activation_hook for greater compatability
165 |
166 | ### 0.3.1
167 | * Added readme for WP-Plugins.org compatability
168 |
169 | ### 0.3
170 | * Various bugfixes and added From options
171 |
172 | ### 0.2
173 | * Reworked approach as suggested by westi, added options page
174 |
175 | ### 0.1
176 | * Initial approach, copying the wp_mail function and replacing it
177 |
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "webdevstudios/wds-smtp-mail-plugin",
3 | "type": "wordpress-plugin",
4 | "require": {
5 | "composer/installers": "^1.5 || ^2.0"
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/options-form.php:
--------------------------------------------------------------------------------
1 |
2 |
3 |
105 |
106 |
107 |
121 |
122 |
--------------------------------------------------------------------------------
/readme.txt:
--------------------------------------------------------------------------------
1 | === WDS SMTP Mail Plugin ===
2 | Contributors: chmac, webdevstudios
3 | Donate link: http://webdevstudios.com
4 | Tags: mail, smtp, wp_mail, mailer, phpmailer
5 | Requires at least: 2.7
6 | Tested up to: 4.2.2
7 | Stable tag: 1.0.0
8 |
9 | Reconfigures the wp_mail() function to use SMTP instead of mail() and creates an options page to manage the settings. Based on WP Mail SMTP.
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 |
17 | * Specify the from name and email address for outgoing email.
18 | * Choose to send mail by SMTP or PHP's mail() function.
19 | * Specify an SMTP host (defaults to localhost).
20 | * Specify an SMTP port (defaults to 25).
21 | * Choose SSL / TLS encryption (not the same as STARTTLS).
22 | * Choose to use SMTP authentication or not (defaults to not).
23 | * Specify an SMTP username and password.
24 |
25 | == Installation ==
26 |
27 | 1. Download
28 | 2. Upload to your `/wp-contents/plugins/` directory.
29 | 3. Activate the plugin through the 'Plugins' menu in WordPress.
30 |
31 | == Frequently Asked Questions ==
32 |
33 | = My plugin still sends mail via the mail() function =
34 |
35 | 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.
36 |
37 | = Will this plugin work with WordPress versions less than 2.7? =
38 |
39 | No. WordPress 2.7 changed the way options were updated, so the options page will only work on 2.7 or later.
40 |
41 | = Can I use this plugin to send email via Gmail / Google Apps =
42 |
43 | Yes. Use these settings:
44 | Mailer: SMTP
45 | SMTP Host: smtp.gmail.com
46 | SMTP Port: 465
47 | Encryption: SSL
48 | Authentication: Yes
49 | Username: your full gmail address
50 | Password: your mail password
51 |
52 | == Screenshots ==
53 |
54 | 1. Screenshot of the Options > Email Options page.
55 |
56 | == Changelog ==
57 |
58 | = 1.0.0 =
59 | * Forked and revamped by WebDevStudios
60 |
61 | = 0.9.5 =
62 | * Minor security fix, hat tip JD Grimes.
63 |
64 | = 0.9.4 =
65 | * Improvement to the test email function, very low priority update.
66 |
67 | = 0.9.3 =
68 | * Fixing reported issue with passing by reference. props Adam Conway
69 |
70 | = 0.9.2 =
71 | * Removing the deprecation notice.
72 |
73 | = 0.9.1 =
74 | * $phpmailer->language became protected in WP 3.2, no longer unset on debug output.
75 |
76 | = 0.9.0 =
77 | * Typo in the From email description.
78 | * Removed changelog from plugin file, no need to duplicate it.
79 | * Optionally set $phpmailer->Sender from from email, helps with sendmail / mail().
80 |
81 | = 0.8.7 =
82 | * Fix for a long standing bug that caused an error during plugin activation.
83 |
84 | = 0.8.6 =
85 | * The Settings link really does work this time, promise. Apologies for the unnecessary updates.
86 |
87 | = 0.8.5 =
88 | * Bugfix, the settings link on the Plugin page was broken by 0.8.4.
89 |
90 | = 0.8.4 =
91 | * Minor bugfix, remove use of esc_html() to improve backwards compatibility.
92 | * Removed second options page menu props ovidiu.
93 |
94 | = 0.8.3 =
95 | * Bugfix, return WPMS_MAIL_FROM_NAME, props nacin.
96 | * Add Settings link, props Mike Challis http://profiles.wordpress.org/MikeChallis/
97 |
98 | = 0.8.2 =
99 | * Bugfix, call phpmailer_init_smtp() correctly, props Sinklar.
100 |
101 | = 0.8.1 =
102 | * Internationalisation improvements.
103 |
104 | = 0.8 =
105 | * Added port, SSL/TLS, option whitelisting, validate_email(), and constant options.
106 |
107 | = 0.7 =
108 | * Added checks to only override the default from name / email
109 |
110 | = 0.6 =
111 | * Added additional SMTP debugging output
112 |
113 | = 0.5.2 =
114 | * Fixed a pre 2.3 bug to do with mail from
115 |
116 | = 0.5.1 =
117 | * Added a check to display a warning on versions prior to 2.3
118 |
119 | = 0.5.0 =
120 | * Upgraded to match 2.3 filters which add a second filter for from name
121 |
122 | = 0.4.2 =
123 | * Fixed a bug in 0.4.1 and added more debugging output
124 |
125 | = 0.4.1 =
126 | * Added $phpmailer->ErroInfo to the test mail output
127 |
128 | = 0.4 =
129 | * Added the test email feature and cleaned up some other bits and pieces
130 |
131 | = 0.3.2 =
132 | * Changed to use register_activation_hook for greater compatability
133 |
134 | = 0.3.1 =
135 | * Added readme for WP-Plugins.org compatability
136 |
137 | = 0.3 =
138 | * Various bugfixes and added From options
139 |
140 | = 0.2 =
141 | * Reworked approach as suggested by westi, added options page
142 |
143 | = 0.1 =
144 | * Initial approach, copying the wp_mail function and replacing it
145 |
146 | == Upgrade Notice ==
147 |
148 | = 0.9.5 =
149 | Minor security fix, hat tip JD Grimes.
150 |
151 | = 0.9.4 =
152 | Improvement to the test email function, very low priority update.
153 |
154 | = 0.9.3 =
155 | Fixing reported issue with passing by reference.
156 |
157 | = 0.9.2 =
158 | Removing the deprecation notice.
159 |
160 | = 0.9.1 =
161 | Test mail functionality was broken on upgrade to 3.2, now restored.
162 |
163 | = 0.9.0 =
164 | Low priority upgrade. Improves the appearance of the options page.
165 |
166 | = 0.8.7 =
167 | Very low priority update. Fixes a bug that causes a spurious error during activation.
168 |
169 | = 0.8.6 =
170 | Low priority update. The Settings link was still broken in 0.8.5.
171 |
172 | = 0.8.5 =
173 | Minor bugfix correcting the Settings link bug introduced in 0.8.4. Very low priority update.
174 |
175 | = 0.8.4 =
176 | Minor bugfix for users using constants. Another very low priority upgrade. Apologies for the version creep.
177 |
178 | = 0.8.3 =
179 | Minor bugfix for users using constants. Very low priority upgrade.
180 |
--------------------------------------------------------------------------------
/screenshot-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WebDevStudios/WDS-SMTP-Mail-Plugin/17b2918bba754a6891edb4361c3ea72cb6872783/screenshot-1.png
--------------------------------------------------------------------------------
/wds-smtp-mail.php:
--------------------------------------------------------------------------------
1 | null,
22 | 'mail_from_name' => null,
23 | 'mailer' => 'smtp',
24 | 'mail_set_return_path' => false,
25 | 'smtp_host' => 'localhost',
26 | 'smtp_port' => '25',
27 | 'smtp_ssl' => 'none',
28 | 'smtp_auth' => false,
29 | 'smtp_user' => null,
30 | 'smtp_pass' => null,
31 | 'smtp_user' => null,
32 | );
33 |
34 | public function __construct() {
35 | // Set base vars for plugin
36 | $this->basename = plugin_basename( __FILE__ );
37 | $this->directory_path = plugin_dir_path( __FILE__ );
38 | $this->directory_url = plugins_url( dirname( $this->basename ) );
39 | }
40 |
41 | // For the hooks
42 | public function do_hooks() {
43 | // Include required files
44 | add_action( 'init', array( $this, 'includes' ) );
45 |
46 | // Activation/Deactivation Hooks
47 | register_activation_hook( __FILE__, array( $this, 'activate' ) );
48 | register_deactivation_hook( __FILE__, array( $this, 'deactivate' ) );
49 |
50 | // Add an action on phpmailer_init
51 | add_action( 'phpmailer_init', array( $this, 'phpmailer_init_smtp' ) );
52 |
53 | // Whitelist our options
54 | add_filter( 'whitelist_options', array( $this, 'whitelist_options' ) );
55 |
56 | //Add the create pages options
57 | add_action( 'admin_menu', array( $this, 'menus' ) );
58 |
59 | // Adds "Settings" link to the plugin action page
60 | add_filter( 'plugin_action_links', array( $this, 'plugin_action_links' ), 10, 2 );
61 |
62 | // Add filters to replace the mail from name and email address
63 | add_filter( 'wp_mail_from', array( $this, 'mail_from' ) );
64 | add_filter( 'wp_mail_from_name', array( $this, 'mail_from_name' ) );
65 | }
66 |
67 | // Include Plugin Dependencies
68 | public function includes() { }
69 |
70 | // Activation tasks
71 | public function activate() {
72 | foreach( $this->options as $name => $value ) {
73 | add_option( $name, $value );
74 | }
75 | }
76 |
77 | // Deactivation tasks
78 | public function deactivate() { }
79 |
80 | public function whitelist_options( $whitelist_options ) {
81 | $whitelist_options['email'] = array_keys( $this->options );
82 | return $whitelist_options;
83 | }
84 |
85 | public function phpmailer_init_smtp( $phpmailer ) {
86 | // We can't use smtp without a host
87 | if( !get_option( 'mailer' ) || ( 'smtp' == get_option( 'mailer' ) && !get_option( 'smtp_host' )) ) {
88 | return;
89 | }
90 |
91 | // Set the mailer type - overriding isMail method
92 | $phpmailer->Mailer = get_option( 'mailer' );
93 |
94 | // Sender return path
95 | if( get_option( 'mail_set_return_path' ) )
96 | $phpmailer->Sender = $phpmailer->From;
97 |
98 | // Set SMTPSecure value
99 | $phpmailer->SMTPSecure = 'none' == get_option( 'smtp_ssl' ) ? '' : get_option( 'smtp_ssl' );
100 |
101 | if( 'smtp' == get_option( 'mailer' ) ) {
102 | // Set the SMTPSecure value
103 | $phpmailer->SMTPSecure = get_option( 'smtp_ssl' ) == 'none' ? '' : get_option( 'smtp_ssl' );
104 |
105 | $phpmailer->Host = get_option( 'smtp_host' );
106 | $phpmailer->Port = get_option( 'smtp_port' );
107 |
108 | // Is SMTP Auth on?
109 | if( get_option( 'smtp_auth' ) == true ) {
110 | $phpmailer->SMTPAuth = true;
111 | $phpmailer->Username = get_option( 'smtp_user' );
112 | $phpmailer->Password = get_option( 'smtp_pass' );
113 | }
114 | }
115 |
116 | $phpmailer = apply_filters( 'smtp_custom_options', $phpmailer );
117 | }
118 |
119 | public function options_page() {
120 | global $phpmailer;
121 |
122 | if( ! is_object( $phpmailer ) || ! is_a( $phpmailer, 'PHPMailer' ) ) {
123 | require_once ABSPATH . WPINC . '/class-phpmailer.php';
124 | $phpmailer = new PHPMailer(true);
125 | }
126 |
127 | if( isset( $_POST['wds_smtp_action'] )
128 | && $_POST['wds_smtp_action'] == __( 'Send Test', 'wds_smtp' )
129 | && isset( $_POST['to'] )
130 | ) {
131 | check_admin_referer('test-email');
132 |
133 | // Set up the mail vars
134 | $to = $_POST['to'];
135 | $subject = 'wds SMTP: ' . __( 'Test mail to ', 'wds_smtp' ) . $to;
136 | $message = __('This is a test email generated by the wds SMTP WordPress plugin');
137 |
138 | // Set SMTPDebug to true
139 | $phpmailer->SMTPDebug = true;
140 |
141 | // Start output buffer
142 | ob_start();
143 |
144 | $result = wp_mail( $to, $subject, $message );
145 |
146 | $smtp_debug = ob_get_clean();
147 | ?>
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 | ' . __( 'Settings', 'wds_smtp' ) . '';
222 |
223 | array_unshift($links, $settings_link);
224 | return $links;
225 | }
226 | }
227 |
228 | $GLOBALS['wds_smtp'] = new WDS_SMTP_Mail;
229 | $GLOBALS['wds_smtp']->do_hooks();
230 |
231 | endif; // end class_exists check
232 |
--------------------------------------------------------------------------------