How can I send an email formatted as "Name <user@example.com>
" to:
ŠŒŽœžŸ¥µÀÁÃÄÅÆÇÉÊËÍÎÏÐÒÓÕÖØÙÜÝßàáâåæçèéëìíîïðñóôõöøùûýÿ <user@example.com>
Obviously, many of these characters will never show up in a name, but in case they do, I would prefer that they do not prevent an email from being successfully sent.
Currently, this fails as noted in Apache's error.log with
Ignoring invalid 'To:' recipient address '¥µÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýÿ ' Transaction aborted: no recipients specified
If possible, I would like to keep the special characters 'as they are.' Otherwise, can I use some sort of transliteration function to clean-up the name?
Example of usage:
<?php
$to = "ŠŒŽšœžŸ¥µÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýÿ <CHANGED@gmail.com>";
$subject = "Test Subject";
$body = "Test Body";
if (mail($to, $subject, $body)) {
echo("<p>Message successfully sent!</p>");
} else {
echo("<p>Message delivery failed...</p>");
}
?>
RFC-821 (2821) tells us, that all and any 8bit-data in headers field must be encoded. Base64 or QuotedPrintable, as you want and can. Most e-mail readers automatically decode encoded strings
mb_encode_mimeheader
should do it, just as shown in the example:For better compatibility you should set the header
Mime-Version: 1.0
so all mail clients understand you're using MIME encoding.The final email headers should look like this:
Renders as:
Related: https://stackoverflow.com/a/13569317/476