templates
1 year ago
SendinblueAccount.php
1 year ago
SendinblueApiClient.php
1 year ago
function.wp_mail.php
8 years ago
http-build-url.php
1 year ago
index.php
8 years ago
mailin.php
3 years ago
push-admin.php
1 year ago
push-amp.php
1 year ago
push-api.php
1 year ago
push-httpclient.php
1 year ago
push-public.php
1 year ago
push-settings.php
1 year ago
push-utils.php
1 year ago
push-woocommerce.php
1 year 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 |