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