The problem I had was that email with French subject was sent with no subject. Because subject field is one part of header in email, accented characters in header seemed to cause problem.
First attempt to fix this problem was to encode the subject field in unicode as below but the issue persisted.
[code language=”PHP”]
$subject = iconv(‘UTF-8’, ‘ISO-8859-1’, $subject);
$subject = utf8_encode($subject);
[/code]
Second attempt was to strip out unseen unicodes or other codes as below but it displayed only ASCII part of the subject or displayed ? or other characters.
[code language=”PHP”]
// 7 bit ASCII
$subject = preg_replace(‘/[\x00-\x1F\x7F-\xFF]/’, ”, $subject);
// 8 bit extended ASCII
$subject = preg_replace(‘/[\x00-\x1F\x7F]/’, ”, $subject);
// UTF-8
$subject = preg_replace(‘/[\x00-\x1F\x7F]/u’, ”, $subject);
//$subject = iconv(‘UTF-8’, ‘ASCII//TRANSLIT//IGNORE’, $subject);
//$subject = iconv(‘UTF-8’, ‘ASCII//TRANSLIT’, $subject);
[/code]
The last attempt was to encode it into unicode and base64. Then, send subject field with header escape codes stating that the field is encoded in utf-8 and base64. Since it is a pure text format, it did not interfere a header was displayed as it was in French.
[code language=”PHP”]
$subject = stripslashes($subject);
$subject = utf8_encode($subject);
$subject = ‘=?UTF-8?B?’.base64_encode($subject).’?=’;
[/code]
Source code as below is another attempts to resolve the issue. They were not sucessful
[code language=”PHP”]
//$subject = htmlentities($subject);
//$subject = html_entity_decode($subject);
//$subject = iconv(‘UTF-8’, ‘ISO-8859-1’, $subject);
[/code]