Symfony Mailer / Mime 8.0: UTF-8 Subject gets corrupted (C3 B6 → C3 3F) during header encoding

2 days ago 2
ARTICLE AD BOX

I am seeing what looks like UTF-8 corruption in the Subject header when using Symfony Mailer / Mime 8.0.x with PHP 8.4.

Symptoms:
Umlauts and other multibyte characters are partially replaced with ? in the encoded Subject header (e.g. ö → =?utf-8?Q?=C3=3F?=), even though the input string is valid UTF-8 and the message object contains the correct data before header encoding.

Environment

PHP: 8.4.x

Symfony Mailer: 8.0.3

Symfony Mime: 8.0.x

Transport: SMTP

mb_internal_encoding() = UTF-8

default_charset = UTF-8

mb_substitute_character() = 63 (?)

Input data (verified UTF-8)

Hex dumps of the subject parts before calling $message->subject():

db heading: 45697365726b756368656e202d2057616666656c68c3b6726e6368656e206d6974205361686e65 "Eiserkuchen - Waffelhörnchen mit Sahne" piece (heading + emoji): 45697365726b756368656e202d2057616666656c68c3b6726e6368656e206d6974205361686e6520f09f8db420 "... Waffelhörnchen mit Sahne 🍴"

Second heading:

db heading: 506cc3a4747a6368656e2d52657374652d4b756368656e3a2052657a657074207a757220506cc3a4747a6368656e76657277657274756e67 "Plätzchen-Reste-Kuchen: Rezept zur Plätzchenverwertung"

Final subject before setting it on the message:

subject before set: 45697365726b756368656e202d2057616666656c68c3b6726e6368656e206d6974205361686e6520f09f8db420506cc3a4747a6368656e2d52657374652d4b756368656e3a2052657a657074207a757220506cc3a4747a6368656e76657277657274756e67

This is valid UTF-8 (c3 b6, c3 a4, emoji f0 9f 8d b4).


Resulting encoded Subject header

After calling:

$message->subject($subject);

Symfony produces:

Subject: Eiserkuchen - =?utf-8?Q?Waffelh=C3=3Frnchen?= mit Sahne =?utf-8?Q?=F0=9F=8D=B4=3FPl=C3=3Ftzchen-Reste-K?= =?utf-8?Q?uchen=3A?= Rezept zur =?utf-8?Q?Pl=C3=3Ftzchenverwertuntzchenverwertung?=

Notice that:

C3 B6 → C3 3F

C3 A4 → C3 3F

Only the UTF-8 continuation bytes (0x80–0xBF) are replaced by ?.

Observations

The message object contains correct UTF-8 before header encoding.

Email::toString() shows the same corrupted encoded header.

Increasing header line length (setMaxLineLength(998)) does not change the behavior.

Forcing RFC-2047 Base64 (B) encoding manually works correctly:

$encoded = '=?UTF-8?B?' . base64_encode($subject) . '?='; $headers->remove('Subject'); $headers->addTextHeader('Subject', $encoded);

Question

Is this a known issue or regression in Symfony Mime 8.0.x when Q-encoding unstructured headers with multibyte UTF-8 characters (especially emojis + umlauts)?

Or am I missing a required configuration / usage pattern for Email::subject() in Symfony 8?

Any guidance or confirmation would be appreciated before filing a formal bug report.

Read Entire Article