Ticket #15448: 15448_Sept2015.diff
File 15448_Sept2015.diff, 5.1 KB (added by , 9 years ago) |
---|
-
src/wp-includes/pluggable.php
211 211 * However, you can set the content type of the email by using the 212 212 * 'wp_mail_content_type' filter. 213 213 * 214 * If $message is an array, the key of each is used to add as an attachment 215 * with the value used as the body. The 'text/plain' element is used as the 216 * text version of the body, with the 'text/html' element used as the HTML 217 * version of the body. All other types are added as attachments. 218 * 214 219 * The default charset is based on the charset used on the blog. The charset can 215 220 * be set using the 'wp_mail_charset' filter. 216 221 * … … 220 225 * 221 226 * @param string|array $to Array or comma-separated list of email addresses to send message. 222 227 * @param string $subject Email subject 223 * @param string 228 * @param string|array $message Message contents 224 229 * @param string|array $headers Optional. Additional headers. 225 230 * @param string|array $attachments Optional. Files to attach. 226 231 * @return bool Whether the email contents were sent successfully. … … 325 330 } 326 331 break; 327 332 case 'content-type': 333 if ( is_array($message) ) { 334 // Multipart email, ignore the content-type header 335 break; 336 } 328 337 if ( strpos( $content, ';' ) !== false ) { 329 338 list( $type, $charset_content ) = explode( ';', $content ); 330 339 $content_type = trim( $type ); … … 361 370 $phpmailer->ClearCustomHeaders(); 362 371 $phpmailer->ClearReplyTos(); 363 372 373 $phpmailer->Body= ''; 374 $phpmailer->AltBody= ''; 375 364 376 // From email and name 365 377 // If we don't have a name from the input headers 366 378 if ( !isset( $from_name ) ) … … 421 433 } 422 434 } 423 435 436 // If we don't have a charset from the input headers 437 if ( !isset( $charset ) ) 438 $charset = get_bloginfo( 'charset' ); 439 440 // Set the content-type and charset 441 442 /** 443 * Filter the default wp_mail() charset. 444 * 445 * @since 2.3.0 446 * 447 * @param string $charset Default email charset. 448 */ 449 $phpmailer->CharSet = apply_filters( 'wp_mail_charset', $charset ); 450 424 451 // Set mail's subject and body 425 452 $phpmailer->Subject = $subject; 426 $phpmailer->Body = $message;427 453 454 if ( is_string($message) ) { 455 $phpmailer->Body = $message; 456 457 // Set Content-Type and charset 458 // If we don't have a content-type from the input headers 459 if ( !isset( $content_type ) ) 460 $content_type = 'text/plain'; 461 462 /** 463 * Filter the wp_mail() content type. 464 * 465 * @since 2.3.0 466 * 467 * @param string $content_type Default wp_mail() content type. 468 */ 469 $content_type = apply_filters( 'wp_mail_content_type', $content_type ); 470 471 $phpmailer->ContentType = $content_type; 472 473 // Set whether it's plaintext, depending on $content_type 474 if ( 'text/html' == $content_type ) 475 $phpmailer->IsHTML( true ); 476 477 // For backwards compatibility, new multipart emails should use 478 // the array style $message. This never really worked well anyway 479 if ( false !== stripos( $content_type, 'multipart' ) && ! empty($boundary) ) 480 $phpmailer->AddCustomHeader( sprintf( "Content-Type: %s;\n\t boundary=\"%s\"", $content_type, $boundary ) ); 481 } 482 elseif ( is_array($message) ) { 483 foreach ($message as $type => $bodies) { 484 foreach ((array) $bodies as $body) { 485 if ($type === 'text/html') { 486 $phpmailer->Body = $body; 487 } 488 elseif ($type === 'text/plain') { 489 $phpmailer->AltBody = $body; 490 } 491 else { 492 $phpmailer->AddAttachment($body, '', 'base64', $type); 493 } 494 } 495 } 496 } 497 428 498 // Add any CC and BCC recipients 429 499 if ( !empty( $cc ) ) { 430 500 foreach ( (array) $cc as $recipient ) { … … 465 535 // Set to use PHP's mail() 466 536 $phpmailer->IsMail(); 467 537 468 // Set Content-Type and charset469 // If we don't have a content-type from the input headers470 if ( !isset( $content_type ) )471 $content_type = 'text/plain';472 473 /**474 * Filter the wp_mail() content type.475 *476 * @since 2.3.0477 *478 * @param string $content_type Default wp_mail() content type.479 */480 $content_type = apply_filters( 'wp_mail_content_type', $content_type );481 482 $phpmailer->ContentType = $content_type;483 484 // Set whether it's plaintext, depending on $content_type485 if ( 'text/html' == $content_type )486 $phpmailer->IsHTML( true );487 488 // If we don't have a charset from the input headers489 if ( !isset( $charset ) )490 $charset = get_bloginfo( 'charset' );491 492 // Set the content-type and charset493 494 /**495 * Filter the default wp_mail() charset.496 *497 * @since 2.3.0498 *499 * @param string $charset Default email charset.500 */501 $phpmailer->CharSet = apply_filters( 'wp_mail_charset', $charset );502 503 538 // Set custom headers 504 539 if ( !empty( $headers ) ) { 505 540 foreach ( (array) $headers as $name => $content ) { 506 541 $phpmailer->AddCustomHeader( sprintf( '%1$s: %2$s', $name, $content ) ); 507 542 } 508 509 if ( false !== stripos( $content_type, 'multipart' ) && ! empty($boundary) )510 $phpmailer->AddCustomHeader( sprintf( "Content-Type: %s;\n\t boundary=\"%s\"", $content_type, $boundary ) );511 543 } 512 544 513 545 if ( !empty( $attachments ) ) {