Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

email - PHP Mail Encodes Subject Line

When I try to send a HTML encoded email from PHP, if the subject line contains special chars like "Here's the information you requested", PHP encodes it to read "Here's the information you requested."

How do I fix this?


Here's what the code looks like using PHP mail():

$headers  = 'MIME-Version: 1.0' . "
";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "
";

$headers .= 'To: ' . $mod_params['name'] . '<' . $mod_params['email'] . '>' . "
";

$headers .= 'From: <do_not_reply@a4isp.com>' . "
";  

$email_to = $mod_params['email'];

$email_sub = "Here's the Information You Requested";

$body = html_entity_decode("<html><body>" . $email_html_body . "</body></html>");

mail($email_to,$email_sub,$body,$headers);

It gives the same error as running it through the SugarPHPMailer class.

See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

Try this:

 $newsubject='=?UTF-8?B?'.base64_encode($subject).'?=';

This way you don't rely on PHP or the MTA's encoding, you do the job, and the mail client should understand it. No special characters will be present in your new subject, so no problems should arise while delivering the email.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...