1

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, '-fnoreply@domain.com'); 

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?

1
  • 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, 2010 at 10:23

2 Answers 2

2

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?=")

1
  • I just saw you are doing this with the Subject field, but not the From field.
    – Jure1873
    Feb 26, 2012 at 15:07
2

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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