From 848a32947801185818e15ec52d3fac7f7087433e Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Sat, 14 Sep 2019 20:13:37 +0000 Subject: [PATCH] Mail: Avoid setting duplicate `MIME-Version` and `X-Mailer` headers in `wp_mail()`, they are added automatically by PHPMailer. Props lbenicio, junktrunk, danieltj, studyboi, bennemann. Fixes #43542. git-svn-id: https://develop.svn.wordpress.org/trunk@46115 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/pluggable.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/wp-includes/pluggable.php b/src/wp-includes/pluggable.php index 9336e03c7e..835a0d6df3 100644 --- a/src/wp-includes/pluggable.php +++ b/src/wp-includes/pluggable.php @@ -450,10 +450,13 @@ if ( ! function_exists( 'wp_mail' ) ) : */ $phpmailer->CharSet = apply_filters( 'wp_mail_charset', $charset ); - // Set custom headers + // Set custom headers. if ( ! empty( $headers ) ) { foreach ( (array) $headers as $name => $content ) { - $phpmailer->addCustomHeader( sprintf( '%1$s: %2$s', $name, $content ) ); + // Only add custom headers not added automatically by PHPMailer. + if ( ! in_array( $name, array( 'MIME-Version', 'X-Mailer') ) ) { + $phpmailer->addCustomHeader( sprintf( '%1$s: %2$s', $name, $content ) ); + } } if ( false !== stripos( $content_type, 'multipart' ) && ! empty( $boundary ) ) {