SMTP Mailer - Version 1.0.1

Version Description

none

Download this release

Release Info

Developer naa986
Plugin Icon 128x128 SMTP Mailer
Version 1.0.1
Comparing to
See all releases

Version 1.0.1

Files changed (4) hide show
  1. languages/smtp-mailer.mo +0 -0
  2. languages/smtp-mailer.pot +176 -0
  3. main.php +765 -0
  4. readme.txt +72 -0
languages/smtp-mailer.mo ADDED
Binary file
languages/smtp-mailer.pot ADDED
@@ -0,0 +1,176 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ msgid ""
2
+ msgstr ""
3
+ "Project-Id-Version: SMTP Mailer\n"
4
+ "POT-Creation-Date: 2015-12-20 14:09+1000\n"
5
+ "PO-Revision-Date: 2015-12-20 14:09+1000\n"
6
+ "Last-Translator: \n"
7
+ "Language-Team: \n"
8
+ "MIME-Version: 1.0\n"
9
+ "Content-Type: text/plain; charset=UTF-8\n"
10
+ "Content-Transfer-Encoding: 8bit\n"
11
+ "X-Generator: Poedit 1.5.5\n"
12
+ "X-Poedit-KeywordsList: _e;__\n"
13
+ "X-Poedit-Basepath: .\n"
14
+ "X-Poedit-SearchPath-0: .\n"
15
+
16
+ #: main.php:66
17
+ msgid "Settings"
18
+ msgstr ""
19
+
20
+ #: main.php:72
21
+ msgid "SMTP Mailer"
22
+ msgstr ""
23
+
24
+ #: main.php:77
25
+ msgid "General"
26
+ msgstr ""
27
+
28
+ #: main.php:78
29
+ msgid "Test Email"
30
+ msgstr ""
31
+
32
+ #: main.php:79
33
+ msgid "Server Info"
34
+ msgstr ""
35
+
36
+ #: main.php:82
37
+ #, php-format
38
+ msgid ""
39
+ "Please visit the <a target=\"_blank\" href=\"%s\">SMTP Mailer</a> "
40
+ "documentation page for usage instructions."
41
+ msgstr ""
42
+
43
+ #: main.php:141
44
+ msgid "To"
45
+ msgstr ""
46
+
47
+ #: main.php:143
48
+ msgid "Email address of the recipient"
49
+ msgstr ""
50
+
51
+ #: main.php:147
52
+ msgid "Subject"
53
+ msgstr ""
54
+
55
+ #: main.php:149
56
+ msgid "Subject of the email"
57
+ msgstr ""
58
+
59
+ #: main.php:153
60
+ msgid "Message"
61
+ msgstr ""
62
+
63
+ #: main.php:155
64
+ msgid "Email body"
65
+ msgstr ""
66
+
67
+ #: main.php:162
68
+ msgid "Send Email"
69
+ msgstr ""
70
+
71
+ #: main.php:256
72
+ msgid "Settings Saved!"
73
+ msgstr ""
74
+
75
+ #: main.php:286
76
+ msgid "SMTP Host"
77
+ msgstr ""
78
+
79
+ #: main.php:288
80
+ msgid ""
81
+ "The SMTP server which will be used to send email. For example: smtp.gmail.com"
82
+ msgstr ""
83
+
84
+ #: main.php:292
85
+ msgid "SMTP Authentication"
86
+ msgstr ""
87
+
88
+ #: main.php:295
89
+ msgid "True"
90
+ msgstr ""
91
+
92
+ #: main.php:296
93
+ msgid "False"
94
+ msgstr ""
95
+
96
+ #: main.php:298
97
+ msgid ""
98
+ "Whether to use SMTP Authentication when sending an email (recommended: True)."
99
+ msgstr ""
100
+
101
+ #: main.php:303
102
+ msgid "SMTP Username"
103
+ msgstr ""
104
+
105
+ #: main.php:305
106
+ msgid "Your SMTP Username."
107
+ msgstr ""
108
+
109
+ #: main.php:309
110
+ msgid "SMTP Password"
111
+ msgstr ""
112
+
113
+ #: main.php:311
114
+ msgid "Your SMTP Password."
115
+ msgstr ""
116
+
117
+ #: main.php:315
118
+ msgid "Type of Encryption"
119
+ msgstr ""
120
+
121
+ #: main.php:318
122
+ msgid "TLS"
123
+ msgstr ""
124
+
125
+ #: main.php:319
126
+ msgid "SSL"
127
+ msgstr ""
128
+
129
+ #: main.php:320
130
+ msgid "No Encryption"
131
+ msgstr ""
132
+
133
+ #: main.php:322
134
+ msgid ""
135
+ "The encryption which will be used when sending an email (recommended: TLS)."
136
+ msgstr ""
137
+
138
+ #: main.php:327
139
+ msgid "SMTP Port"
140
+ msgstr ""
141
+
142
+ #: main.php:329
143
+ msgid ""
144
+ "The port which will be used when sending an email (587/465/25). If you "
145
+ "choose TLS it should be set to 587. For SSL use port 465 instead."
146
+ msgstr ""
147
+
148
+ #: main.php:333
149
+ msgid "From Email Address"
150
+ msgstr ""
151
+
152
+ #: main.php:335
153
+ msgid ""
154
+ "The email address which will be used as the From Address if it is not "
155
+ "supplied to the mail function."
156
+ msgstr ""
157
+
158
+ #: main.php:339
159
+ msgid "From Name"
160
+ msgstr ""
161
+
162
+ #: main.php:341
163
+ msgid ""
164
+ "The name which will be used as the From Name if it is not supplied to the "
165
+ "mail function."
166
+ msgstr ""
167
+
168
+ #: main.php:348
169
+ msgid "Save Changes"
170
+ msgstr ""
171
+
172
+ #: main.php:368
173
+ msgid ""
174
+ "SMTP Mailer plugin cannot send email until you enter your credentials in the "
175
+ "settings."
176
+ msgstr ""
main.php ADDED
@@ -0,0 +1,765 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ Plugin Name: SMTP Mailer
4
+ Version: 1.0.1
5
+ Plugin URI: http://wphowto.net/smtp-mailer-plugin-for-wordpress-1482
6
+ Author: naa986
7
+ Author URI: http://wphowto.net/
8
+ Description: Configure a SMTP server to send email from your WordPress site
9
+ Text Domain: smtp-mailer
10
+ Domain Path: /languages
11
+ */
12
+
13
+ if (!defined('ABSPATH')){
14
+ exit;
15
+ }
16
+
17
+ class SMTP_MAILER {
18
+
19
+ var $plugin_version = '1.0.1';
20
+ var $phpmailer_version = '5.2.10';
21
+ var $plugin_url;
22
+ var $plugin_path;
23
+
24
+ function __construct() {
25
+ define('SMTP_MAILER_VERSION', $this->plugin_version);
26
+ define('SMTP_MAILER_SITE_URL', site_url());
27
+ define('SMTP_MAILER_HOME_URL', home_url());
28
+ define('SMTP_MAILER_URL', $this->plugin_url());
29
+ define('SMTP_MAILER_PATH', $this->plugin_path());
30
+ $this->plugin_includes();
31
+ $this->loader_operations();
32
+ }
33
+
34
+ function plugin_includes() {
35
+
36
+ }
37
+
38
+ function loader_operations() {
39
+ if (is_admin()) {
40
+ add_filter('plugin_action_links', array($this, 'add_plugin_action_links'), 10, 2);
41
+ }
42
+ add_action('plugins_loaded', array($this, 'plugins_loaded_handler'));
43
+ add_action('admin_menu', array($this, 'options_menu'));
44
+ add_action('admin_notices', 'smtp_mailer_admin_notice');
45
+ }
46
+
47
+ function plugins_loaded_handler()
48
+ {
49
+ load_plugin_textdomain('smtp-mailer', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/');
50
+ }
51
+
52
+ function plugin_url() {
53
+ if ($this->plugin_url)
54
+ return $this->plugin_url;
55
+ return $this->plugin_url = plugins_url(basename(plugin_dir_path(__FILE__)), basename(__FILE__));
56
+ }
57
+
58
+ function plugin_path() {
59
+ if ($this->plugin_path)
60
+ return $this->plugin_path;
61
+ return $this->plugin_path = untrailingslashit(plugin_dir_path(__FILE__));
62
+ }
63
+
64
+ function add_plugin_action_links($links, $file) {
65
+ if ($file == plugin_basename(dirname(__FILE__) . '/main.php')) {
66
+ $links[] = '<a href="options-general.php?page=smtp-mailer-settings">'.__('Settings', 'smtp-mailer').'</a>';
67
+ }
68
+ return $links;
69
+ }
70
+
71
+ function options_menu() {
72
+ add_options_page(__('SMTP Mailer', 'smtp-mailer'), __('SMTP Mailer', 'smtp-mailer'), 'manage_options', 'smtp-mailer-settings', array($this, 'options_page'));
73
+ }
74
+
75
+ function options_page() {
76
+ $plugin_tabs = array(
77
+ 'smtp-mailer-settings' => __('General', 'smtp-mailer'),
78
+ 'smtp-mailer-settings&action=test-email' => __('Test Email', 'smtp-mailer'),
79
+ 'smtp-mailer-settings&action=server-info' => __('Server Info', 'smtp-mailer'),
80
+ );
81
+ $url = "http://wphowto.net/smtp-mailer-plugin-for-wordpress-1482";
82
+ $link_text = sprintf(wp_kses(__('Please visit the <a target="_blank" href="%s">SMTP Mailer</a> documentation page for usage instructions.', 'smtp-mailer'), array('a' => array('href' => array(), 'target' => array()))), esc_url($url));
83
+ echo '<div class="wrap"><h2>SMTP Mailer v' . SMTP_MAILER_VERSION . '</h2>';
84
+ echo '<div class="update-nag">'.$link_text.'</div>';
85
+ if (isset($_GET['page'])) {
86
+ $current = $_GET['page'];
87
+ if (isset($_GET['action'])) {
88
+ $current .= "&action=" . $_GET['action'];
89
+ }
90
+ }
91
+ $content = '';
92
+ $content .= '<h2 class="nav-tab-wrapper">';
93
+ foreach ($plugin_tabs as $location => $tabname) {
94
+ if ($current == $location) {
95
+ $class = ' nav-tab-active';
96
+ } else {
97
+ $class = '';
98
+ }
99
+ $content .= '<a class="nav-tab' . $class . '" href="?page=' . $location . '">' . $tabname . '</a>';
100
+ }
101
+ $content .= '</h2>';
102
+ echo $content;
103
+
104
+ if(isset($_GET['action']) && $_GET['action'] == 'test-email'){
105
+ $this->test_email_settings();
106
+ }
107
+ else if(isset($_GET['action']) && $_GET['action'] == 'server-info'){
108
+ $this->server_info_settings();
109
+ }
110
+ else{
111
+ $this->general_settings();
112
+ }
113
+ echo '</div>';
114
+ }
115
+
116
+ function test_email_settings(){
117
+ if(isset($_POST['smtp_mailer_send_test_email'])){
118
+ $to = '';
119
+ if(isset($_POST['smtp_mailer_to_email']) && !empty($_POST['smtp_mailer_to_email'])){
120
+ $to = sanitize_text_field($_POST['smtp_mailer_to_email']);
121
+ }
122
+ $subject = '';
123
+ if(isset($_POST['smtp_mailer_email_subject']) && !empty($_POST['smtp_mailer_email_subject'])){
124
+ $subject = sanitize_text_field($_POST['smtp_mailer_email_subject']);
125
+ }
126
+ $message = '';
127
+ if(isset($_POST['smtp_mailer_email_body']) && !empty($_POST['smtp_mailer_email_body'])){
128
+ $message = sanitize_text_field($_POST['smtp_mailer_email_body']);
129
+ }
130
+ wp_mail($to, $subject, $message);
131
+ }
132
+ ?>
133
+ <form method="post" action="<?php echo $_SERVER["REQUEST_URI"]; ?>">
134
+ <?php wp_nonce_field('smtp_mailer_test_email'); ?>
135
+
136
+ <table class="form-table">
137
+
138
+ <tbody>
139
+
140
+ <tr valign="top">
141
+ <th scope="row"><label for="smtp_mailer_to_email"><?php _e('To', 'smtp-mailer');?></label></th>
142
+ <td><input name="smtp_mailer_to_email" type="text" id="smtp_mailer_to_email" value="" class="regular-text">
143
+ <p class="description"><?php _e('Email address of the recipient', 'smtp-mailer');?></p></td>
144
+ </tr>
145
+
146
+ <tr valign="top">
147
+ <th scope="row"><label for="smtp_mailer_email_subject"><?php _e('Subject', 'smtp-mailer');?></label></th>
148
+ <td><input name="smtp_mailer_email_subject" type="text" id="smtp_mailer_email_subject" value="" class="regular-text">
149
+ <p class="description"><?php _e('Subject of the email', 'smtp-mailer');?></p></td>
150
+ </tr>
151
+
152
+ <tr valign="top">
153
+ <th scope="row"><label for="smtp_mailer_email_body"><?php _e('Message', 'smtp-mailer');?></label></th>
154
+ <td><textarea name="smtp_mailer_email_body" id="smtp_mailer_email_body" rows="6"></textarea>
155
+ <p class="description"><?php _e('Email body', 'smtp-mailer');?></p></td>
156
+ </tr>
157
+
158
+ </tbody>
159
+
160
+ </table>
161
+
162
+ <p class="submit"><input type="submit" name="smtp_mailer_send_test_email" id="smtp_mailer_send_test_email" class="button button-primary" value="<?php _e('Send Email', 'smtp-mailer');?>"></p>
163
+ </form>
164
+
165
+ <?php
166
+ }
167
+
168
+ function server_info_settings()
169
+ {
170
+ $server_info = '';
171
+ $server_info .= sprintf('OS: %s%s', php_uname(), PHP_EOL);
172
+ $server_info .= sprintf('PHP version: %s%s', PHP_VERSION, PHP_EOL);
173
+ $server_info .= sprintf('WordPress version: %s%s', get_bloginfo('version'), PHP_EOL);
174
+ $server_info .= sprintf('WordPress multisite: %s%s', (is_multisite() ? 'Yes' : 'No'), PHP_EOL);
175
+ $openssl_status = 'Available';
176
+ $openssl_text = '';
177
+ if(!extension_loaded('openssl') && !defined('OPENSSL_ALGO_SHA1')){
178
+ $openssl_status = 'Not available';
179
+ $openssl_text = ' (openssl extension is required in order to use any kind of encryption like TLS or SSL)';
180
+ }
181
+ $server_info .= sprintf('openssl: %s%s%s', $openssl_status, $openssl_text, PHP_EOL);
182
+ $server_info .= sprintf('allow_url_fopen: %s%s', (ini_get('allow_url_fopen') ? 'Enabled' : 'Disabled'), PHP_EOL);
183
+ $stream_socket_client_status = 'Not Available';
184
+ $fsockopen_status = 'Not Available';
185
+ $socket_enabled = false;
186
+ if(function_exists('stream_socket_client')){
187
+ $stream_socket_client_status = 'Available';
188
+ $socket_enabled = true;
189
+ }
190
+ if(function_exists('fsockopen')){
191
+ $fsockopen_status = 'Available';
192
+ $socket_enabled = true;
193
+ }
194
+ $socket_text = '';
195
+ if(!$socket_enabled){
196
+ $socket_text = ' (In order to make a SMTP connection your server needs to have either stream_socket_client or fsockopen)';
197
+ }
198
+ $server_info .= sprintf('stream_socket_client: %s%s', $stream_socket_client_status, PHP_EOL);
199
+ $server_info .= sprintf('fsockopen: %s%s%s', $fsockopen_status, $socket_text, PHP_EOL);
200
+ ?>
201
+ <textarea rows="10" cols="50" class="large-text code"><?php echo $server_info;?></textarea>
202
+ <?php
203
+ }
204
+
205
+ function general_settings() {
206
+
207
+ if (isset($_POST['smtp_mailer_update_settings'])) {
208
+ $nonce = $_REQUEST['_wpnonce'];
209
+ if (!wp_verify_nonce($nonce, 'smtp_mailer_general_settings')) {
210
+ wp_die('Error! Nonce Security Check Failed! please save the settings again.');
211
+ }
212
+ $smtp_host = '';
213
+ if(isset($_POST['smtp_host']) && !empty($_POST['smtp_host'])){
214
+ $smtp_host = sanitize_text_field($_POST['smtp_host']);
215
+ }
216
+ $smtp_auth = '';
217
+ if(isset($_POST['smtp_auth']) && !empty($_POST['smtp_auth'])){
218
+ $smtp_auth = sanitize_text_field($_POST['smtp_auth']);
219
+ }
220
+ $smtp_username = '';
221
+ if(isset($_POST['smtp_username']) && !empty($_POST['smtp_username'])){
222
+ $smtp_username = sanitize_text_field($_POST['smtp_username']);
223
+ }
224
+ $smtp_password = '';
225
+ if(isset($_POST['smtp_password']) && !empty($_POST['smtp_password'])){
226
+ $smtp_password = sanitize_text_field($_POST['smtp_password']);
227
+ $smtp_password = base64_encode($smtp_password);
228
+ }
229
+ $type_of_encryption = '';
230
+ if(isset($_POST['type_of_encryption']) && !empty($_POST['type_of_encryption'])){
231
+ $type_of_encryption = sanitize_text_field($_POST['type_of_encryption']);
232
+ }
233
+ $smtp_port = '';
234
+ if(isset($_POST['smtp_port']) && !empty($_POST['smtp_port'])){
235
+ $smtp_port = sanitize_text_field($_POST['smtp_port']);
236
+ }
237
+ $from_email = '';
238
+ if(isset($_POST['from_email']) && !empty($_POST['from_email'])){
239
+ $from_email = sanitize_email($_POST['from_email']);
240
+ }
241
+ $from_name = '';
242
+ if(isset($_POST['from_name']) && !empty($_POST['from_name'])){
243
+ $from_name = sanitize_text_field(stripslashes($_POST['from_name']));
244
+ }
245
+ $options = array();
246
+ $options['smtp_host'] = $smtp_host;
247
+ $options['smtp_auth'] = $smtp_auth;
248
+ $options['smtp_username'] = $smtp_username;
249
+ $options['smtp_password'] = $smtp_password;
250
+ $options['type_of_encryption'] = $type_of_encryption;
251
+ $options['smtp_port'] = $smtp_port;
252
+ $options['from_email'] = $from_email;
253
+ $options['from_name'] = $from_name;
254
+ smtp_mailer_update_option($options);
255
+ echo '<div id="message" class="updated fade"><p><strong>';
256
+ echo __('Settings Saved!', 'smtp-mailer');
257
+ echo '</strong></p></div>';
258
+ }
259
+
260
+ $options = smtp_mailer_get_option();
261
+ if(!is_array($options)){
262
+ $options = array();
263
+ $options['smtp_host'] = '';
264
+ $options['smtp_auth'] = '';
265
+ $options['smtp_username'] = '';
266
+ $options['smtp_password'] = '';
267
+ $options['type_of_encryption'] = '';
268
+ $options['smtp_port'] = '';
269
+ $options['from_email'] = '';
270
+ $options['from_name'] = '';
271
+ }
272
+ $smtp_password = '';
273
+ if(isset($options['smtp_password']) && !empty($options['smtp_password'])){
274
+ $smtp_password = base64_decode($options['smtp_password']);
275
+ }
276
+ ?>
277
+
278
+ <form method="post" action="<?php echo $_SERVER["REQUEST_URI"]; ?>">
279
+ <?php wp_nonce_field('smtp_mailer_general_settings'); ?>
280
+
281
+ <table class="form-table">
282
+
283
+ <tbody>
284
+
285
+ <tr valign="top">
286
+ <th scope="row"><label for="smtp_host"><?php _e('SMTP Host', 'smtp-mailer');?></label></th>
287
+ <td><input name="smtp_host" type="text" id="smtp_host" value="<?php echo $options['smtp_host']; ?>" class="regular-text code">
288
+ <p class="description"><?php _e('The SMTP server which will be used to send email. For example: smtp.gmail.com', 'smtp-mailer');?></p></td>
289
+ </tr>
290
+
291
+ <tr>
292
+ <th scope="row"><label for="smtp_auth"><?php _e('SMTP Authentication', 'smtp-mailer');?></label></th>
293
+ <td>
294
+ <select name="smtp_auth" id="smtp_auth">
295
+ <option value="true" <?php echo selected( $options['smtp_auth'], 'true', false );?>><?php _e('True', 'smtp-mailer');?></option>
296
+ <option value="false" <?php echo selected( $options['smtp_auth'], 'false', false );?>><?php _e('False', 'smtp-mailer');?></option>
297
+ </select>
298
+ <p class="description"><?php _e('Whether to use SMTP Authentication when sending an email (recommended: True).', 'smtp-mailer');?></p>
299
+ </td>
300
+ </tr>
301
+
302
+ <tr valign="top">
303
+ <th scope="row"><label for="smtp_username"><?php _e('SMTP Username', 'smtp-mailer');?></label></th>
304
+ <td><input name="smtp_username" type="text" id="smtp_username" value="<?php echo $options['smtp_username']; ?>" class="regular-text code">
305
+ <p class="description"><?php _e('Your SMTP Username.', 'smtp-mailer');?></p></td>
306
+ </tr>
307
+
308
+ <tr valign="top">
309
+ <th scope="row"><label for="smtp_password"><?php _e('SMTP Password', 'smtp-mailer');?></label></th>
310
+ <td><input name="smtp_password" type="password" id="smtp_password" value="<?php echo $smtp_password; ?>" class="regular-text code">
311
+ <p class="description"><?php _e('Your SMTP Password.', 'smtp-mailer');?></p></td>
312
+ </tr>
313
+
314
+ <tr>
315
+ <th scope="row"><label for="type_of_encryption"><?php _e('Type of Encryption', 'smtp-mailer');?></label></th>
316
+ <td>
317
+ <select name="type_of_encryption" id="type_of_encryption">
318
+ <option value="tls" <?php echo selected( $options['type_of_encryption'], 'tls', false );?>><?php _e('TLS', 'smtp-mailer');?></option>
319
+ <option value="ssl" <?php echo selected( $options['type_of_encryption'], 'ssl', false );?>><?php _e('SSL', 'smtp-mailer');?></option>
320
+ <option value="none" <?php echo selected( $options['type_of_encryption'], 'none', false );?>><?php _e('No Encryption', 'smtp-mailer');?></option>
321
+ </select>
322
+ <p class="description"><?php _e('The encryption which will be used when sending an email (recommended: TLS).', 'smtp-mailer');?></p>
323
+ </td>
324
+ </tr>
325
+
326
+ <tr valign="top">
327
+ <th scope="row"><label for="smtp_port"><?php _e('SMTP Port', 'smtp-mailer');?></label></th>
328
+ <td><input name="smtp_port" type="text" id="smtp_port" value="<?php echo $options['smtp_port']; ?>" class="regular-text code">
329
+ <p class="description"><?php _e('The port which will be used when sending an email (587/465/25). If you choose TLS it should be set to 587. For SSL use port 465 instead.', 'smtp-mailer');?></p></td>
330
+ </tr>
331
+
332
+ <tr valign="top">
333
+ <th scope="row"><label for="from_email"><?php _e('From Email Address', 'smtp-mailer');?></label></th>
334
+ <td><input name="from_email" type="text" id="from_email" value="<?php echo $options['from_email']; ?>" class="regular-text code">
335
+ <p class="description"><?php _e('The email address which will be used as the From Address if it is not supplied to the mail function.', 'smtp-mailer');?></p></td>
336
+ </tr>
337
+
338
+ <tr valign="top">
339
+ <th scope="row"><label for="from_name"><?php _e('From Name', 'smtp-mailer');?></label></th>
340
+ <td><input name="from_name" type="text" id="from_name" value="<?php echo $options['from_name']; ?>" class="regular-text code">
341
+ <p class="description"><?php _e('The name which will be used as the From Name if it is not supplied to the mail function.', 'smtp-mailer');?></p></td>
342
+ </tr>
343
+
344
+ </tbody>
345
+
346
+ </table>
347
+
348
+ <p class="submit"><input type="submit" name="smtp_mailer_update_settings" id="smtp_mailer_update_settings" class="button button-primary" value="<?php _e('Save Changes', 'smtp-mailer')?>"></p>
349
+ </form>
350
+
351
+ <?php
352
+ }
353
+ }
354
+
355
+ function smtp_mailer_get_option(){
356
+ $options = get_option('smtp_mailer_options');
357
+ return $options;
358
+ }
359
+
360
+ function smtp_mailer_update_option($options){
361
+ update_option('smtp_mailer_options', $options);
362
+ }
363
+
364
+ function smtp_mailer_admin_notice() {
365
+ if(!is_smtp_mailer_configured()){
366
+ ?>
367
+ <div class="error">
368
+ <p><?php _e('SMTP Mailer plugin cannot send email until you enter your credentials in the settings.', 'smtp-mailer'); ?></p>
369
+ </div>
370
+ <?php
371
+ }
372
+ }
373
+
374
+ function is_smtp_mailer_configured() {
375
+ $options = smtp_mailer_get_option();
376
+ $smtp_configured = true;
377
+ if(!isset($options['smtp_host']) || empty($options['smtp_host'])){
378
+ $smtp_configured = false;
379
+ }
380
+ if(!isset($options['smtp_auth']) || empty($options['smtp_auth'])){
381
+ $smtp_configured = false;
382
+ }
383
+ if(isset($options['smtp_auth']) && $options['smtp_auth'] == "true"){
384
+ if(!isset($options['smtp_username']) || empty($options['smtp_username'])){
385
+ $smtp_configured = false;
386
+ }
387
+ if(!isset($options['smtp_password']) || empty($options['smtp_password'])){
388
+ $smtp_configured = false;
389
+ }
390
+ }
391
+ if(!isset($options['type_of_encryption']) || empty($options['type_of_encryption'])){
392
+ $smtp_configured = false;
393
+ }
394
+ if(!isset($options['smtp_port']) || empty($options['smtp_port'])){
395
+ $smtp_configured = false;
396
+ }
397
+ if(!isset($options['from_email']) || empty($options['from_email'])){
398
+ $smtp_configured = false;
399
+ }
400
+ if(!isset($options['from_name']) || empty($options['from_name'])){
401
+ $smtp_configured = false;
402
+ }
403
+ return $smtp_configured;
404
+ }
405
+
406
+ $GLOBALS['smtp_mailer'] = new SMTP_MAILER();
407
+
408
+ if(!function_exists('wp_mail') && is_smtp_mailer_configured()){
409
+
410
+ function wp_mail( $to, $subject, $message, $headers = '', $attachments = array() ) {
411
+ // Compact the input, apply the filters, and extract them back out
412
+
413
+ /**
414
+ * Filter the wp_mail() arguments.
415
+ *
416
+ * @since 2.2.0
417
+ *
418
+ * @param array $args A compacted array of wp_mail() arguments, including the "to" email,
419
+ * subject, message, headers, and attachments values.
420
+ */
421
+ $atts = apply_filters( 'wp_mail', compact( 'to', 'subject', 'message', 'headers', 'attachments' ) );
422
+
423
+ if ( isset( $atts['to'] ) ) {
424
+ $to = $atts['to'];
425
+ }
426
+
427
+ if ( isset( $atts['subject'] ) ) {
428
+ $subject = $atts['subject'];
429
+ }
430
+
431
+ if ( isset( $atts['message'] ) ) {
432
+ $message = $atts['message'];
433
+ }
434
+
435
+ if ( isset( $atts['headers'] ) ) {
436
+ $headers = $atts['headers'];
437
+ }
438
+
439
+ if ( isset( $atts['attachments'] ) ) {
440
+ $attachments = $atts['attachments'];
441
+ }
442
+
443
+ if ( ! is_array( $attachments ) ) {
444
+ $attachments = explode( "\n", str_replace( "\r\n", "\n", $attachments ) );
445
+ }
446
+
447
+ $options = smtp_mailer_get_option();
448
+
449
+ global $phpmailer;
450
+
451
+ // (Re)create it, if it's gone missing
452
+ if ( ! ( $phpmailer instanceof PHPMailer ) ) {
453
+ require_once ABSPATH . WPINC . '/class-phpmailer.php';
454
+ require_once ABSPATH . WPINC . '/class-smtp.php';
455
+ $phpmailer = new PHPMailer( true );
456
+ }
457
+
458
+ // Headers
459
+ if ( empty( $headers ) ) {
460
+ $headers = array();
461
+ } else {
462
+ if ( !is_array( $headers ) ) {
463
+ // Explode the headers out, so this function can take both
464
+ // string headers and an array of headers.
465
+ $tempheaders = explode( "\n", str_replace( "\r\n", "\n", $headers ) );
466
+ } else {
467
+ $tempheaders = $headers;
468
+ }
469
+ $headers = array();
470
+ $cc = array();
471
+ $bcc = array();
472
+
473
+ // If it's actually got contents
474
+ if ( !empty( $tempheaders ) ) {
475
+ // Iterate through the raw headers
476
+ foreach ( (array) $tempheaders as $header ) {
477
+ if ( strpos($header, ':') === false ) {
478
+ if ( false !== stripos( $header, 'boundary=' ) ) {
479
+ $parts = preg_split('/boundary=/i', trim( $header ) );
480
+ $boundary = trim( str_replace( array( "'", '"' ), '', $parts[1] ) );
481
+ }
482
+ continue;
483
+ }
484
+ // Explode them out
485
+ list( $name, $content ) = explode( ':', trim( $header ), 2 );
486
+
487
+ // Cleanup crew
488
+ $name = trim( $name );
489
+ $content = trim( $content );
490
+
491
+ switch ( strtolower( $name ) ) {
492
+ // Mainly for legacy -- process a From: header if it's there
493
+ case 'from':
494
+ $bracket_pos = strpos( $content, '<' );
495
+ if ( $bracket_pos !== false ) {
496
+ // Text before the bracketed email is the "From" name.
497
+ if ( $bracket_pos > 0 ) {
498
+ $from_name = substr( $content, 0, $bracket_pos - 1 );
499
+ $from_name = str_replace( '"', '', $from_name );
500
+ $from_name = trim( $from_name );
501
+ }
502
+
503
+ $from_email = substr( $content, $bracket_pos + 1 );
504
+ $from_email = str_replace( '>', '', $from_email );
505
+ $from_email = trim( $from_email );
506
+
507
+ // Avoid setting an empty $from_email.
508
+ } elseif ( '' !== trim( $content ) ) {
509
+ $from_email = trim( $content );
510
+ }
511
+ break;
512
+ case 'content-type':
513
+ if ( strpos( $content, ';' ) !== false ) {
514
+ list( $type, $charset_content ) = explode( ';', $content );
515
+ $content_type = trim( $type );
516
+ if ( false !== stripos( $charset_content, 'charset=' ) ) {
517
+ $charset = trim( str_replace( array( 'charset=', '"' ), '', $charset_content ) );
518
+ } elseif ( false !== stripos( $charset_content, 'boundary=' ) ) {
519
+ $boundary = trim( str_replace( array( 'BOUNDARY=', 'boundary=', '"' ), '', $charset_content ) );
520
+ $charset = '';
521
+ }
522
+
523
+ // Avoid setting an empty $content_type.
524
+ } elseif ( '' !== trim( $content ) ) {
525
+ $content_type = trim( $content );
526
+ }
527
+ break;
528
+ case 'cc':
529
+ $cc = array_merge( (array) $cc, explode( ',', $content ) );
530
+ break;
531
+ case 'bcc':
532
+ $bcc = array_merge( (array) $bcc, explode( ',', $content ) );
533
+ break;
534
+ default:
535
+ // Add it to our grand headers array
536
+ $headers[trim( $name )] = trim( $content );
537
+ break;
538
+ }
539
+ }
540
+ }
541
+ }
542
+
543
+ // Empty out the values that may be set
544
+ $phpmailer->ClearAllRecipients();
545
+ $phpmailer->ClearAttachments();
546
+ $phpmailer->ClearCustomHeaders();
547
+ $phpmailer->ClearReplyTos();
548
+
549
+ // From email and name
550
+ // If we don't have a name from the input headers
551
+ if ( !isset( $from_name ) ){
552
+ $from_name = $options['from_name'];//'WordPress';
553
+ }
554
+ /* If we don't have an email from the input headers default to wordpress@$sitename
555
+ * Some hosts will block outgoing mail from this address if it doesn't exist but
556
+ * there's no easy alternative. Defaulting to admin_email might appear to be another
557
+ * option but some hosts may refuse to relay mail from an unknown domain. See
558
+ * https://core.trac.wordpress.org/ticket/5007.
559
+ */
560
+
561
+ if ( !isset( $from_email ) ) {
562
+ // Get the site domain and get rid of www.
563
+ $sitename = strtolower( $_SERVER['SERVER_NAME'] );
564
+ if ( substr( $sitename, 0, 4 ) == 'www.' ) {
565
+ $sitename = substr( $sitename, 4 );
566
+ }
567
+
568
+ $from_email = $options['from_email'];//'wordpress@' . $sitename;
569
+ }
570
+
571
+ /**
572
+ * Filter the email address to send from.
573
+ *
574
+ * @since 2.2.0
575
+ *
576
+ * @param string $from_email Email address to send from.
577
+ */
578
+ $phpmailer->From = apply_filters( 'wp_mail_from', $from_email );
579
+
580
+ /**
581
+ * Filter the name to associate with the "from" email address.
582
+ *
583
+ * @since 2.3.0
584
+ *
585
+ * @param string $from_name Name associated with the "from" email address.
586
+ */
587
+ $phpmailer->FromName = apply_filters( 'wp_mail_from_name', $from_name );
588
+
589
+ // Set destination addresses
590
+ if ( !is_array( $to ) )
591
+ $to = explode( ',', $to );
592
+
593
+ foreach ( (array) $to as $recipient ) {
594
+ try {
595
+ // Break $recipient into name and address parts if in the format "Foo <bar@baz.com>"
596
+ $recipient_name = '';
597
+ if ( preg_match( '/(.*)<(.+)>/', $recipient, $matches ) ) {
598
+ if ( count( $matches ) == 3 ) {
599
+ $recipient_name = $matches[1];
600
+ $recipient = $matches[2];
601
+ }
602
+ }
603
+ $phpmailer->AddAddress( $recipient, $recipient_name);
604
+ } catch ( phpmailerException $e ) {
605
+ continue;
606
+ }
607
+ }
608
+
609
+ // Set mail's subject and body
610
+ $phpmailer->Subject = $subject;
611
+ $phpmailer->Body = $message;
612
+
613
+ // Add any CC and BCC recipients
614
+ if ( !empty( $cc ) ) {
615
+ foreach ( (array) $cc as $recipient ) {
616
+ try {
617
+ // Break $recipient into name and address parts if in the format "Foo <bar@baz.com>"
618
+ $recipient_name = '';
619
+ if ( preg_match( '/(.*)<(.+)>/', $recipient, $matches ) ) {
620
+ if ( count( $matches ) == 3 ) {
621
+ $recipient_name = $matches[1];
622
+ $recipient = $matches[2];
623
+ }
624
+ }
625
+ $phpmailer->AddCc( $recipient, $recipient_name );
626
+ } catch ( phpmailerException $e ) {
627
+ continue;
628
+ }
629
+ }
630
+ }
631
+
632
+ if ( !empty( $bcc ) ) {
633
+ foreach ( (array) $bcc as $recipient) {
634
+ try {
635
+ // Break $recipient into name and address parts if in the format "Foo <bar@baz.com>"
636
+ $recipient_name = '';
637
+ if ( preg_match( '/(.*)<(.+)>/', $recipient, $matches ) ) {
638
+ if ( count( $matches ) == 3 ) {
639
+ $recipient_name = $matches[1];
640
+ $recipient = $matches[2];
641
+ }
642
+ }
643
+ $phpmailer->AddBcc( $recipient, $recipient_name );
644
+ } catch ( phpmailerException $e ) {
645
+ continue;
646
+ }
647
+ }
648
+ }
649
+
650
+ // Tell PHPMailer to use SMTP
651
+ $phpmailer->isSMTP(); //$phpmailer->IsMail();
652
+ // Set the hostname of the mail server
653
+ $phpmailer->Host = $options['smtp_host'];
654
+ // Whether to use SMTP authentication
655
+ if(isset($options['smtp_auth']) && $options['smtp_auth'] == "true"){
656
+ $phpmailer->SMTPAuth = true;
657
+ // SMTP username
658
+ $phpmailer->Username = $options['smtp_username'];
659
+ // SMTP password
660
+ $phpmailer->Password = base64_decode($options['smtp_password']);
661
+ }
662
+ // Whether to use encryption
663
+ $type_of_encryption = $options['type_of_encryption'];
664
+ if($type_of_encryption=="none"){
665
+ $type_of_encryption = '';
666
+ }
667
+ $phpmailer->SMTPSecure = $type_of_encryption;
668
+ // SMTP port
669
+ $phpmailer->Port = $options['smtp_port'];
670
+
671
+ // Whether to enable TLS encryption automatically if a server supports it
672
+ $phpmailer->SMTPAutoTLS = false;
673
+ //enable debug when sending a test mail
674
+ if(isset($_POST['smtp_mailer_send_test_email'])){
675
+ $phpmailer->SMTPDebug = 4;
676
+ // Ask for HTML-friendly debug output
677
+ $phpmailer->Debugoutput = 'html';
678
+ }
679
+
680
+ // Set Content-Type and charset
681
+ // If we don't have a content-type from the input headers
682
+ if ( !isset( $content_type ) )
683
+ $content_type = 'text/plain';
684
+
685
+ /**
686
+ * Filter the wp_mail() content type.
687
+ *
688
+ * @since 2.3.0
689
+ *
690
+ * @param string $content_type Default wp_mail() content type.
691
+ */
692
+ $content_type = apply_filters( 'wp_mail_content_type', $content_type );
693
+
694
+ $phpmailer->ContentType = $content_type;
695
+
696
+ // Set whether it's plaintext, depending on $content_type
697
+ if ( 'text/html' == $content_type )
698
+ $phpmailer->IsHTML( true );
699
+
700
+ // If we don't have a charset from the input headers
701
+ if ( !isset( $charset ) )
702
+ $charset = get_bloginfo( 'charset' );
703
+
704
+ // Set the content-type and charset
705
+
706
+ /**
707
+ * Filter the default wp_mail() charset.
708
+ *
709
+ * @since 2.3.0
710
+ *
711
+ * @param string $charset Default email charset.
712
+ */
713
+ $phpmailer->CharSet = apply_filters( 'wp_mail_charset', $charset );
714
+
715
+ // Set custom headers
716
+ if ( !empty( $headers ) ) {
717
+ foreach ( (array) $headers as $name => $content ) {
718
+ $phpmailer->AddCustomHeader( sprintf( '%1$s: %2$s', $name, $content ) );
719
+ }
720
+
721
+ if ( false !== stripos( $content_type, 'multipart' ) && ! empty($boundary) )
722
+ $phpmailer->AddCustomHeader( sprintf( "Content-Type: %s;\n\t boundary=\"%s\"", $content_type, $boundary ) );
723
+ }
724
+
725
+ if ( !empty( $attachments ) ) {
726
+ foreach ( $attachments as $attachment ) {
727
+ try {
728
+ $phpmailer->AddAttachment($attachment);
729
+ } catch ( phpmailerException $e ) {
730
+ continue;
731
+ }
732
+ }
733
+ }
734
+
735
+ /**
736
+ * Fires after PHPMailer is initialized.
737
+ *
738
+ * @since 2.2.0
739
+ *
740
+ * @param PHPMailer &$phpmailer The PHPMailer instance, passed by reference.
741
+ */
742
+ //do_action_ref_array( 'phpmailer_init', array( &$phpmailer ) );
743
+
744
+ // Send!
745
+ try {
746
+ return $phpmailer->Send();
747
+ } catch ( phpmailerException $e ) {
748
+
749
+ $mail_error_data = compact( $to, $subject, $message, $headers, $attachments );
750
+
751
+ /**
752
+ * Fires after a phpmailerException is caught.
753
+ *
754
+ * @since 4.4.0
755
+ *
756
+ * @param WP_Error $error A WP_Error object with the phpmailerException code, message, and an array
757
+ * containing the mail recipient, subject, message, headers, and attachments.
758
+ */
759
+ do_action( 'wp_mail_failed', new WP_Error( $e->getCode(), $e->getMessage(), $mail_error_data ) );
760
+
761
+ return false;
762
+ }
763
+ }
764
+
765
+ }
readme.txt ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === SMTP Mailer ===
2
+ Contributors: naa986
3
+ Donate link: https://wphowto.net/
4
+ Tags: smtp, mail, mailer, phpmailer, wp_mail, email
5
+ Requires at least: 4.4
6
+ Tested up to: 4.7
7
+ Stable tag: 1.0.1
8
+ License: GPLv2 or later
9
+ License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
+
11
+ Configure a SMTP server to send email from your WordPress site. Configure the wp_mail() function to use SMTP instead of the PHP mail() function.
12
+
13
+ == Description ==
14
+
15
+ [SMTP Mailer](https://wphowto.net/smtp-mailer-plugin-for-wordpress-1482) plugin allows you to configure a mail server which handles all outgoing email from your website. It takes control of the wp_mail function and use SMTP instead.
16
+
17
+ = SMTP Mailer Settings =
18
+
19
+ * **SMTP Host**: Your outgoing mail server (e.g. smtp.gmail.com).
20
+ * **SMTP Authentication**: Whether to use SMTP authentication when sending an email (True/False). If you choose to authenticate you will also need to provide your username and password.
21
+ * **SMTP Username**: The username to connect to your SMTP server.
22
+ * **SMTP Password**: The password to connect to your SMTP server.
23
+ * **Type of Encryption**: The encryption to be used when sending an email (TLS/SSL/No Encryption. TLS is recommended).
24
+ * **SMTP Port**: The port to be used when sending an email (587/465/25). If you choose TLS the port should be set to 587. For SSL use port 465 instead.
25
+ * **From Email Address**: The email address to be used as the From Address when sending an email.
26
+ * **From Name**: The name to be used as the From Name when sending an email.
27
+
28
+ = SMTP Mailer Test Email =
29
+
30
+ Once you have configured the settings you can send a test email to check the functionality of the plugin.
31
+
32
+ * **To**: Email address of the recipient.
33
+ * **Subject**: Subject of the email.
34
+ * **Message**: Email body.
35
+
36
+ = Known Compatibility =
37
+
38
+ SMTP Mailer should work with any plugin that uses the WordPress Mail function. However, It has been tested with the following form and contact form plugins:
39
+
40
+ * Contact Form 7
41
+ * Jetpack Contact Form
42
+ * Visual Form Builder
43
+ * Fast Secure Contact Form
44
+ * Formidable Forms
45
+ * Contact Form by BestWebSoft
46
+
47
+ For detailed setup instructions please visit the [SMTP Mailer](https://wphowto.net/smtp-mailer-plugin-for-wordpress-1482) plugin page.
48
+
49
+ == Installation ==
50
+
51
+ 1. Go to the Add New plugins screen in your WordPress Dashboard
52
+ 1. Click the upload tab
53
+ 1. Browse for the plugin file (smtp-mailer.zip) on your computer
54
+ 1. Click "Install Now" and then hit the activate button
55
+
56
+ == Frequently Asked Questions ==
57
+
58
+ = Can I send email via SMTP from my website using this plugin? =
59
+
60
+ Yes.
61
+
62
+ == Screenshots ==
63
+
64
+ For screenshots please visit the [SMTP Mailer](https://wphowto.net/smtp-mailer-plugin-for-wordpress-1482) plugin page
65
+
66
+ == Upgrade Notice ==
67
+ none
68
+
69
+ == Changelog ==
70
+
71
+ = 1.0.1 =
72
+ * First commit