3

I am using the following code to send email to members of my site. The script works and the email is recieved by the user. But, I do encounter encoding problems when emailing to Hotmail or Notes.

The code:

$to       = "to@email.com";
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/plain; charset="utf-8"; format="flowed"' . "\r\n";
$headers .= 'Content-Transfer-Encoding: 8bit'. "\n\r\n";
$headers .= "To: John Doe<john@doe.com>" . "\r\n" . 
"From: John Smith<john@smith.com" . "\r\n" .
"Reply-To: john@doe.com" . "\r\n" .
"Return-Path: john@doe.com" . "\r\n" .
"Sender: john@doe.com" . "\r\n" .
"X-Sender: john@doe.com" . "\r\n" .
"X-Mailer: JohnDoe". "\r\n".
"X-Report-Abuse: Please report abuse to: john@doe.com";

//If the e-mail was successfully sent...
$subject = $translation[104];
if(mail($to, $subject, $message, $headers)){

}

Both the message and the subject contains the swedish letters Å, Ä and Ö. The actual message is correctly encoded and viewed in Hotmail, while the subject is not. You can view the image below for more information:

Image: http://www.aspkoll.se/imgo/649

I am confused. I've googled for days and tried different kind of solutions, but without any success I am afraid.

Can you please help me with this problem?

Appreciated!

Shubbi
  • 107
  • 1
  • 2
  • 6
  • 1
    possible duplicate of [How to send mail with binary word in mail subject using PHP](http://stackoverflow.com/questions/1450846/how-to-send-mail-with-binary-word-in-mail-subject-using-php) – Steve-o Aug 25 '11 at 12:48
  • You cannot have non-ASCII in a mail header. It’s against The Rules. – tchrist Aug 25 '11 at 12:55

2 Answers2

6

Email subjects, and other header content, such as names, are encoded using RFC 2047

php.net comments on mail() give the following example:

mail($mail, "=?utf-8?B?".base64_encode ($subject)."?=", $message, $headers);
Steve-o
  • 12,678
  • 2
  • 41
  • 60
-1

Try http://www.phpclasses.org/browse/file/919.html. It works for Yahoo mail, Gmail, Hotmail.

P.S.: Hotmail sucks. :)

Akos
  • 1,997
  • 6
  • 27
  • 40