I've received a report that a mail sent with CMSimple_XH's built-in mailform contained garbage in the message body. It seems to be related to the MTA, which either had needed a Content-Transfer-Encoding header or had problems with 8-bit characters. I've sent the following fix back to the user, and this worked fine. In cmsimple/mailform.php:
Code: Select all
function mail_utf8($to, $subject = '(No Subject)', $message = '', $header = '')
{
$header = 'MIME-Version: 1.0' . "\r\n"
. 'Content-Type: text/plain; charset=UTF-8' . "\r\n"
. 'Content-Transfer-Encoding: base64' . "\r\n"
. $header;
$subject = '=?UTF-8?B?'
. base64_encode(utf8_substr($subject, 0, 45)) . '?=';
// word wrap the message giving preference to already existing line breaks
$message = strtr(rtrim($message), array("\r\n" => "\n", "\r" => "\n"));
$lines = explode("\n", $message);
array_walk($lines,
create_function('&$v, $i',
'$v = utf8_wordwrap($v, 72, "\n", true);'));
$message = implode("\r\n", $lines);
$message = chunk_split(base64_encode($message));
return mail($to, $subject, $message, $header);
}
The drawback: this base64 encoding has an overhead of about 35%. The alternative quoted-printable would have nearly no overhead for typical mails in English, estimated 10% for German, up to 500% for Russian and more than 1000% for several Asian languages. Additionally PHP offers a function to encode quoted-printable only since PHP 5.3.
I suggest that we include the bugfix in CMSimple_XH 1.5.6.
Christoph
PS: The amount of overhead given above is nonsense The overhead of base64 encoding is indeed about 35%. The overhead of quoted-printable is 200% in the worst case (texts that doesn't contain printable ASCII characters) , as each byte outside the ASCII range is encoded with 3 bytes.