Version Description
- Gmail SMTP now supports the "wp_mail_failed" hook which fires after a phpmailerException is caught.
Download this release
Release Info
Developer | naa986 |
Plugin | Gmail SMTP |
Version | 1.0.8 |
Comparing to | |
See all releases |
Code changes from version 1.0.7 to 1.0.8
- main.php +367 -350
- readme.txt +5 -2
main.php
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
<?php
|
2 |
/*
|
3 |
Plugin Name: Gmail SMTP
|
4 |
-
Version: 1.0.
|
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.
|
20 |
var $phpmailer_version = '5.2.14';
|
21 |
var $plugin_url;
|
22 |
var $plugin_path;
|
@@ -578,361 +578,378 @@ function is_gmail_smtp_configured() {
|
|
578 |
$GLOBALS['gmail-smtp'] = new GMAIL_SMTP();
|
579 |
|
580 |
if(!function_exists('wp_mail') && is_gmail_smtp_configured()){
|
581 |
-
|
582 |
-
|
583 |
-
|
584 |
-
|
585 |
-
|
586 |
-
|
587 |
-
|
588 |
-
|
589 |
-
|
590 |
-
|
591 |
-
|
592 |
-
|
593 |
-
|
594 |
-
|
595 |
-
|
596 |
-
|
597 |
-
|
598 |
-
if ( isset( $atts['subject'] ) ) {
|
599 |
-
$subject = $atts['subject'];
|
600 |
-
}
|
601 |
-
|
602 |
-
if ( isset( $atts['message'] ) ) {
|
603 |
-
$message = $atts['message'];
|
604 |
-
}
|
605 |
-
|
606 |
-
if ( isset( $atts['headers'] ) ) {
|
607 |
-
$headers = $atts['headers'];
|
608 |
-
}
|
609 |
-
|
610 |
-
if ( isset( $atts['attachments'] ) ) {
|
611 |
-
$attachments = $atts['attachments'];
|
612 |
-
}
|
613 |
-
|
614 |
-
if ( ! is_array( $attachments ) ) {
|
615 |
-
$attachments = explode( "\n", str_replace( "\r\n", "\n", $attachments ) );
|
616 |
-
}
|
617 |
-
|
618 |
-
$options = gmail_smtp_get_option();
|
619 |
-
|
620 |
-
$phpmailer = new PHPMailerOAuth; /* this must be the custom class we created */
|
621 |
|
622 |
-
|
623 |
-
|
624 |
-
|
625 |
-
// Set AuthType
|
626 |
-
$phpmailer->AuthType = 'XOAUTH2';
|
627 |
|
628 |
-
|
629 |
-
|
|
|
630 |
|
631 |
-
|
632 |
-
|
|
|
633 |
|
634 |
-
|
635 |
-
|
|
|
636 |
|
637 |
-
|
638 |
-
|
639 |
-
|
640 |
-
$phpmailer->SMTPAutoTLS = false;
|
641 |
-
|
642 |
-
//enable debug when sending a test mail
|
643 |
-
if(isset($_POST['gmail_smtp_send_test_email'])){
|
644 |
-
$phpmailer->SMTPDebug = 4;
|
645 |
-
// Ask for HTML-friendly debug output
|
646 |
-
$phpmailer->Debugoutput = 'html';
|
647 |
-
}
|
648 |
-
|
649 |
-
//disable ssl certificate verification if checked
|
650 |
-
if(isset($options['disable_ssl_verification']) && !empty($options['disable_ssl_verification'])){
|
651 |
-
$phpmailer->SMTPOptions = array(
|
652 |
-
'ssl' => array(
|
653 |
-
'verify_peer' => false,
|
654 |
-
'verify_peer_name' => false,
|
655 |
-
'allow_self_signed' => true
|
656 |
-
)
|
657 |
-
);
|
658 |
-
}
|
659 |
-
// User Email to use for SMTP authentication - Use the same Email used in Google Developer Console
|
660 |
-
$phpmailer->oauthUserEmail = $options['oauth_user_email'];
|
661 |
|
662 |
-
|
663 |
-
$phpmailer->oauthClientId = $options['oauth_client_id'];
|
664 |
|
665 |
-
|
666 |
-
$phpmailer->oauthClientSecret = $options['oauth_client_secret'];
|
667 |
|
668 |
-
|
|
|
669 |
|
670 |
-
|
671 |
-
|
672 |
-
|
673 |
-
|
674 |
-
|
675 |
-
|
676 |
-
|
677 |
-
|
678 |
-
|
679 |
-
|
680 |
-
|
681 |
-
|
682 |
-
|
683 |
-
|
684 |
-
|
685 |
-
|
686 |
-
|
687 |
-
|
688 |
-
|
689 |
-
|
690 |
-
|
691 |
-
|
692 |
-
|
693 |
-
|
694 |
-
|
695 |
-
|
696 |
-
|
697 |
-
|
698 |
-
|
699 |
-
|
700 |
-
|
701 |
-
|
702 |
-
|
703 |
-
|
704 |
-
|
705 |
-
|
706 |
-
|
707 |
-
|
708 |
-
|
709 |
-
|
710 |
-
|
711 |
-
|
712 |
-
|
713 |
-
|
714 |
-
|
715 |
-
|
716 |
-
|
717 |
-
|
718 |
-
|
719 |
-
|
720 |
-
|
721 |
-
|
722 |
-
|
723 |
-
|
724 |
-
|
725 |
-
|
726 |
-
|
727 |
-
|
728 |
-
|
729 |
-
|
730 |
-
|
731 |
-
|
732 |
-
|
733 |
-
|
734 |
-
|
735 |
-
|
736 |
-
|
737 |
-
|
738 |
-
|
739 |
-
|
740 |
-
|
741 |
-
|
742 |
-
|
743 |
-
|
744 |
-
|
745 |
-
|
746 |
-
|
747 |
-
|
748 |
-
|
749 |
-
|
750 |
-
|
751 |
-
|
752 |
-
|
753 |
-
|
754 |
-
|
755 |
-
|
756 |
-
|
757 |
-
|
758 |
-
|
759 |
-
|
760 |
-
|
761 |
-
|
762 |
-
|
763 |
-
|
764 |
-
|
765 |
-
|
766 |
-
|
767 |
-
|
768 |
-
|
769 |
-
|
770 |
-
|
771 |
-
|
772 |
-
|
773 |
-
|
774 |
-
|
775 |
-
|
776 |
-
|
777 |
-
|
778 |
-
|
779 |
-
|
780 |
-
|
781 |
-
|
782 |
-
|
783 |
-
|
784 |
-
|
785 |
-
|
786 |
-
|
787 |
-
|
788 |
-
|
789 |
-
|
790 |
-
|
791 |
-
|
792 |
-
|
793 |
-
|
794 |
-
|
795 |
-
|
796 |
-
|
797 |
-
|
798 |
-
|
799 |
-
|
800 |
-
|
801 |
-
|
802 |
-
|
803 |
-
|
804 |
-
|
805 |
-
|
806 |
-
|
807 |
-
|
808 |
-
|
809 |
-
|
810 |
-
|
811 |
-
|
812 |
-
|
813 |
-
|
814 |
-
|
815 |
-
|
816 |
-
|
817 |
-
|
818 |
-
|
819 |
-
|
820 |
-
|
821 |
-
|
822 |
-
|
823 |
-
|
824 |
-
|
825 |
-
|
826 |
-
|
827 |
-
|
828 |
-
|
829 |
-
|
830 |
-
|
831 |
-
|
832 |
-
|
833 |
-
|
834 |
-
|
835 |
-
|
836 |
-
|
837 |
-
|
838 |
-
|
839 |
-
|
840 |
-
|
841 |
-
|
842 |
-
|
843 |
-
|
844 |
-
|
845 |
-
|
846 |
-
|
847 |
-
|
848 |
-
|
849 |
-
|
850 |
-
|
851 |
-
|
852 |
-
|
853 |
-
|
854 |
-
|
855 |
-
|
856 |
-
|
857 |
-
|
858 |
-
|
859 |
-
|
860 |
-
|
861 |
-
|
862 |
-
|
863 |
-
|
864 |
-
|
865 |
-
|
866 |
-
|
867 |
-
|
868 |
-
|
869 |
-
|
870 |
-
|
871 |
-
|
872 |
-
|
873 |
-
|
874 |
-
|
875 |
-
|
876 |
-
|
877 |
-
|
878 |
-
|
879 |
-
|
880 |
-
|
881 |
-
|
882 |
-
|
883 |
-
|
884 |
-
|
885 |
-
|
886 |
-
|
887 |
-
|
888 |
-
|
889 |
-
|
890 |
-
|
891 |
-
|
892 |
-
|
893 |
-
|
894 |
-
|
895 |
-
|
896 |
-
|
897 |
-
|
898 |
-
|
899 |
-
|
900 |
-
|
901 |
-
|
902 |
-
|
903 |
-
|
904 |
-
|
905 |
-
|
906 |
-
|
907 |
-
|
908 |
-
|
909 |
-
|
910 |
-
|
911 |
-
|
912 |
-
|
913 |
-
|
914 |
-
|
915 |
-
|
916 |
-
|
917 |
-
|
918 |
-
|
919 |
-
|
920 |
-
|
921 |
-
|
922 |
-
|
923 |
-
|
924 |
-
|
925 |
-
|
926 |
-
|
927 |
-
|
928 |
-
|
929 |
-
|
930 |
-
|
931 |
-
|
932 |
-
|
933 |
-
|
934 |
-
|
935 |
-
|
936 |
-
|
937 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
938 |
}
|
1 |
<?php
|
2 |
/*
|
3 |
Plugin Name: Gmail SMTP
|
4 |
+
Version: 1.0.8
|
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.8';
|
20 |
var $phpmailer_version = '5.2.14';
|
21 |
var $plugin_url;
|
22 |
var $plugin_path;
|
578 |
$GLOBALS['gmail-smtp'] = new GMAIL_SMTP();
|
579 |
|
580 |
if(!function_exists('wp_mail') && is_gmail_smtp_configured()){
|
581 |
+
|
582 |
+
function wp_mail( $to, $subject, $message, $headers = '', $attachments = array() ) {
|
583 |
+
// Compact the input, apply the filters, and extract them back out
|
584 |
+
|
585 |
+
/**
|
586 |
+
* Filters the wp_mail() arguments.
|
587 |
+
*
|
588 |
+
* @since 2.2.0
|
589 |
+
*
|
590 |
+
* @param array $args A compacted array of wp_mail() arguments, including the "to" email,
|
591 |
+
* subject, message, headers, and attachments values.
|
592 |
+
*/
|
593 |
+
$atts = apply_filters( 'wp_mail', compact( 'to', 'subject', 'message', 'headers', 'attachments' ) );
|
594 |
+
|
595 |
+
if ( isset( $atts['to'] ) ) {
|
596 |
+
$to = $atts['to'];
|
597 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
598 |
|
599 |
+
if ( isset( $atts['subject'] ) ) {
|
600 |
+
$subject = $atts['subject'];
|
601 |
+
}
|
|
|
|
|
602 |
|
603 |
+
if ( isset( $atts['message'] ) ) {
|
604 |
+
$message = $atts['message'];
|
605 |
+
}
|
606 |
|
607 |
+
if ( isset( $atts['headers'] ) ) {
|
608 |
+
$headers = $atts['headers'];
|
609 |
+
}
|
610 |
|
611 |
+
if ( isset( $atts['attachments'] ) ) {
|
612 |
+
$attachments = $atts['attachments'];
|
613 |
+
}
|
614 |
|
615 |
+
if ( ! is_array( $attachments ) ) {
|
616 |
+
$attachments = explode( "\n", str_replace( "\r\n", "\n", $attachments ) );
|
617 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
618 |
|
619 |
+
$options = gmail_smtp_get_option();
|
|
|
620 |
|
621 |
+
$phpmailer = new PHPMailerOAuth; /* this must be the custom class we created */
|
|
|
622 |
|
623 |
+
// Tell PHPMailer to use SMTP
|
624 |
+
$phpmailer->isSMTP();
|
625 |
|
626 |
+
// Set AuthType
|
627 |
+
$phpmailer->AuthType = 'XOAUTH2';
|
628 |
+
|
629 |
+
// Whether to use SMTP authentication
|
630 |
+
$phpmailer->SMTPAuth = true;
|
631 |
+
|
632 |
+
// Set the encryption system to use - ssl (deprecated) or tls
|
633 |
+
$phpmailer->SMTPSecure = $options['type_of_encryption'];
|
634 |
+
|
635 |
+
// Set the hostname of the mail server
|
636 |
+
$phpmailer->Host = 'smtp.gmail.com';
|
637 |
+
|
638 |
+
// Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
|
639 |
+
$phpmailer->Port = $options['smtp_port'];
|
640 |
+
|
641 |
+
$phpmailer->SMTPAutoTLS = false;
|
642 |
+
|
643 |
+
//enable debug when sending a test mail
|
644 |
+
if(isset($_POST['gmail_smtp_send_test_email'])){
|
645 |
+
$phpmailer->SMTPDebug = 4;
|
646 |
+
// Ask for HTML-friendly debug output
|
647 |
+
$phpmailer->Debugoutput = 'html';
|
648 |
+
}
|
649 |
+
|
650 |
+
//disable ssl certificate verification if checked
|
651 |
+
if(isset($options['disable_ssl_verification']) && !empty($options['disable_ssl_verification'])){
|
652 |
+
$phpmailer->SMTPOptions = array(
|
653 |
+
'ssl' => array(
|
654 |
+
'verify_peer' => false,
|
655 |
+
'verify_peer_name' => false,
|
656 |
+
'allow_self_signed' => true
|
657 |
+
)
|
658 |
+
);
|
659 |
+
}
|
660 |
+
// User Email to use for SMTP authentication - Use the same Email used in Google Developer Console
|
661 |
+
$phpmailer->oauthUserEmail = $options['oauth_user_email'];
|
662 |
+
|
663 |
+
//Obtained From Google Developer Console
|
664 |
+
$phpmailer->oauthClientId = $options['oauth_client_id'];
|
665 |
+
|
666 |
+
//Obtained From Google Developer Console
|
667 |
+
$phpmailer->oauthClientSecret = $options['oauth_client_secret'];
|
668 |
+
|
669 |
+
$gmail_token = json_decode($options['oauth_access_token'], true);
|
670 |
+
|
671 |
+
//Obtained By running get_oauth_token.php after setting up APP in Google Developer Console.
|
672 |
+
//Set Redirect URI in Developer Console as [https/http]://<yourdomain>/<folder>/get_oauth_token.php
|
673 |
+
// eg: http://localhost/phpmail/get_oauth_token.php
|
674 |
+
$phpmailer->oauthRefreshToken = $gmail_token['refresh_token'];
|
675 |
+
|
676 |
+
// Headers
|
677 |
+
$cc = $bcc = $reply_to = array();
|
678 |
+
|
679 |
+
if ( empty( $headers ) ) {
|
680 |
+
$headers = array();
|
681 |
+
} else {
|
682 |
+
if ( !is_array( $headers ) ) {
|
683 |
+
// Explode the headers out, so this function can take both
|
684 |
+
// string headers and an array of headers.
|
685 |
+
$tempheaders = explode( "\n", str_replace( "\r\n", "\n", $headers ) );
|
686 |
+
} else {
|
687 |
+
$tempheaders = $headers;
|
688 |
+
}
|
689 |
+
$headers = array();
|
690 |
+
$cc = array();
|
691 |
+
$bcc = array();
|
692 |
+
|
693 |
+
// If it's actually got contents
|
694 |
+
if ( !empty( $tempheaders ) ) {
|
695 |
+
// Iterate through the raw headers
|
696 |
+
foreach ( (array) $tempheaders as $header ) {
|
697 |
+
if ( strpos($header, ':') === false ) {
|
698 |
+
if ( false !== stripos( $header, 'boundary=' ) ) {
|
699 |
+
$parts = preg_split('/boundary=/i', trim( $header ) );
|
700 |
+
$boundary = trim( str_replace( array( "'", '"' ), '', $parts[1] ) );
|
701 |
+
}
|
702 |
+
continue;
|
703 |
+
}
|
704 |
+
// Explode them out
|
705 |
+
list( $name, $content ) = explode( ':', trim( $header ), 2 );
|
706 |
+
|
707 |
+
// Cleanup crew
|
708 |
+
$name = trim( $name );
|
709 |
+
$content = trim( $content );
|
710 |
+
|
711 |
+
switch ( strtolower( $name ) ) {
|
712 |
+
// Mainly for legacy -- process a From: header if it's there
|
713 |
+
case 'from':
|
714 |
+
$bracket_pos = strpos( $content, '<' );
|
715 |
+
if ( $bracket_pos !== false ) {
|
716 |
+
// Text before the bracketed email is the "From" name.
|
717 |
+
if ( $bracket_pos > 0 ) {
|
718 |
+
$from_name = substr( $content, 0, $bracket_pos - 1 );
|
719 |
+
$from_name = str_replace( '"', '', $from_name );
|
720 |
+
$from_name = trim( $from_name );
|
721 |
+
}
|
722 |
+
|
723 |
+
$from_email = substr( $content, $bracket_pos + 1 );
|
724 |
+
$from_email = str_replace( '>', '', $from_email );
|
725 |
+
$from_email = trim( $from_email );
|
726 |
+
|
727 |
+
// Avoid setting an empty $from_email.
|
728 |
+
} elseif ( '' !== trim( $content ) ) {
|
729 |
+
$from_email = trim( $content );
|
730 |
+
}
|
731 |
+
break;
|
732 |
+
case 'content-type':
|
733 |
+
if ( strpos( $content, ';' ) !== false ) {
|
734 |
+
list( $type, $charset_content ) = explode( ';', $content );
|
735 |
+
$content_type = trim( $type );
|
736 |
+
if ( false !== stripos( $charset_content, 'charset=' ) ) {
|
737 |
+
$charset = trim( str_replace( array( 'charset=', '"' ), '', $charset_content ) );
|
738 |
+
} elseif ( false !== stripos( $charset_content, 'boundary=' ) ) {
|
739 |
+
$boundary = trim( str_replace( array( 'BOUNDARY=', 'boundary=', '"' ), '', $charset_content ) );
|
740 |
+
$charset = '';
|
741 |
+
}
|
742 |
+
|
743 |
+
// Avoid setting an empty $content_type.
|
744 |
+
} elseif ( '' !== trim( $content ) ) {
|
745 |
+
$content_type = trim( $content );
|
746 |
+
}
|
747 |
+
break;
|
748 |
+
case 'cc':
|
749 |
+
$cc = array_merge( (array) $cc, explode( ',', $content ) );
|
750 |
+
break;
|
751 |
+
case 'bcc':
|
752 |
+
$bcc = array_merge( (array) $bcc, explode( ',', $content ) );
|
753 |
+
break;
|
754 |
+
default:
|
755 |
+
// Add it to our grand headers array
|
756 |
+
$headers[trim( $name )] = trim( $content );
|
757 |
+
break;
|
758 |
+
}
|
759 |
+
}
|
760 |
+
}
|
761 |
+
}
|
762 |
+
|
763 |
+
// Empty out the values that may be set
|
764 |
+
$phpmailer->ClearAllRecipients();
|
765 |
+
$phpmailer->ClearAttachments();
|
766 |
+
$phpmailer->ClearCustomHeaders();
|
767 |
+
$phpmailer->ClearReplyTos();
|
768 |
+
|
769 |
+
// From email and name
|
770 |
+
// If we don't have a name from the input headers
|
771 |
+
if ( !isset( $from_name ) ){
|
772 |
+
$from_name = $options['from_name'];//'WordPress';
|
773 |
+
}
|
774 |
+
/* If we don't have an email from the input headers default to wordpress@$sitename
|
775 |
+
* Some hosts will block outgoing mail from this address if it doesn't exist but
|
776 |
+
* there's no easy alternative. Defaulting to admin_email might appear to be another
|
777 |
+
* option but some hosts may refuse to relay mail from an unknown domain. See
|
778 |
+
* https://core.trac.wordpress.org/ticket/5007.
|
779 |
+
*/
|
780 |
+
|
781 |
+
if ( !isset( $from_email ) ) {
|
782 |
+
// Get the site domain and get rid of www.
|
783 |
+
$sitename = strtolower( $_SERVER['SERVER_NAME'] );
|
784 |
+
if ( substr( $sitename, 0, 4 ) == 'www.' ) {
|
785 |
+
$sitename = substr( $sitename, 4 );
|
786 |
+
}
|
787 |
+
|
788 |
+
$from_email = $options['from_email'];//'wordpress@' . $sitename;
|
789 |
+
}
|
790 |
+
|
791 |
+
/**
|
792 |
+
* Filter the email address to send from.
|
793 |
+
*
|
794 |
+
* @since 2.2.0
|
795 |
+
*
|
796 |
+
* @param string $from_email Email address to send from.
|
797 |
+
*/
|
798 |
+
$phpmailer->From = apply_filters( 'wp_mail_from', $from_email );
|
799 |
+
|
800 |
+
/**
|
801 |
+
* Filter the name to associate with the "from" email address.
|
802 |
+
*
|
803 |
+
* @since 2.3.0
|
804 |
+
*
|
805 |
+
* @param string $from_name Name associated with the "from" email address.
|
806 |
+
*/
|
807 |
+
$phpmailer->FromName = apply_filters( 'wp_mail_from_name', $from_name );
|
808 |
+
|
809 |
+
// Set destination addresses
|
810 |
+
if ( !is_array( $to ) )
|
811 |
+
$to = explode( ',', $to );
|
812 |
+
|
813 |
+
foreach ( (array) $to as $recipient ) {
|
814 |
+
try {
|
815 |
+
// Break $recipient into name and address parts if in the format "Foo <bar@baz.com>"
|
816 |
+
$recipient_name = '';
|
817 |
+
if ( preg_match( '/(.*)<(.+)>/', $recipient, $matches ) ) {
|
818 |
+
if ( count( $matches ) == 3 ) {
|
819 |
+
$recipient_name = $matches[1];
|
820 |
+
$recipient = $matches[2];
|
821 |
+
}
|
822 |
+
}
|
823 |
+
$phpmailer->AddAddress( $recipient, $recipient_name);
|
824 |
+
} catch ( phpmailerException $e ) {
|
825 |
+
continue;
|
826 |
+
}
|
827 |
+
}
|
828 |
+
|
829 |
+
// Set mail's subject and body
|
830 |
+
$phpmailer->Subject = $subject;
|
831 |
+
$phpmailer->Body = $message;
|
832 |
+
|
833 |
+
// Add any CC and BCC recipients
|
834 |
+
if ( !empty( $cc ) ) {
|
835 |
+
foreach ( (array) $cc as $recipient ) {
|
836 |
+
try {
|
837 |
+
// Break $recipient into name and address parts if in the format "Foo <bar@baz.com>"
|
838 |
+
$recipient_name = '';
|
839 |
+
if ( preg_match( '/(.*)<(.+)>/', $recipient, $matches ) ) {
|
840 |
+
if ( count( $matches ) == 3 ) {
|
841 |
+
$recipient_name = $matches[1];
|
842 |
+
$recipient = $matches[2];
|
843 |
+
}
|
844 |
+
}
|
845 |
+
$phpmailer->AddCc( $recipient, $recipient_name );
|
846 |
+
} catch ( phpmailerException $e ) {
|
847 |
+
continue;
|
848 |
+
}
|
849 |
+
}
|
850 |
+
}
|
851 |
+
|
852 |
+
if ( !empty( $bcc ) ) {
|
853 |
+
foreach ( (array) $bcc as $recipient) {
|
854 |
+
try {
|
855 |
+
// Break $recipient into name and address parts if in the format "Foo <bar@baz.com>"
|
856 |
+
$recipient_name = '';
|
857 |
+
if ( preg_match( '/(.*)<(.+)>/', $recipient, $matches ) ) {
|
858 |
+
if ( count( $matches ) == 3 ) {
|
859 |
+
$recipient_name = $matches[1];
|
860 |
+
$recipient = $matches[2];
|
861 |
+
}
|
862 |
+
}
|
863 |
+
$phpmailer->AddBcc( $recipient, $recipient_name );
|
864 |
+
} catch ( phpmailerException $e ) {
|
865 |
+
continue;
|
866 |
+
}
|
867 |
+
}
|
868 |
+
}
|
869 |
+
|
870 |
+
// Set Content-Type and charset
|
871 |
+
// If we don't have a content-type from the input headers
|
872 |
+
if ( !isset( $content_type ) )
|
873 |
+
$content_type = 'text/plain';
|
874 |
+
|
875 |
+
/**
|
876 |
+
* Filter the wp_mail() content type.
|
877 |
+
*
|
878 |
+
* @since 2.3.0
|
879 |
+
*
|
880 |
+
* @param string $content_type Default wp_mail() content type.
|
881 |
+
*/
|
882 |
+
$content_type = apply_filters( 'wp_mail_content_type', $content_type );
|
883 |
+
|
884 |
+
$phpmailer->ContentType = $content_type;
|
885 |
+
|
886 |
+
// Set whether it's plaintext, depending on $content_type
|
887 |
+
if ( 'text/html' == $content_type )
|
888 |
+
$phpmailer->IsHTML( true );
|
889 |
+
|
890 |
+
// If we don't have a charset from the input headers
|
891 |
+
if ( !isset( $charset ) )
|
892 |
+
$charset = get_bloginfo( 'charset' );
|
893 |
+
|
894 |
+
// Set the content-type and charset
|
895 |
+
|
896 |
+
/**
|
897 |
+
* Filter the default wp_mail() charset.
|
898 |
+
*
|
899 |
+
* @since 2.3.0
|
900 |
+
*
|
901 |
+
* @param string $charset Default email charset.
|
902 |
+
*/
|
903 |
+
$phpmailer->CharSet = apply_filters( 'wp_mail_charset', $charset );
|
904 |
+
|
905 |
+
// Set custom headers
|
906 |
+
if ( !empty( $headers ) ) {
|
907 |
+
foreach( (array) $headers as $name => $content ) {
|
908 |
+
$phpmailer->AddCustomHeader( sprintf( '%1$s: %2$s', $name, $content ) );
|
909 |
+
}
|
910 |
+
|
911 |
+
if ( false !== stripos( $content_type, 'multipart' ) && ! empty($boundary) )
|
912 |
+
$phpmailer->AddCustomHeader( sprintf( "Content-Type: %s;\n\t boundary=\"%s\"", $content_type, $boundary ) );
|
913 |
+
}
|
914 |
+
|
915 |
+
if ( !empty( $attachments ) ) {
|
916 |
+
foreach ( $attachments as $attachment ) {
|
917 |
+
try {
|
918 |
+
$phpmailer->AddAttachment($attachment);
|
919 |
+
} catch ( phpmailerException $e ) {
|
920 |
+
continue;
|
921 |
+
}
|
922 |
+
}
|
923 |
+
}
|
924 |
+
|
925 |
+
/**
|
926 |
+
* Fires after PHPMailer is initialized.
|
927 |
+
*
|
928 |
+
* @since 2.2.0
|
929 |
+
*
|
930 |
+
* @param PHPMailer &$phpmailer The PHPMailer instance, passed by reference.
|
931 |
+
*/
|
932 |
+
//do_action_ref_array( 'phpmailer_init', array( &$phpmailer ) );
|
933 |
+
|
934 |
+
// Send!
|
935 |
+
try {
|
936 |
+
return $phpmailer->Send();
|
937 |
+
} catch ( phpmailerException $e ) {
|
938 |
+
|
939 |
+
$mail_error_data = compact( 'to', 'subject', 'message', 'headers', 'attachments' );
|
940 |
+
$mail_error_data['phpmailer_exception_code'] = $e->getCode();
|
941 |
+
|
942 |
+
/**
|
943 |
+
* Fires after a phpmailerException is caught.
|
944 |
+
*
|
945 |
+
* @since 4.4.0
|
946 |
+
*
|
947 |
+
* @param WP_Error $error A WP_Error object with the phpmailerException message, and an array
|
948 |
+
* containing the mail recipient, subject, message, headers, and attachments.
|
949 |
+
*/
|
950 |
+
do_action( 'wp_mail_failed', new WP_Error( 'wp_mail_failed', $e->getMessage(), $mail_error_data ) );
|
951 |
+
|
952 |
+
return false;
|
953 |
+
}
|
954 |
+
}
|
955 |
}
|
readme.txt
CHANGED
@@ -2,9 +2,9 @@
|
|
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.
|
6 |
Tested up to: 4.7
|
7 |
-
Stable tag: 1.0.
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
@@ -102,6 +102,9 @@ none
|
|
102 |
|
103 |
== Changelog ==
|
104 |
|
|
|
|
|
|
|
105 |
= 1.0.7 =
|
106 |
* Added more requirements to the Server Info tab to help with troubleshooting.
|
107 |
* Compatible with WooCommerce email in HTML format.
|
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.7
|
6 |
Tested up to: 4.7
|
7 |
+
Stable tag: 1.0.8
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
102 |
|
103 |
== Changelog ==
|
104 |
|
105 |
+
= 1.0.8 =
|
106 |
+
* Gmail SMTP now supports the "wp_mail_failed" hook which fires after a phpmailerException is caught.
|
107 |
+
|
108 |
= 1.0.7 =
|
109 |
* Added more requirements to the Server Info tab to help with troubleshooting.
|
110 |
* Compatible with WooCommerce email in HTML format.
|