I’m using a function for sending UTF8 emails.
Since at least one recipient has issues with emails sent by my function (not UTF8, so special chars broken; some mail headers appear in body), I’m wondering if I have to put another line break at the end of the header string:
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";
$header_ .= "From: my@mail.com"; //Should be optional...
if (!empty($header)) $header_ .= "\r\n".$header;
$out = mail($to, '=?UTF-8?B?'.base64_encode($subject).'?=', $message, $header_);
return $out;
}
So what’s correct – mail_utf8("x@y.z", "", "blah", "") or mail_utf8("x@y.z", "", "blah", "\r\n")?
Edit: The obvious resource for that kind of matter – http://www.php.net/mail – uses such a line break only in example #4, unlike in #2.
Edit2: So here’s the current version. See comments for further info.
function mail_utf8($to, $subject = "(No subject)", $message = "", $header = "")
{
$linebreak = PHP_EOL; //Seems to work everywhere, including IncrediMail
$linebreak = "\n"; //Debug
$header_ = 'MIME-Version: 1.0'.$linebreak.'Content-type: text/plain; charset=UTF-8'.$linebreak;
$header_ .= "From: my@mail.com".$linebreak;
if (!empty($header)) $header_ .= $header.$linebreak; //Last line break !?
$out = mail($to, '=?UTF-8?B?'.base64_encode($subject).'?=', $message, $header_);
return $out;
}
Try terminating each header line with just
\n, instead of\r\n.Source: PHP
mail()Function