PHP, SMTP - Subject in the letter shows international characters as HTML_Entities

I spent more than half a day on this - just trying to get an email message that looks normal. But international characters appear as HTML_Entities when a mailbox ends up in your inbox.

For example: Tydzień o Jedność

Shows how: Tydzień o Jedność

I am already encoding an email subject for UTF-8:

$this->subject = "=?UTF-8?B?" . base64_encode($this->subject) . "?=";

When I receive an email (Gmail), the header displays as:

Subject: =?UTF-8?B?VHlkemllJiMzMjQ7IG8gSmVkbm8mIzM0NzsmIzI2Mzs=?=

So, it is encoded correctly. But for some reason, Gmail still displays the subject with HTML_Entities.

Any ideas?

See code: SMTP mail class

+3
source share
3 answers

$this->subject UTF-8? UTF-8 .php( )?

:

$this->subject = "=?UTF-8?B?" . base64_encode(html_entity_decode($this->subject, ENT_COMPAT, 'UTF-8')) . "?=";
+2

,

$this->subject = mb_encode_mimeheader($this->subject);

Tydzień o Jedność,

=?UTF-8?B?VHlkemllw4XChCBvIEplZG5vw4XCm8OEwoc=?=

, , , HTML:

echo mb_decode_mimeheader('=?UTF-8?B?VHlkemllJiMzMjQ7IG8gSmVkbm8mIzM0NzsmIzI2Mzs=?=');

Tydzień o Jedność. , HTML , base64.

+2

, iconv_mime_encode() "=?UTF-8?B?" . base64_encode($this->subject) . "?=";

+1

Source: https://habr.com/ru/post/1786198/


All Articles