SMTP Mailer - Version 1.0.2

Version Description

  • SMTP Mailer now supports the "wp_mail_failed" hook which fires after a phpmailerException is caught.
  • 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 SMTP Mailer
Version 1.0.2
Comparing to
See all releases

Code changes from version 1.0.1 to 1.0.2

Files changed (2) hide show
  1. main.php +74 -52
  2. readme.txt +6 -2
main.php CHANGED
@@ -1,7 +1,7 @@
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/
@@ -16,8 +16,8 @@ if (!defined('ABSPATH')){
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
 
@@ -242,6 +242,10 @@ class SMTP_MAILER {
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;
@@ -251,6 +255,7 @@ class SMTP_MAILER {
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');
@@ -268,7 +273,14 @@ class SMTP_MAILER {
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']);
@@ -340,6 +352,12 @@ class SMTP_MAILER {
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
 
@@ -411,7 +429,7 @@ if(!function_exists('wp_mail') && is_smtp_mailer_configured()){
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
  *
@@ -456,6 +474,8 @@ if(!function_exists('wp_mail') && is_smtp_mailer_configured()){
456
  }
457
 
458
  // Headers
 
 
459
  if ( empty( $headers ) ) {
460
  $headers = array();
461
  } else {
@@ -467,8 +487,6 @@ if(!function_exists('wp_mail') && is_smtp_mailer_configured()){
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 ) ) {
@@ -531,6 +549,9 @@ if(!function_exists('wp_mail') && is_smtp_mailer_configured()){
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 );
@@ -569,78 +590,67 @@ if(!function_exists('wp_mail') && is_smtp_mailer_configured()){
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
  }
@@ -676,6 +686,17 @@ if(!function_exists('wp_mail') && is_smtp_mailer_configured()){
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
@@ -683,7 +704,7 @@ if(!function_exists('wp_mail') && is_smtp_mailer_configured()){
683
  $content_type = 'text/plain';
684
 
685
  /**
686
- * Filter the wp_mail() content type.
687
  *
688
  * @since 2.3.0
689
  *
@@ -704,7 +725,7 @@ if(!function_exists('wp_mail') && is_smtp_mailer_configured()){
704
  // Set the content-type and charset
705
 
706
  /**
707
- * Filter the default wp_mail() charset.
708
  *
709
  * @since 2.3.0
710
  *
@@ -746,17 +767,18 @@ if(!function_exists('wp_mail') && is_smtp_mailer_configured()){
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
  }
1
  <?php
2
  /*
3
  Plugin Name: SMTP Mailer
4
+ Version: 1.0.2
5
  Plugin URI: http://wphowto.net/smtp-mailer-plugin-for-wordpress-1482
6
  Author: naa986
7
  Author URI: http://wphowto.net/
16
 
17
  class SMTP_MAILER {
18
 
19
+ var $plugin_version = '1.0.2';
20
+ var $phpmailer_version = '5.2.14';
21
  var $plugin_url;
22
  var $plugin_path;
23
 
242
  if(isset($_POST['from_name']) && !empty($_POST['from_name'])){
243
  $from_name = sanitize_text_field(stripslashes($_POST['from_name']));
244
  }
245
+ $disable_ssl_verification = '';
246
+ if(isset($_POST['disable_ssl_verification']) && !empty($_POST['disable_ssl_verification'])){
247
+ $disable_ssl_verification = sanitize_text_field($_POST['disable_ssl_verification']);
248
+ }
249
  $options = array();
250
  $options['smtp_host'] = $smtp_host;
251
  $options['smtp_auth'] = $smtp_auth;
255
  $options['smtp_port'] = $smtp_port;
256
  $options['from_email'] = $from_email;
257
  $options['from_name'] = $from_name;
258
+ $options['disable_ssl_verification'] = $disable_ssl_verification;
259
  smtp_mailer_update_option($options);
260
  echo '<div id="message" class="updated fade"><p><strong>';
261
  echo __('Settings Saved!', 'smtp-mailer');
273
  $options['smtp_port'] = '';
274
  $options['from_email'] = '';
275
  $options['from_name'] = '';
276
+ $options['disable_ssl_verification'] = '';
277
+ }
278
+
279
+ // Avoid warning notice since this option was added later
280
+ if(!isset($options['disable_ssl_verification'])){
281
+ $options['disable_ssl_verification'] = '';
282
  }
283
+
284
  $smtp_password = '';
285
  if(isset($options['smtp_password']) && !empty($options['smtp_password'])){
286
  $smtp_password = base64_decode($options['smtp_password']);
352
  <td><input name="from_name" type="text" id="from_name" value="<?php echo $options['from_name']; ?>" class="regular-text code">
353
  <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>
354
  </tr>
355
+
356
+ <tr valign="top">
357
+ <th scope="row"><label for="disable_ssl_verification"><?php _e('Disable SSL Certificate Verification', 'smtp-mailer');?></label></th>
358
+ <td><input name="disable_ssl_verification" type="checkbox" id="disable_ssl_verification" <?php checked($options['disable_ssl_verification'], 1); ?> value="1">
359
+ <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', 'smtp-mailer');?></p></td>
360
+ </tr>
361
 
362
  </tbody>
363
 
429
  // Compact the input, apply the filters, and extract them back out
430
 
431
  /**
432
+ * Filters the wp_mail() arguments.
433
  *
434
  * @since 2.2.0
435
  *
474
  }
475
 
476
  // Headers
477
+ $cc = $bcc = $reply_to = array();
478
+
479
  if ( empty( $headers ) ) {
480
  $headers = array();
481
  } else {
487
  $tempheaders = $headers;
488
  }
489
  $headers = array();
 
 
490
 
491
  // If it's actually got contents
492
  if ( !empty( $tempheaders ) ) {
549
  case 'bcc':
550
  $bcc = array_merge( (array) $bcc, explode( ',', $content ) );
551
  break;
552
+ case 'reply-to':
553
+ $reply_to = array_merge( (array) $reply_to, explode( ',', $content ) );
554
+ break;
555
  default:
556
  // Add it to our grand headers array
557
  $headers[trim( $name )] = trim( $content );
590
  }
591
 
592
  /**
593
+ * Filters the email address to send from.
594
  *
595
  * @since 2.2.0
596
  *
597
  * @param string $from_email Email address to send from.
598
  */
599
+ $from_email = apply_filters( 'wp_mail_from', $from_email );
600
 
601
  /**
602
+ * Filters the name to associate with the "from" email address.
603
  *
604
  * @since 2.3.0
605
  *
606
  * @param string $from_name Name associated with the "from" email address.
607
  */
608
+ $from_name = apply_filters( 'wp_mail_from_name', $from_name );
609
+
610
+ $phpmailer->setFrom( $from_email, $from_name, false );
611
 
612
  // Set destination addresses
613
  if ( !is_array( $to ) )
614
  $to = explode( ',', $to );
615
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
616
  // Set mail's subject and body
617
  $phpmailer->Subject = $subject;
618
  $phpmailer->Body = $message;
619
 
620
+ // Use appropriate methods for handling addresses, rather than treating them as generic headers
621
+ $address_headers = compact( 'to', 'cc', 'bcc', 'reply_to' );
622
+
623
+ foreach ( $address_headers as $address_header => $addresses ) {
624
+ if ( empty( $addresses ) ) {
 
 
 
 
 
 
 
 
 
625
  continue;
626
  }
 
 
627
 
628
+ foreach ( (array) $addresses as $address ) {
 
629
  try {
630
  // Break $recipient into name and address parts if in the format "Foo <bar@baz.com>"
631
  $recipient_name = '';
632
+
633
+ if ( preg_match( '/(.*)<(.+)>/', $address, $matches ) ) {
634
  if ( count( $matches ) == 3 ) {
635
  $recipient_name = $matches[1];
636
+ $address = $matches[2];
637
  }
638
  }
639
+
640
+ switch ( $address_header ) {
641
+ case 'to':
642
+ $phpmailer->addAddress( $address, $recipient_name );
643
+ break;
644
+ case 'cc':
645
+ $phpmailer->addCc( $address, $recipient_name );
646
+ break;
647
+ case 'bcc':
648
+ $phpmailer->addBcc( $address, $recipient_name );
649
+ break;
650
+ case 'reply_to':
651
+ $phpmailer->addReplyTo( $address, $recipient_name );
652
+ break;
653
+ }
654
  } catch ( phpmailerException $e ) {
655
  continue;
656
  }
686
  // Ask for HTML-friendly debug output
687
  $phpmailer->Debugoutput = 'html';
688
  }
689
+
690
+ //disable ssl certificate verification if checked
691
+ if(isset($options['disable_ssl_verification']) && !empty($options['disable_ssl_verification'])){
692
+ $phpmailer->SMTPOptions = array(
693
+ 'ssl' => array(
694
+ 'verify_peer' => false,
695
+ 'verify_peer_name' => false,
696
+ 'allow_self_signed' => true
697
+ )
698
+ );
699
+ }
700
 
701
  // Set Content-Type and charset
702
  // If we don't have a content-type from the input headers
704
  $content_type = 'text/plain';
705
 
706
  /**
707
+ * Filters the wp_mail() content type.
708
  *
709
  * @since 2.3.0
710
  *
725
  // Set the content-type and charset
726
 
727
  /**
728
+ * Filters the default wp_mail() charset.
729
  *
730
  * @since 2.3.0
731
  *
767
  return $phpmailer->Send();
768
  } catch ( phpmailerException $e ) {
769
 
770
+ $mail_error_data = compact( 'to', 'subject', 'message', 'headers', 'attachments' );
771
+ $mail_error_data['phpmailer_exception_code'] = $e->getCode();
772
 
773
  /**
774
  * Fires after a phpmailerException is caught.
775
  *
776
  * @since 4.4.0
777
  *
778
+ * @param WP_Error $error A WP_Error object with the phpmailerException message, and an array
779
  * containing the mail recipient, subject, message, headers, and attachments.
780
  */
781
+ do_action( 'wp_mail_failed', new WP_Error( 'wp_mail_failed', $e->getMessage(), $mail_error_data ) );
782
 
783
  return false;
784
  }
readme.txt CHANGED
@@ -2,9 +2,9 @@
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
 
@@ -68,5 +68,9 @@ none
68
 
69
  == Changelog ==
70
 
 
 
 
 
71
  = 1.0.1 =
72
  * First commit
2
  Contributors: naa986
3
  Donate link: https://wphowto.net/
4
  Tags: smtp, mail, mailer, phpmailer, wp_mail, email
5
+ Requires at least: 4.7
6
  Tested up to: 4.7
7
+ Stable tag: 1.0.2
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
68
 
69
  == Changelog ==
70
 
71
+ = 1.0.2 =
72
+ * SMTP Mailer now supports the "wp_mail_failed" hook which fires after a phpmailerException is caught.
73
+ * 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.
74
+
75
  = 1.0.1 =
76
  * First commit