diff --git src/bp-core/classes/class-bp-phpmailer.php src/bp-core/classes/class-bp-phpmailer.php
index ab0b3e14e..76b24395d 100644
|
|
class BP_PHPMailer implements BP_Email_Delivery { |
26 | 26 | */ |
27 | 27 | public function bp_email( BP_Email $email ) { |
28 | 28 | static $phpmailer = null; |
| 29 | $phpmailer_is_6_0 = false; |
29 | 30 | |
30 | 31 | /** |
31 | 32 | * Filter PHPMailer object to use. |
… |
… |
class BP_PHPMailer implements BP_Email_Delivery { |
38 | 39 | */ |
39 | 40 | $phpmailer = apply_filters( 'bp_phpmailer_object', $phpmailer ); |
40 | 41 | |
41 | | if ( ! ( $phpmailer instanceof PHPMailer ) ) { |
42 | | if ( ! class_exists( 'PHPMailer' ) ) { |
43 | | require_once ABSPATH . WPINC . '/class-phpmailer.php'; |
44 | | require_once ABSPATH . WPINC . '/class-smtp.php'; |
| 42 | /** |
| 43 | * WordPress 5.5 deprecated version 5.2 of PHPMailer |
| 44 | * and is now using version 6.0 of PHPMailer. |
| 45 | */ |
| 46 | if ( file_exists( ABSPATH . WPINC . '/PHPMailer/PHPMailer.php' ) ) { |
| 47 | if ( ! ( $phpmailer instanceof PHPMailer\PHPMailer\PHPMailer ) ) { |
| 48 | if ( ! class_exists( 'PHPMailer\\PHPMailer\\PHPMailer' ) ) { |
| 49 | require_once ABSPATH . WPINC . '/PHPMailer/PHPMailer.php'; |
| 50 | require_once ABSPATH . WPINC . '/PHPMailer/SMTP.php'; |
| 51 | require_once ABSPATH . WPINC . '/PHPMailer/Exception.php'; |
| 52 | } |
| 53 | |
| 54 | $phpmailer = new PHPMailer\PHPMailer\PHPMailer( true ); |
| 55 | $phpmailer_is_6_0 = true; |
45 | 56 | } |
| 57 | } else { |
| 58 | if ( ! ( $phpmailer instanceof PHPMailer ) ) { |
| 59 | if ( ! class_exists( 'PHPMailer' ) ) { |
| 60 | require_once ABSPATH . WPINC . '/class-phpmailer.php'; |
| 61 | require_once ABSPATH . WPINC . '/class-smtp.php'; |
| 62 | } |
46 | 63 | |
47 | | $phpmailer = new PHPMailer( true ); |
| 64 | $phpmailer = new PHPMailer( true ); |
| 65 | } |
48 | 66 | } |
49 | 67 | |
50 | | |
51 | 68 | /* |
52 | 69 | * Resets. |
53 | 70 | */ |
… |
… |
class BP_PHPMailer implements BP_Email_Delivery { |
58 | 75 | $phpmailer->clearReplyTos(); |
59 | 76 | $phpmailer->Sender = ''; |
60 | 77 | |
61 | | |
62 | 78 | /* |
63 | 79 | * Set up. |
64 | 80 | */ |
65 | | |
66 | 81 | $phpmailer->IsMail(); |
67 | 82 | $phpmailer->CharSet = bp_get_option( 'blog_charset' ); |
68 | 83 | |
69 | | |
70 | 84 | /* |
71 | 85 | * Content. |
72 | 86 | */ |
73 | | |
74 | 87 | $phpmailer->Subject = $email->get_subject( 'replace-tokens' ); |
75 | | $content_plaintext = PHPMailer::normalizeBreaks( $email->get_content_plaintext( 'replace-tokens' ) ); |
| 88 | if ( $phpmailer_is_6_0 ) { |
| 89 | $content_plaintext = PHPMailer\PHPMailer\PHPMailer::normalizeBreaks( $email->get_content_plaintext( 'replace-tokens' ) ); |
| 90 | } else { |
| 91 | $content_plaintext = PHPMailer::normalizeBreaks( $email->get_content_plaintext( 'replace-tokens' ) ); |
| 92 | } |
76 | 93 | |
77 | 94 | if ( $email->get( 'content_type' ) === 'html' ) { |
78 | 95 | $phpmailer->msgHTML( $email->get_template( 'add-content' ) ); |
… |
… |
class BP_PHPMailer implements BP_Email_Delivery { |
84 | 101 | } |
85 | 102 | |
86 | 103 | $recipient = $email->get_from(); |
87 | | try { |
88 | | $phpmailer->SetFrom( $recipient->get_address(), $recipient->get_name(), false ); |
89 | | } catch ( phpmailerException $e ) { |
| 104 | if ( $phpmailer_is_6_0 ) { |
| 105 | try { |
| 106 | $phpmailer->setFrom( $recipient->get_address(), $recipient->get_name(), false ); |
| 107 | } catch ( PHPMailer\PHPMailer\Exception $e ) { |
| 108 | } |
| 109 | } else { |
| 110 | try { |
| 111 | $phpmailer->SetFrom( $recipient->get_address(), $recipient->get_name(), false ); |
| 112 | } catch ( phpmailerException $e ) { |
| 113 | } |
90 | 114 | } |
91 | 115 | |
92 | 116 | $recipient = $email->get_reply_to(); |
93 | | try { |
94 | | $phpmailer->addReplyTo( $recipient->get_address(), $recipient->get_name() ); |
95 | | } catch ( phpmailerException $e ) { |
| 117 | if ( $phpmailer_is_6_0 ) { |
| 118 | try { |
| 119 | $phpmailer->addReplyTo( $recipient->get_address(), $recipient->get_name() ); |
| 120 | } catch ( PHPMailer\PHPMailer\Exception $e ) { |
| 121 | } |
| 122 | } else { |
| 123 | try { |
| 124 | $phpmailer->addReplyTo( $recipient->get_address(), $recipient->get_name() ); |
| 125 | } catch ( phpmailerException $e ) { |
| 126 | } |
96 | 127 | } |
97 | 128 | |
98 | 129 | $recipients = $email->get_to(); |
99 | | foreach ( $recipients as $recipient ) { |
100 | | try { |
101 | | $phpmailer->AddAddress( $recipient->get_address(), $recipient->get_name() ); |
102 | | } catch ( phpmailerException $e ) { |
| 130 | if ( $phpmailer_is_6_0 ) { |
| 131 | foreach ( $recipients as $recipient ) { |
| 132 | try { |
| 133 | $phpmailer->AddAddress( $recipient->get_address(), $recipient->get_name() ); |
| 134 | } catch ( PHPMailer\PHPMailer\Exception $e ) { |
| 135 | } |
| 136 | } |
| 137 | } else { |
| 138 | foreach ( $recipients as $recipient ) { |
| 139 | try { |
| 140 | $phpmailer->AddAddress( $recipient->get_address(), $recipient->get_name() ); |
| 141 | } catch ( phpmailerException $e ) { |
| 142 | } |
103 | 143 | } |
104 | 144 | } |
105 | 145 | |
106 | 146 | $recipients = $email->get_cc(); |
107 | | foreach ( $recipients as $recipient ) { |
108 | | try { |
109 | | $phpmailer->AddCc( $recipient->get_address(), $recipient->get_name() ); |
110 | | } catch ( phpmailerException $e ) { |
| 147 | if ( $phpmailer_is_6_0 ) { |
| 148 | foreach ( $recipients as $recipient ) { |
| 149 | try { |
| 150 | $phpmailer->AddCc( $recipient->get_address(), $recipient->get_name() ); |
| 151 | } catch ( PHPMailer\PHPMailer\Exception $e ) { |
| 152 | } |
| 153 | } |
| 154 | } else { |
| 155 | foreach ( $recipients as $recipient ) { |
| 156 | try { |
| 157 | $phpmailer->AddCc( $recipient->get_address(), $recipient->get_name() ); |
| 158 | } catch ( phpmailerException $e ) { |
| 159 | } |
111 | 160 | } |
112 | 161 | } |
113 | 162 | |
114 | 163 | $recipients = $email->get_bcc(); |
115 | | foreach ( $recipients as $recipient ) { |
116 | | try { |
117 | | $phpmailer->AddBcc( $recipient->get_address(), $recipient->get_name() ); |
118 | | } catch ( phpmailerException $e ) { |
| 164 | if ( $phpmailer_is_6_0 ) { |
| 165 | foreach ( $recipients as $recipient ) { |
| 166 | try { |
| 167 | $phpmailer->AddBcc( $recipient->get_address(), $recipient->get_name() ); |
| 168 | } catch ( PHPMailer\PHPMailer\Exception $e ) { |
| 169 | } |
| 170 | } |
| 171 | } else { |
| 172 | foreach ( $recipients as $recipient ) { |
| 173 | try { |
| 174 | $phpmailer->AddBcc( $recipient->get_address(), $recipient->get_name() ); |
| 175 | } catch ( phpmailerException $e ) { |
| 176 | } |
119 | 177 | } |
120 | 178 | } |
121 | 179 | |
… |
… |
class BP_PHPMailer implements BP_Email_Delivery { |
124 | 182 | $phpmailer->AddCustomHeader( $name, $content ); |
125 | 183 | } |
126 | 184 | |
127 | | |
128 | 185 | /** |
129 | 186 | * Fires after PHPMailer is initialised. |
130 | 187 | * |
… |
… |
class BP_PHPMailer implements BP_Email_Delivery { |
137 | 194 | /** This filter is documented in wp-includes/pluggable.php */ |
138 | 195 | do_action_ref_array( 'phpmailer_init', array( &$phpmailer ) ); |
139 | 196 | |
140 | | try { |
141 | | return $phpmailer->Send(); |
142 | | } catch ( phpmailerException $e ) { |
143 | | return new WP_Error( $e->getCode(), $e->getMessage(), $email ); |
| 197 | if ( $phpmailer_is_6_0 ) { |
| 198 | try { |
| 199 | return $phpmailer->Send(); |
| 200 | } catch ( PHPMailer\PHPMailer\Exception $e ) { |
| 201 | return new WP_Error( $e->getCode(), $e->getMessage(), $email ); |
| 202 | } |
| 203 | } else { |
| 204 | try { |
| 205 | return $phpmailer->Send(); |
| 206 | } catch ( phpmailerException $e ) { |
| 207 | return new WP_Error( $e->getCode(), $e->getMessage(), $email ); |
| 208 | } |
144 | 209 | } |
145 | 210 | } |
146 | 211 | |
147 | | |
148 | 212 | /* |
149 | 213 | * Utility/helper functions. |
150 | 214 | */ |