From 59fa3389799efa54a77dc71f25805f2a9289b447 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Tue, 11 Nov 2025 02:36:35 +0000 Subject: [PATCH] Mail: Improve multipart message handling in `wp_mail()`. This improves how `wp_mail()` handles `Content-Type` headers for multipart messages, preventing cases where the header could be duplicated. Developed in https://github.com/WordPress/wordpress-develop/pull/9500 Props SirLouen, gitlost, rmccue, westi, MattyRob, bgermann, nacin, SergeyBiryukov, dd32, MikeHansenMe, Kleor, kitchin, JeffMatson, abcd95, westonruter, christinecooper, JohnVieth, dawidadach, imokweb, ayeshrajans, lakshyajeet, tusharbharti, sajjad67. Fixes #15448. Built from https://develop.svn.wordpress.org/trunk@61201 git-svn-id: http://core.svn.wordpress.org/trunk@60537 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/pluggable.php | 8 ++++---- wp-includes/version.php | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/wp-includes/pluggable.php b/wp-includes/pluggable.php index 0c61a6f7e1..ca85a85e4e 100644 --- a/wp-includes/pluggable.php +++ b/wp-includes/pluggable.php @@ -174,6 +174,7 @@ if ( ! function_exists( 'wp_mail' ) ) : * @since 5.5.0 is_email() is used for email validation, * instead of PHPMailer's default validator. * @since 6.9.0 Added $embeds parameter. + * @since 6.9.0 Improved Content-Type header handling for multipart messages. * * @global PHPMailer\PHPMailer\PHPMailer $phpmailer * @@ -351,6 +352,9 @@ if ( ! function_exists( 'wp_mail' ) ) : } elseif ( false !== stripos( $charset_content, 'boundary=' ) ) { $boundary = trim( str_replace( array( 'BOUNDARY=', 'boundary=', '"' ), '', $charset_content ) ); $charset = ''; + if ( preg_match( '~^multipart/(\S+)~', $content_type, $matches ) ) { + $content_type = 'multipart/' . strtolower( $matches[1] ) . '; boundary="' . $boundary . '"'; + } } // Avoid setting an empty $content_type. @@ -547,10 +551,6 @@ if ( ! function_exists( 'wp_mail' ) ) : } } } - - if ( false !== stripos( $content_type, 'multipart' ) && ! empty( $boundary ) ) { - $phpmailer->addCustomHeader( sprintf( 'Content-Type: %s; boundary="%s"', $content_type, $boundary ) ); - } } if ( ! empty( $attachments ) ) { diff --git a/wp-includes/version.php b/wp-includes/version.php index 8c36d21d70..7bfd8a2350 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.9-beta4-61200'; +$wp_version = '6.9-beta4-61201'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.