Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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);

mail($to, '=?UTF-8?B?'.base64_encode($subject).'?=', $text, $headers, ''); 

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?

share|improve this question
If it is only your VPS provider who is seeing the incorrect name, but the rest of the world gets it, seems like the problem may lie with them. But if they are just seeing a malformed name, is the problem a big one? – dunxd Dec 24 '10 at 10:23

The message text can be any character set you define (because you define the character set for the mail in the mail header (content-type = utf8), but the headers (subject, from - name, email) are defined in the client that is reading the email, so you can't affect that. Gmail is using utf8 as the default, while other clients that are viewing the emails can use anything they like and basically only ASCII characters are fully supported everywhere.

Edit: You can have characters outside US-ASCII in the message header if they are MIME encoded ("=?charset?encoding?encoded text?=")

share|improve this answer
I just saw you are doing this with the Subject field, but not the From field. – Jure1873 Feb 26 '12 at 15:07

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 $headers.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.