While working with IMAP email headers in PHP , I encountered an issue which is related to encoding of subject line. When I am try mb_decode_mimeheader
(as per the duplicate issue) then I am not getting desired result:
$subject = "=?UTF-8?Q?=e2=99=a3?= Your winning day =?UTF-8?Q?=e2=99=a3?=";
echo mb_decode_mimeheader($subject);
Output:
? Your winning day ?
To fix the example in the comments:
mb_internal_encoding('UTF-8');
$subject = "=?UTF-8?Q?=e2=99=a3?= Your winning day =?UTF-8?Q?=e2=99=a3?=";
echo mb_decode_mimeheader($subject);
Outputs "♣ Your winning day ♣".
It's undocumented that mb_internal_encoding
influences the operation of mb_decode_mimeheader
, but it does. mb_internal_encoding
is taken as the target charset that should be returned from mb_decode_mimeheader
. If that's set to Latin-1, then characters like "♣" cannot be decoded into this target charset and will fail.
You may want to look at imap_utf8
for a less finicky function.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With