3

I am sending an automated mail,written in Greek, from a php script. I tried:

 $headers  = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/plain; charset=utf-8\r\n";
$headers .= "From: example@mail.com\r\n";
$headers .= "Reply-To: example@mail.com\r\n";
mail($to, $subject,$body, $headers) ;

The body and subject are in Greek. Hotmail is reading subject but not the body and gmail reads it well. I replaced utf-8 with iso-8859-7 (contains greek chars) and it works . 1) Any idea why it doesn't work with utf-8? 2) Also gmail is writing my server in the mail.. How can i prevent this from happening?

casperOne
  • 73,706
  • 19
  • 184
  • 253
user666
  • 834
  • 2
  • 10
  • 20

1 Answers1

3

All email headers, which includes the subject, need to be pure ASCII, you cannot use UTF-8 or other encodings directly in email headers. Some mail services may be able to detect other encodings and do the right thing, but it's not technically valid. Encode your headers using MIME encoding, see How to use special characters in recipients name when using PHP's mail function.

Community
  • 1
  • 1
deceze
  • 510,633
  • 85
  • 743
  • 889
  • You may need to understand this also, when you use `mb_internal_encoding()` http://stackoverflow.com/questions/7501924/php-messing-with-html-charset-encoding/7502564#7502564 – Diblo Dk Dec 28 '11 at 15:17