Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
858 views
in Technique[技术] by (71.8m points)

email - send mail from php - charset encoding

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

 $headers  = "MIME-Version: 1.0
";
$headers .= "Content-type: text/plain; charset=utf-8
";
$headers .= "From: [email protected]
";
$headers .= "Reply-To: [email protected]
";
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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...