[wp-trac] [WordPress Trac] #15448: wp_mail() sets Content-Type header twice for multipart emails
WordPress Trac
noreply at wordpress.org
Wed Jun 25 20:36:44 UTC 2025
#15448: wp_mail() sets Content-Type header twice for multipart emails
-------------------------------------------------+-------------------------
Reporter: rmccue | Owner:
| SergeyBiryukov
Type: feature request | Status: reviewing
Priority: normal | Milestone: Future
| Release
Component: Mail | Version:
Severity: normal | Resolution:
Keywords: has-patch has-unit-tests has-test- | Focuses:
info |
-------------------------------------------------+-------------------------
Changes (by SirLouen):
* keywords: gci has-patch westi-likes needs-testing has-unit-tests => has-
patch has-unit-tests has-test-info
* type: enhancement => feature request
Comment:
== Combined Reproduction and Patch Test Report
=== Description
🟠 This report can't validate that the issue can be fully reproduced,
Patch tested: https://github.com/WordPress/wordpress-
develop/pull/9063.diff
=== Environment
- WordPress: 6.9-alpha-60093-src
- PHP: 8.2.28
- Server: nginx/1.27.5
- Database: mysqli (Server: 8.4.5 / Client: mysqlnd 8.2.28)
- Browser: Chrome 137.0.0.0
- OS: Windows 10/11
- Theme: Twenty Twenty-One 2.5
- MU Plugins: None activated
- Plugins:
* Multipart Email Sender 1.0.0
* Test Reports 1.2.0
* WP_Mail Setup 1.0.0
=== Reproduction Setup
1. Setup the email server, in my case, my PR 8555 with `wordpress-develop`
and Mailhog
2. Setup in WP the connection with PHPMailer to the local server
3. Add the code below anywhere where it can be executed (including wp-
load.php and executing such function)
4. ❌ The email is received, but no trace of two `multipart` sections as
reported
5. 🐞 The email is not multipart by default, this is the real problem.
=== Expected Results
- A multipart/alternative email, hence one side Plain Text and the other
side, HTML
=== Actual Results with the Patch
1. ✅ The patch works correctly.
=== Additional Comments
I've been playing around with the last patch with my refresh
Also reading through the whole post and stumbled into the
[http://wordpress.stackexchange.com/questions/191923/sending-multipart-
text-html-emails-via-wp-mail-will-likely-get-your-domain-b WP Stack
Exchange topic].
The thing is that using the provided code in the WP SE topic
{{{
Content-Type: multipart/alternative; charset=
Date: Wed, 25 Jun 2025 20:13:36 +0000
From: Foo <foo at bar.com>
MIME-Version: 1.0
Message-ID: <QisEmVtRxTD2dTUEwnWxR2FyFGEYjvJhaaykSKl0 at localhost>
Received: from localhost by mailhog.example (MailHog)
id xLmoK23xx_Mp7ymSnM-PsnFPgWVR4czzoTFUatwetos=@mailhog.example;
Wed, 25 Jun 2025 20:13:36 +0000
Return-Path: <foo at bar.com>
Subject: wp_mail testing multipart
To: YourEmail at hotmail.com
X-Mailer: PHPMailer 6.9.3 (https://github.com/PHPMailer/PHPMailer)
------=_Part_18243133_1346573420.1408991447668
Content-Type: text/plain; charset=UTF-8
Hello world! This is plain text...
------=_Part_18243133_1346573420.1408991447668
Content-Type: text/html; charset=UTF-8
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"
/>
</head>
<body>
<p>Hello World! This is HTML...</p>
</body>
</html>
------=_Part_18243133_1346573420.1408991447668--
}}}
This is the source of the sent email (and received mail in Mailhog)
{{{
Content-Type: multipart/alternative; charset=
Date: Wed, 25 Jun 2025 20:13:36 +0000
From: Foo <foo at bar.com>
MIME-Version: 1.0
Message-ID: <QisEmVtRxTD2dTUEwnWxR2FyFGEYjvJhaaykSKl0 at localhost>
Received: from localhost by mailhog.example (MailHog)
id xLmoK23xx_Mp7ymSnM-PsnFPgWVR4czzoTFUatwetos=@mailhog.example;
Wed, 25 Jun 2025 20:13:36 +0000
Return-Path: <foo at bar.com>
Subject: wp_mail testing multipart
To: YourEmail at hotmail.com
X-Mailer: PHPMailer 6.9.3 (https://github.com/PHPMailer/PHPMailer)
------=_Part_18243133_1346573420.1408991447668
Content-Type: text/plain; charset=UTF-8
Hello world! This is plain text...
------=_Part_18243133_1346573420.1408991447668
Content-Type: text/html; charset=UTF-8
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"
/>
</head>
<body>
<p>Hello World! This is HTML...</p>
</body>
</html>
------=_Part_18243133_1346573420.1408991447668--
}}}
True is, that there is no multiparted received mail as reported: it's just
a regular plain text email.
On the other side I can't see that "double" multipart thing:
{{{
Content-Type: multipart/alternative;
boundary="example_boundary"
Content-Type: multipart/alternative; charset=""
}}}
That some reporters have been commenting in the early days, like @rmccue
and @christinecooper
They were talking about Outlook, Hotmail, … I wonder if these clients
added this section or something because I can't really see this in the
Original content in Mailhog. Or maybe the latest versions of PHPMailer
have sorted this out.
If any of the reporters could throw more light on this "double" multipart
section, it would be great.
Furthermore, I can comment, that the workaround with `$phpmailer->AltBody`
is definitely working well before the patch.
`needs-code-review`
This is just a testing report. I've also reviewed the patch, and looks
good. I've also fixed the Unit Tests to fit to the current PHPUnit
formatting we are using.
But before taking a final conclusion, I need to dig a bit more into the
behaviour of PHPMailer. Many users, including @dd32 and some in the post
of Stack Exchange, have reported that PHPMailer is the culprit in this
history.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/15448#comment:69>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list