Gmail SMTP - Version 1.0.6

Version Description

  • Added a new option to bypass this error on some servers where the SSL certificate is not properly configured - Warning: stream_socket_enable_crypto(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
Download this release

Release Info

Developer naa986
Plugin Icon 128x128 Gmail SMTP
Version 1.0.6
Comparing to
See all releases

Code changes from version 1.0.5 to 1.0.6

Files changed (2) hide show
  1. main.php +54 -81
  2. readme.txt +11 -11
main.php CHANGED
@@ -1,7 +1,7 @@
1
  <?php
2
  /*
3
  Plugin Name: Gmail SMTP
4
- Version: 1.0.5
5
  Plugin URI: http://wphowto.net/
6
  Author: naa986
7
  Author URI: http://wphowto.net/
@@ -16,7 +16,7 @@ if (!defined('ABSPATH')){
16
 
17
  class GMAIL_SMTP {
18
 
19
- var $plugin_version = '1.0.5';
20
  var $phpmailer_version = '5.2.14';
21
  var $plugin_url;
22
  var $plugin_path;
@@ -168,76 +168,7 @@ class GMAIL_SMTP {
168
  $message = sanitize_text_field($_POST['gmail_smtp_email_body']);
169
  }
170
 
171
- $options = gmail_smtp_get_option();
172
-
173
- $mail = new PHPMailerOAuth; /* this must be the custom class we created */
174
-
175
- // Tell PHPMailer to use SMTP
176
- $mail->isSMTP();
177
-
178
- // Enable SMTP debugging
179
- $mail->SMTPDebug = 4;
180
-
181
- // Ask for HTML-friendly debug output
182
- $mail->Debugoutput = 'html';
183
-
184
- // Set AuthType
185
- $mail->AuthType = 'XOAUTH2';
186
-
187
- // Whether to use SMTP authentication
188
- $mail->SMTPAuth = true;
189
-
190
- // Set the encryption system to use - ssl (deprecated) or tls
191
- $mail->SMTPSecure = $options['type_of_encryption'];
192
-
193
- // Set the hostname of the mail server
194
- $mail->Host = 'smtp.gmail.com';
195
-
196
- // Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
197
- $mail->Port = $options['smtp_port'];
198
-
199
- // User Email to use for SMTP authentication - Use the same Email used in Google Developer Console
200
- $mail->oauthUserEmail = $options['oauth_user_email'];
201
-
202
- //Obtained From Google Developer Console
203
- $mail->oauthClientId = $options['oauth_client_id'];
204
-
205
- //Obtained From Google Developer Console
206
- $mail->oauthClientSecret = $options['oauth_client_secret'];
207
-
208
- $gmail_token = json_decode($options['oauth_access_token'], true);
209
-
210
- //Obtained By running get_oauth_token.php after setting up APP in Google Developer Console.
211
- //Set Redirect URI in Developer Console as [https/http]://<yourdomain>/<folder>/get_oauth_token.php
212
- // eg: http://localhost/phpmail/get_oauth_token.php
213
- $mail->oauthRefreshToken = $gmail_token['refresh_token'];
214
-
215
- //Set who the message is to be sent from
216
- $mail->setFrom($options['from_email'], $options['from_name']);
217
-
218
- //Set an alternative reply-to address
219
- //$mail->addReplyTo('reply_to@gmail.ug', 'James Scott');
220
-
221
- //Set who the message is to be sent to
222
- $mail->addAddress($to);
223
-
224
- //Set the subject line
225
- $mail->Subject = $subject;
226
-
227
- //Read an HTML message body from an external file, convert referenced images to embedded,
228
- //convert HTML into a basic plain-text alternative body
229
- //$mail->msgHTML(file_get_contents('contents.html'), dirname(__FILE__));
230
-
231
- $mail->Body = $message;
232
-
233
- $mail->SMTPAutoTLS = false;
234
- //send the message, check for errors
235
- if (!$mail->send()) {
236
- echo __('Mailer Error: ', 'gmail-smtp') . $mail->ErrorInfo;
237
- } else {
238
- echo __('Message sent!', 'gmail-smtp');
239
- }
240
-
241
  }
242
  ?>
243
  <form method="post" action="<?php echo $_SERVER["REQUEST_URI"]; ?>">
@@ -386,6 +317,10 @@ class GMAIL_SMTP {
386
  if(isset($_POST['smtp_port']) && !empty($_POST['smtp_port'])){
387
  $smtp_port = sanitize_text_field($_POST['smtp_port']);
388
  }
 
 
 
 
389
  $options = array();
390
  $options['oauth_client_id'] = $client_id;
391
  $options['oauth_client_secret'] = $client_secret;
@@ -394,6 +329,7 @@ class GMAIL_SMTP {
394
  $options['from_name'] = $from_name;
395
  $options['type_of_encryption'] = $type_of_encryption;
396
  $options['smtp_port'] = $smtp_port;
 
397
  gmail_smtp_update_option($options);
398
  echo '<div id="message" class="updated fade"><p><strong>';
399
  echo __('Settings Saved!', 'gmail-smtp');
@@ -416,7 +352,20 @@ class GMAIL_SMTP {
416
  $options = gmail_smtp_get_option();
417
  if(!is_array($options)){
418
  $options = array();
 
 
 
 
 
 
 
 
 
 
 
 
419
  }
 
420
  $url = "https://www.google.com/accounts/Logout?continue=https://console.developers.google.com/start/api?id=gmail";
421
  $link_text = sprintf(wp_kses(__('Create a new <a target="_blank" href="%s">web application</a> and set its Authorized Redirect URL to the one shown on this page.', 'gmail-smtp'), array('a' => array('href' => array(), 'target' => array()))), esc_url($url));
422
  ?>
@@ -455,37 +404,37 @@ class GMAIL_SMTP {
455
 
456
  <tr valign="top">
457
  <th scope="row"><label for="oauth_redirect_uri"><?php _e('Authorized Redirect URI', 'gmail-smtp');?></label></th>
458
- <td><input name="oauth_redirect_uri" type="text" id="oauth_redirect_uri" value="<?php echo admin_url("options-general.php?page=gmail-smtp-settings&action=oauth_grant"); ?>" readonly class="regular-text code">
459
  <p class="description"><?php _e('Copy this URL into your web application', 'gmail-smtp');?></p></td>
460
  </tr>
461
 
462
  <tr valign="top">
463
  <th scope="row"><label for="oauth_client_id"><?php _e('Client ID', 'gmail-smtp');?></label></th>
464
- <td><input name="oauth_client_id" type="text" id="oauth_client_id" value="<?php echo $options['oauth_client_id']; ?>" class="regular-text code">
465
  <p class="description"><?php _e('The client ID of your web application', 'gmail-smtp');?></p></td>
466
  </tr>
467
 
468
  <tr valign="top">
469
  <th scope="row"><label for="oauth_client_secret"><?php _e('Client Secret', 'gmail-smtp');?></label></th>
470
- <td><input name="oauth_client_secret" type="text" id="oauth_client_secret" value="<?php echo $options['oauth_client_secret']; ?>" class="regular-text code">
471
  <p class="description"><?php _e('The client secret of your web application', 'gmail-smtp');?></p></td>
472
  </tr>
473
 
474
  <tr valign="top">
475
  <th scope="row"><label for="oauth_user_email"><?php _e('OAuth Email Address', 'gmail-smtp');?></label></th>
476
- <td><input name="oauth_user_email" type="text" id="oauth_user_email" value="<?php echo $options['oauth_user_email']; ?>" class="regular-text code">
477
  <p class="description"><?php _e('The email address that you will use for SMTP authentication. This should be the same email used in the Google Developers Console.', 'gmail-smtp');?></p></td>
478
  </tr>
479
 
480
  <tr valign="top">
481
  <th scope="row"><label for="from_email"><?php _e('From Email Address', 'gmail-smtp');?></label></th>
482
- <td><input name="from_email" type="text" id="from_email" value="<?php echo $options['from_email']; ?>" class="regular-text code">
483
  <p class="description"><?php _e('The email address which will be used as the From Address when sending an email.', 'gmail-smtp');?></p></td>
484
  </tr>
485
 
486
  <tr valign="top">
487
  <th scope="row"><label for="from_name"><?php _e('From Name', 'gmail-smtp');?></label></th>
488
- <td><input name="from_name" type="text" id="from_name" value="<?php echo $options['from_name']; ?>" class="regular-text code">
489
  <p class="description"><?php _e('The name which will be used as the From Name when sending an email.', 'gmail-smtp');?></p></td>
490
  </tr>
491
 
@@ -502,15 +451,21 @@ class GMAIL_SMTP {
502
 
503
  <tr valign="top">
504
  <th scope="row"><label for="smtp_port"><?php _e('SMTP Port', 'gmail-smtp');?></label></th>
505
- <td><input name="smtp_port" type="text" id="smtp_port" value="<?php echo $options['smtp_port']; ?>" class="regular-text code">
506
  <p class="description"><?php _e('The port which will be used when sending an email. If you choose TLS it should be set to 587. For SSL use port 465 instead.', 'gmail-smtp');?></p></td>
507
  </tr>
 
 
 
 
 
 
508
 
509
  </tbody>
510
 
511
  </table>
512
 
513
- <p class="submit"><input type="submit" name="gmail_smtp_update_settings" id="gmail_smtp_update_settings" class="button button-primary" value="Save Changes"></p>
514
  </form>
515
 
516
  <?php
@@ -567,6 +522,7 @@ function gmail_smtp_get_empty_options_array(){
567
  $options['from_name'] = '';
568
  $options['type_of_encryption'] = '';
569
  $options['smtp_port'] = '';
 
570
  return $options;
571
  }
572
 
@@ -673,7 +629,24 @@ function wp_mail( $to, $subject, $message, $headers = '', $attachments = array()
673
  $phpmailer->Port = $options['smtp_port'];
674
 
675
  $phpmailer->SMTPAutoTLS = false;
676
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
677
  // User Email to use for SMTP authentication - Use the same Email used in Google Developer Console
678
  $phpmailer->oauthUserEmail = $options['oauth_user_email'];
679
 
1
  <?php
2
  /*
3
  Plugin Name: Gmail SMTP
4
+ Version: 1.0.6
5
  Plugin URI: http://wphowto.net/
6
  Author: naa986
7
  Author URI: http://wphowto.net/
16
 
17
  class GMAIL_SMTP {
18
 
19
+ var $plugin_version = '1.0.6';
20
  var $phpmailer_version = '5.2.14';
21
  var $plugin_url;
22
  var $plugin_path;
168
  $message = sanitize_text_field($_POST['gmail_smtp_email_body']);
169
  }
170
 
171
+ wp_mail($to, $subject, $message);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
172
  }
173
  ?>
174
  <form method="post" action="<?php echo $_SERVER["REQUEST_URI"]; ?>">
317
  if(isset($_POST['smtp_port']) && !empty($_POST['smtp_port'])){
318
  $smtp_port = sanitize_text_field($_POST['smtp_port']);
319
  }
320
+ $disable_ssl_verification = '';
321
+ if(isset($_POST['disable_ssl_verification']) && !empty($_POST['disable_ssl_verification'])){
322
+ $disable_ssl_verification = sanitize_text_field($_POST['disable_ssl_verification']);
323
+ }
324
  $options = array();
325
  $options['oauth_client_id'] = $client_id;
326
  $options['oauth_client_secret'] = $client_secret;
329
  $options['from_name'] = $from_name;
330
  $options['type_of_encryption'] = $type_of_encryption;
331
  $options['smtp_port'] = $smtp_port;
332
+ $options['disable_ssl_verification'] = $disable_ssl_verification;
333
  gmail_smtp_update_option($options);
334
  echo '<div id="message" class="updated fade"><p><strong>';
335
  echo __('Settings Saved!', 'gmail-smtp');
352
  $options = gmail_smtp_get_option();
353
  if(!is_array($options)){
354
  $options = array();
355
+ $options['oauth_client_id'] = '';
356
+ $options['oauth_client_secret'] = '';
357
+ $options['oauth_user_email'] = '';
358
+ $options['from_email'] = '';
359
+ $options['from_name'] = '';
360
+ $options['type_of_encryption'] = '';
361
+ $options['smtp_port'] = '';
362
+ $options['disable_ssl_verification'] = '';
363
+ }
364
+ // Avoid warning notice since this option was added later
365
+ if(!isset($options['disable_ssl_verification'])){
366
+ $options['disable_ssl_verification'] = '';
367
  }
368
+
369
  $url = "https://www.google.com/accounts/Logout?continue=https://console.developers.google.com/start/api?id=gmail";
370
  $link_text = sprintf(wp_kses(__('Create a new <a target="_blank" href="%s">web application</a> and set its Authorized Redirect URL to the one shown on this page.', 'gmail-smtp'), array('a' => array('href' => array(), 'target' => array()))), esc_url($url));
371
  ?>
404
 
405
  <tr valign="top">
406
  <th scope="row"><label for="oauth_redirect_uri"><?php _e('Authorized Redirect URI', 'gmail-smtp');?></label></th>
407
+ <td><input name="oauth_redirect_uri" type="text" id="oauth_redirect_uri" value="<?php echo esc_url_raw(admin_url("options-general.php?page=gmail-smtp-settings&action=oauth_grant")); ?>" readonly class="regular-text code">
408
  <p class="description"><?php _e('Copy this URL into your web application', 'gmail-smtp');?></p></td>
409
  </tr>
410
 
411
  <tr valign="top">
412
  <th scope="row"><label for="oauth_client_id"><?php _e('Client ID', 'gmail-smtp');?></label></th>
413
+ <td><input name="oauth_client_id" type="text" id="oauth_client_id" value="<?php echo esc_attr($options['oauth_client_id']); ?>" class="regular-text code">
414
  <p class="description"><?php _e('The client ID of your web application', 'gmail-smtp');?></p></td>
415
  </tr>
416
 
417
  <tr valign="top">
418
  <th scope="row"><label for="oauth_client_secret"><?php _e('Client Secret', 'gmail-smtp');?></label></th>
419
+ <td><input name="oauth_client_secret" type="text" id="oauth_client_secret" value="<?php echo esc_attr($options['oauth_client_secret']); ?>" class="regular-text code">
420
  <p class="description"><?php _e('The client secret of your web application', 'gmail-smtp');?></p></td>
421
  </tr>
422
 
423
  <tr valign="top">
424
  <th scope="row"><label for="oauth_user_email"><?php _e('OAuth Email Address', 'gmail-smtp');?></label></th>
425
+ <td><input name="oauth_user_email" type="text" id="oauth_user_email" value="<?php echo esc_attr($options['oauth_user_email']); ?>" class="regular-text code">
426
  <p class="description"><?php _e('The email address that you will use for SMTP authentication. This should be the same email used in the Google Developers Console.', 'gmail-smtp');?></p></td>
427
  </tr>
428
 
429
  <tr valign="top">
430
  <th scope="row"><label for="from_email"><?php _e('From Email Address', 'gmail-smtp');?></label></th>
431
+ <td><input name="from_email" type="text" id="from_email" value="<?php echo esc_attr($options['from_email']); ?>" class="regular-text code">
432
  <p class="description"><?php _e('The email address which will be used as the From Address when sending an email.', 'gmail-smtp');?></p></td>
433
  </tr>
434
 
435
  <tr valign="top">
436
  <th scope="row"><label for="from_name"><?php _e('From Name', 'gmail-smtp');?></label></th>
437
+ <td><input name="from_name" type="text" id="from_name" value="<?php echo esc_attr($options['from_name']); ?>" class="regular-text code">
438
  <p class="description"><?php _e('The name which will be used as the From Name when sending an email.', 'gmail-smtp');?></p></td>
439
  </tr>
440
 
451
 
452
  <tr valign="top">
453
  <th scope="row"><label for="smtp_port"><?php _e('SMTP Port', 'gmail-smtp');?></label></th>
454
+ <td><input name="smtp_port" type="text" id="smtp_port" value="<?php echo esc_attr($options['smtp_port']); ?>" class="regular-text code">
455
  <p class="description"><?php _e('The port which will be used when sending an email. If you choose TLS it should be set to 587. For SSL use port 465 instead.', 'gmail-smtp');?></p></td>
456
  </tr>
457
+
458
+ <tr valign="top">
459
+ <th scope="row"><label for="disable_ssl_verification"><?php _e('Disable SSL Certificate Verification', 'gmail-smtp');?></label></th>
460
+ <td><input name="disable_ssl_verification" type="checkbox" id="disable_ssl_verification" <?php checked($options['disable_ssl_verification'], 1); ?> value="1">
461
+ <p class="description"><?php _e('As of PHP 5.6 you will get a warning/error if the SSL certificate on the server is not properly configured. You can check this option to disable that default behaviour. Please note that PHP 5.6 made this change for a good reason. So you should get your host to fix the SSL configurations instead of bypassing it', 'gmail-smtp');?></p></td>
462
+ </tr>
463
 
464
  </tbody>
465
 
466
  </table>
467
 
468
+ <p class="submit"><input type="submit" name="gmail_smtp_update_settings" id="gmail_smtp_update_settings" class="button button-primary" value="<?php _e('Save Changes', 'gmail-smtp');?>"></p>
469
  </form>
470
 
471
  <?php
522
  $options['from_name'] = '';
523
  $options['type_of_encryption'] = '';
524
  $options['smtp_port'] = '';
525
+ $options['disable_ssl_verification'] = '';
526
  return $options;
527
  }
528
 
629
  $phpmailer->Port = $options['smtp_port'];
630
 
631
  $phpmailer->SMTPAutoTLS = false;
632
+
633
+ //enable debug when sending a test mail
634
+ if(isset($_POST['gmail_smtp_send_test_email'])){
635
+ $phpmailer->SMTPDebug = 4;
636
+ // Ask for HTML-friendly debug output
637
+ $phpmailer->Debugoutput = 'html';
638
+ }
639
+
640
+ //disable ssl certificate verification if checked
641
+ if(isset($options['disable_ssl_verification']) && !empty($options['disable_ssl_verification'])){
642
+ $phpmailer->SMTPOptions = array(
643
+ 'ssl' => array(
644
+ 'verify_peer' => false,
645
+ 'verify_peer_name' => false,
646
+ 'allow_self_signed' => true
647
+ )
648
+ );
649
+ }
650
  // User Email to use for SMTP authentication - Use the same Email used in Google Developer Console
651
  $phpmailer->oauthUserEmail = $options['oauth_user_email'];
652
 
readme.txt CHANGED
@@ -1,10 +1,10 @@
1
  === Gmail SMTP ===
2
  Contributors: naa986
3
- Donate link: http://wphowto.net/
4
  Tags: smtp, gmail, mail, mailer, phpmailer, wp_mail, email, oauth2
5
  Requires at least: 4.3
6
- Tested up to: 4.5
7
- Stable tag: 1.0.5
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -12,7 +12,7 @@ Connect to Gmail SMTP server to automatically send email from your WordPress sit
12
 
13
  == Description ==
14
 
15
- [Gmail SMTP](http://wphowto.net/gmail-smtp-plugin-for-wordpress-1341 "Gmail SMTP Plugin for WordPress") plugin allows you to authenticate with your Gmail account to send email via Gmail SMTP server.
16
 
17
  Most shared hosting servers have restrictions when it comes to email. Usually email will get blocked or missing for no reason. Sometimes it will get blocked when your website reaches the daily limit of outgoing email. This plugin can bypass this issue by routing the email through Gmail's SMTP server.
18
 
@@ -58,6 +58,7 @@ Most shared hosting servers have restrictions when it comes to email. Usually em
58
  * **From Name**: The name which will be used as the From Name when sending an email.
59
  * **Type of Encryption**: The encryption which will be used when sending an email (TLS/SSL. TLS is recommended).
60
  * **SMTP Port**: The port which will be used when sending an email. If you choose TLS it should be set to 587. For SSL use port 465 instead.
 
61
 
62
  = Gmail SMTP Test Email =
63
 
@@ -67,11 +68,7 @@ Once you have configured the settings you can send a test email to check the fun
67
  * **Subject**: Subject of the email.
68
  * **Message**: Email body.
69
 
70
- For detailed setup instructions please visit the [Gmail SMTP](http://wphowto.net/gmail-smtp-plugin-for-wordpress-1341 "Gmail SMTP Plugin Documentation") plugin page.
71
-
72
- = Translation =
73
-
74
- If you are a non-English speaker please help [translate Gmail SMTP](https://translate.wordpress.org/projects/wp-plugins/gmail-smtp) into your language.
75
 
76
  = Requirements =
77
 
@@ -98,14 +95,17 @@ Yes.
98
 
99
  == Screenshots ==
100
 
101
- 1. Gmail SMTP Plugin Settings
102
- 2. Gmail SMTP Test Email Menu
103
 
104
  == Upgrade Notice ==
105
  none
106
 
107
  == Changelog ==
108
 
 
 
 
 
109
  = 1.0.5 =
110
  * Fixed a bug that was causing this error - "Strict Standards: Non-static method GmailXOAuth2::getClient()"
111
 
1
  === Gmail SMTP ===
2
  Contributors: naa986
3
+ Donate link: https://wphowto.net/
4
  Tags: smtp, gmail, mail, mailer, phpmailer, wp_mail, email, oauth2
5
  Requires at least: 4.3
6
+ Tested up to: 4.6
7
+ Stable tag: 1.0.6
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
12
 
13
  == Description ==
14
 
15
+ [Gmail SMTP](https://wphowto.net/gmail-smtp-plugin-for-wordpress-1341) plugin allows you to authenticate with your Gmail account to send email via Gmail SMTP server.
16
 
17
  Most shared hosting servers have restrictions when it comes to email. Usually email will get blocked or missing for no reason. Sometimes it will get blocked when your website reaches the daily limit of outgoing email. This plugin can bypass this issue by routing the email through Gmail's SMTP server.
18
 
58
  * **From Name**: The name which will be used as the From Name when sending an email.
59
  * **Type of Encryption**: The encryption which will be used when sending an email (TLS/SSL. TLS is recommended).
60
  * **SMTP Port**: The port which will be used when sending an email. If you choose TLS it should be set to 587. For SSL use port 465 instead.
61
+ * **Disable SSL Certificate Verification**: As of PHP 5.6 a warning/error will be displayed if the SSL certificate on the server is not properly configured. You can check this option to disable that default behaviour.
62
 
63
  = Gmail SMTP Test Email =
64
 
68
  * **Subject**: Subject of the email.
69
  * **Message**: Email body.
70
 
71
+ For detailed setup instructions please visit the [Gmail SMTP](https://wphowto.net/gmail-smtp-plugin-for-wordpress-1341) plugin page.
 
 
 
 
72
 
73
  = Requirements =
74
 
95
 
96
  == Screenshots ==
97
 
98
+ For screenshots please visit the [Gmail SMTP](https://wphowto.net/gmail-smtp-plugin-for-wordpress-1341) plugin page
 
99
 
100
  == Upgrade Notice ==
101
  none
102
 
103
  == Changelog ==
104
 
105
+ = 1.0.6 =
106
+ * Added a new option to bypass this error on some servers where the SSL certificate is not properly configured - Warning: stream_socket_enable_crypto(): SSL operation failed with code 1.
107
+ OpenSSL Error messages: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
108
+
109
  = 1.0.5 =
110
  * Fixed a bug that was causing this error - "Strict Standards: Non-static method GmailXOAuth2::getClient()"
111