PluginProbe ʕ •ᴥ•ʔ
Brevo – Email, SMS, Web Push, Chat, and more. / 3.1.87
Brevo – Email, SMS, Web Push, Chat, and more. v3.1.87
2.9.13 2.9.14 2.9.15 2.9.16 2.9.17 2.9.18 2.9.4 2.9.5 2.9.6 2.9.7 2.9.8 2.9.9 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.9 3.1.0 3.1.1 3.1.10 3.1.11 3.1.12 3.1.13 3.1.14 3.1.15 3.1.16 3.1.2 3.1.20 3.1.21 3.1.22 3.1.23 3.1.24 3.1.25 3.1.26 3.1.27 3.1.28 3.1.29 3.1.3 3.1.30 3.1.31 3.1.32 3.1.33 3.1.34 3.1.35 3.1.36 3.1.37 3.1.38 3.1.39 3.1.4 3.1.40 3.1.41 3.1.42 3.1.43 3.1.44 3.1.45 3.1.46 3.1.47 3.1.48 3.1.49 3.1.5 3.1.50 3.1.51 3.1.52 3.1.53 3.1.54 3.1.55 3.1.56 3.1.57 3.1.58 3.1.59 3.1.6 3.1.60 3.1.61 3.1.62 3.1.63 3.1.64 3.1.65 3.1.66 3.1.67 3.1.68 3.1.69 3.1.7 3.1.70 3.1.71 3.1.72 3.1.73 3.1.74 3.1.75 3.1.76 3.1.77 3.1.78 3.1.79 3.1.8 3.1.80 3.1.81 3.1.82 3.1.83 3.1.84 3.1.85 3.1.86 3.1.87 3.1.88 3.1.89 3.1.9 3.1.90 3.1.91 3.1.92 3.1.93 3.1.94 3.1.95 3.1.96 3.1.97 3.1.98 3.2.0 3.2.1 3.2.2 3.2.3 3.2.4 3.2.5 3.2.6 3.2.7 3.2.8 3.2.9 3.3.0 3.3.1 3.3.2 3.3.3 3.3.4 3.3.5 trunk 1.0 1.5 2.0.8 2.9.10 2.9.11 2.9.12
mailin / inc / function.wp_mail.php
mailin / inc Last commit date
templates 1 year ago SendinblueAccount.php 5 years ago SendinblueApiClient.php 1 year ago function.wp_mail.php 8 years ago index.php 8 years ago mailin.php 3 years ago sendinblue.php 3 years ago sib-api-manager.php 1 year ago sib-form-preview.php 2 years ago sib-sms-code.php 3 years ago table-forms.php 1 year ago
function.wp_mail.php
250 lines
1 <?php
2 // Compact the input, apply the filters, and extract them back out
3 extract( apply_filters( 'wp_mail', compact( 'to', 'subject', 'message', 'headers', 'attachments' ) ) );
4
5 if ( ! is_array( $attachments ) ) {
6 $attachments = explode( "\n", str_replace( "\r\n", "\n", $attachments ) );
7 }
8
9 global $phpmailer;
10
11 // (Re)create it, if it's gone missing
12 if ( ! is_object( $phpmailer ) || ! is_a( $phpmailer, 'PHPMailer' ) ) {
13 require_once ABSPATH . WPINC . '/class-phpmailer.php';
14 require_once ABSPATH . WPINC . '/class-smtp.php';
15 $phpmailer = new PHPMailer( true );
16 }
17
18 // Headers
19 if ( empty( $headers ) ) {
20 $headers = array();
21 } else {
22 if ( ! is_array( $headers ) ) {
23 // Explode the headers out, so this function can take both
24 // string headers and an array of headers.
25 $tempheaders = explode( "\n", str_replace( "\r\n", "\n", $headers ) );
26 } else {
27 $tempheaders = $headers;
28 }
29 $headers = array();
30 $cc = array();
31 $bcc = array();
32
33 // If it's actually got contents
34 if ( ! empty( $tempheaders ) ) {
35 // Iterate through the raw headers
36 foreach ( (array) $tempheaders as $header ) {
37 if ( strpos( $header, ':' ) === false ) {
38 if ( false !== stripos( $header, 'boundary=' ) ) {
39 $parts = preg_split( '/boundary=/i', trim( $header ) );
40 $boundary = trim( str_replace( array( "'", '"' ), '', $parts[1] ) );
41 }
42 continue;
43 }
44 // Explode them out
45 list( $name, $content ) = explode( ':', trim( $header ), 2 );
46
47 // Cleanup crew
48 $name = trim( $name );
49 $content = trim( $content );
50
51 switch ( strtolower( $name ) ) {
52 // Mainly for legacy -- process a From: header if it's there
53 case 'from':
54 if ( strpos( $content, '<' ) !== false ) {
55 // So... making my life hard again?
56 $from_name = substr( $content, 0, strpos( $content, '<' ) - 1 );
57 $from_name = str_replace( '"', '', $from_name );
58 $from_name = trim( $from_name );
59
60 $from_email = substr( $content, strpos( $content, '<' ) + 1 );
61 $from_email = str_replace( '>', '', $from_email );
62 $from_email = trim( $from_email );
63 } else {
64 $from_email = trim( $content );
65 }
66 break;
67 case 'content-type':
68 if ( strpos( $content, ';' ) !== false ) {
69 list( $type, $charset ) = explode( ';', $content );
70 $content_type = trim( $type );
71 if ( false !== stripos( $charset, 'charset=' ) ) {
72 $charset = trim( str_replace( array( 'charset=', '"' ), '', $charset ) );
73 } elseif ( false !== stripos( $charset, 'boundary=' ) ) {
74 $boundary = trim( str_replace( array( 'BOUNDARY=', 'boundary=', '"' ), '', $charset ) );
75 $charset = '';
76 }
77 } else {
78 $content_type = trim( $content );
79 }
80 break;
81 case 'cc':
82 $cc = array_merge( (array) $cc, explode( ',', $content ) );
83 break;
84 case 'bcc':
85 $bcc = array_merge( (array) $bcc, explode( ',', $content ) );
86 break;
87 default:
88 // Add it to our grand headers array
89 $headers[ trim( $name ) ] = trim( $content );
90 break;
91 }
92 }
93 }
94 }
95
96 // Empty out the values that may be set
97 $phpmailer->ClearAddresses();
98 $phpmailer->ClearAllRecipients();
99 $phpmailer->ClearAttachments();
100 $phpmailer->ClearBCCs();/* $phpmailer->ClearCCs(); $phpmailer->ClearCustomHeaders(); $phpmailer->ClearReplyTos(); */
101
102 // From email and name
103 // If we don't have a name from the input headers
104 if ( ! isset( $from_name ) ) {
105 $from_name = 'WordPress';
106 }
107
108 /*
109 If we don't have an email from the input headers default to wordpress@$sitename
110 * Some hosts will block outgoing mail from this address if it doesn't exist but
111 * there's no easy alternative. Defaulting to admin_email might appear to be another
112 * option but some hosts may refuse to relay mail from an unknown domain. See
113 * http://trac.wordpress.org/ticket/5007.
114 */
115
116 if ( ! isset( $from_email ) ) {
117 // Get the site domain and get rid of www.
118 $sitename = strtolower( $_SERVER['SERVER_NAME'] );
119 if ( substr( $sitename, 0, 4 ) == 'www.' ) {
120 $sitename = substr( $sitename, 4 );
121 }
122
123 $from_email = 'wordpress@' . $sitename;
124 }
125
126 // Plugin authors can override the potentially troublesome default
127 $phpmailer->From = apply_filters( 'wp_mail_from' , $from_email );
128 $phpmailer->FromName = apply_filters( 'wp_mail_from_name', $from_name );
129
130 // Set destination addresses
131 if ( ! is_array( $to ) ) {
132 $to = explode( ',', $to );
133 }
134
135 foreach ( (array) $to as $recipient ) {
136 try {
137 // Break $recipient into name and address parts if in the format "Foo <bar@baz.com>"
138 $recipient_name = '';
139 if ( preg_match( '/(.*)<(.+)>/', $recipient, $matches ) ) {
140 if ( count( $matches ) == 3 ) {
141 $recipient_name = $matches[1];
142 $recipient = $matches[2];
143 }
144 }
145 $phpmailer->AddAddress( $recipient, $recipient_name );
146 } catch ( phpmailerException $e ) {
147 continue;
148 }
149 }
150
151 // Set mail's subject and body
152 $phpmailer->Subject = $subject;
153 $phpmailer->Body = $message;
154
155 // Add any CC and BCC recipients
156 if ( ! empty( $cc ) ) {
157 foreach ( (array) $cc as $recipient ) {
158 try {
159 // Break $recipient into name and address parts if in the format "Foo <bar@baz.com>"
160 $recipient_name = '';
161 if ( preg_match( '/(.*)<(.+)>/', $recipient, $matches ) ) {
162 if ( count( $matches ) == 3 ) {
163 $recipient_name = $matches[1];
164 $recipient = $matches[2];
165 }
166 }
167 $phpmailer->AddCc( $recipient, $recipient_name );
168 } catch ( phpmailerException $e ) {
169 continue;
170 }
171 }
172 }
173
174 if ( ! empty( $bcc ) ) {
175 foreach ( (array) $bcc as $recipient ) {
176 try {
177 // Break $recipient into name and address parts if in the format "Foo <bar@baz.com>"
178 $recipient_name = '';
179 if ( preg_match( '/(.*)<(.+)>/', $recipient, $matches ) ) {
180 if ( count( $matches ) == 3 ) {
181 $recipient_name = $matches[1];
182 $recipient = $matches[2];
183 }
184 }
185 $phpmailer->AddBcc( $recipient, $recipient_name );
186 } catch ( phpmailerException $e ) {
187 continue;
188 }
189 }
190 }
191
192 // Set to use PHP's mail()
193 $phpmailer->IsMail();
194
195 // Set Content-Type and charset
196 // If we don't have a content-type from the input headers
197 if ( ! isset( $content_type ) ) {
198 $content_type = 'text/plain';
199 }
200
201 $content_type = apply_filters( 'wp_mail_content_type', $content_type );
202
203 $phpmailer->ContentType = $content_type;
204
205 // Set whether it's plaintext, depending on $content_type
206 if ( 'text/html' == $content_type ) {
207 $phpmailer->IsHTML( true );
208 }
209
210 // If we don't have a charset from the input headers
211 if ( ! isset( $charset ) ) {
212 $charset = get_bloginfo( 'charset' );
213 }
214
215 // Set the content-type and charset
216 $phpmailer->CharSet = apply_filters( 'wp_mail_charset', $charset );
217
218 // Set custom headers
219 if ( ! empty( $headers ) ) {
220 foreach ( (array) $headers as $name => $content ) {
221 $phpmailer->AddCustomHeader( sprintf( '%1$s: %2$s', $name, $content ) );
222 }
223
224 if ( false !== stripos( $content_type, 'multipart' ) && ! empty( $boundary ) ) {
225 $phpmailer->AddCustomHeader( sprintf( "Content-Type: %s;\n\t boundary=\"%s\"", $content_type, $boundary ) );
226 }
227 }
228
229 if ( ! empty( $attachments ) ) {
230 foreach ( $attachments as $attachment ) {
231 try {
232 $phpmailer->AddAttachment( $attachment );
233 } catch ( phpmailerException $e ) {
234 continue;
235 }
236 }
237 }
238
239 do_action_ref_array( 'phpmailer_init', array( &$phpmailer ) );
240
241 // Send!
242 try {
243 $phpmailer->Send();
244 } catch ( phpmailerException $e ) {
245 return false;
246 }
247
248 return true;
249
250