I use Postfix as a mailserver.
I have Ubuntu OS.
Then I use PHP to send emails.
Problem is that none of my emails are encoded properly by a mailsoftware which my VPS provider uses.
According to them, the problem lies with me.
It is only the name field which isn’t encoded properly. For example “Björn” becomes “BjÃ¶rn” in my emails.
However, when I echo the
$name, it outputs “Björn” which is correct.
Also, gmail and hotmail does show it correctly.
The strange part is that the “text” (the message itself) is encoded properly.
I use the following for sending mail:
$headers="MIME-Version: 1.0"."\n"; $headers.="Content-type: text/plain; charset=UTF-8"."\n"; $headers.="From: $name <$email>"."\n"; $name= iconv(mb_detect_encoding($name), "UTF-8//IGNORE//TRANSLIT", $name); //// I HAVE TRIED WITH AND WITHOUT THE LINE ABOVE, NO DIFFERENCE mail($to, '=?UTF-8?B?'.base64_encode($subject).'?=', $text, $headers, '-firstname.lastname@example.org');
I have tried with and without the iconv line also, no luck.
The last thing I can think of is POSTFIX, could there be a setting for character encoding there? Anybody knows?
One problem I see is that you’ve converted
$name to UTF-8 after embedding it in the
$headers. So what’s getting sent to postfix is whatever was in there before. You should
iconv() it and add the MIME encoding to it before adding it into
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.