Quantcast
Channel: Raz-Soft » [ En ]
Viewing all articles
Browse latest Browse all 35

PHP email subject encoding

$
0
0
If you thought that setting “Content-Type” will suffice to make your email just send away without problems, think again. The specified character encoding in “Content-Type” will only describe the character encoding of the body, not the subject itself. If the subject contains UTF-8 chars your email subject will not look as expected on the recipient. To fix this issue you will need to use the encoded-word syntax (RFC2047#section-2) with either the quoted-printable encoding or the Base64 encoding. Here is a quick snippet on how I did it: 1234if (strlen($subject) != strlen(utf8_decode($subject))) //check if subject is utf-8        fwrite($socket, 'Subject: =?UTF-8?B?'.base64_encode(html_entity_decode(utf8_encode($subject), ENT_COMPAT, "UTF-8"))."?="."\r\n".'To: <'.implode('>, <', $recipients).'>'."\r\n".$headers."\r\n\r\n".$message."\r\n");  else        fwrite($socket, 'Subject: '.$subject."\r\n".'To: <'.implode('>, <', $recipients).'>'."\r\n".$headers."\r\n\r\n".$message."\r\n"); This syntax uses a string of ASCII characters indicating both the original char encoding and the content-transfer-encoding used to map the bytes of the charset into ASCII characters. The syntax is: “=?charset?encoding?encoded text?=”. As you can see above I’m trying to see if …

read more


Viewing all articles
Browse latest Browse all 35

Latest Images

Trending Articles





Latest Images