php utf-8 emails with national characters
Here are the details:
(1) php code is used to send an html message.
(2) the message contains Hebrew characters.
(3) when the message is received at the other end (a gmail account) by an auto parser, all the Hebrew characters appear as question marks and the parser fails.
(4) when the message is sent to any other destination (also gmail), being opened and then forwarded to the parser, the Hebrew chars are correctly received and parsed.
(5) when the message is auto-forwarded from other email accounts to the parser, the Hebrew chars appear as question marks again.
Relevant part of the PHP code:
$headers = "From: $from\r\n";
$headers .= "Content-type: text/html\r\n";
// $message is an html code with Hebrew content.
mail($to, $subject, $message, $headers);
as per RFC 1555:
Have tried also the following headers:
$headers = "From: $from\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=ISO-8859-8\r\n";
$headers .= "Content-transfer-encoding: BASE64 | Quoted-Printable\r\n";
and also with the following conversion:
mail($to, $subject, iconv("UTF-8", "ISO-8859-8//TRANSLIT", $message), $headers);
2 Replies
$headers = "From: $from\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=UTF-8\r\n";
$headers .= "Content-Transfer-Encoding: 8bit\r\n";
Note that the 8bit transfer encoding is specified. This will keep the non-ASCII characters from being munged. If the path the mail traverses over the Internet is not 8-bit clean, the mailservers should be able to automatically convert the body to quoted-printable or base64. If this doesn't work, you could wrap a call to quotedprintableencode() around $message and use Content-Transfer-Encoding: quoted-printable\r\n instead.
In the HTML $message, it would be a good idea to include a line
in the head section. This tells the parser what character set to expect, since the file may already be separated from the mail headers.