PHP邮件编码主题行 [英] PHP Mail Encodes Subject Line

查看:86
本文介绍了PHP邮件编码主题行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试从PHP发送HTML编码的电子邮件时,如果主题行包含特殊字符,例如这是您请求的信息,PHP将其编码为这里和#039是您要求的信息。



我该如何解决?




这是代码如何使用PHP邮件():

  $ headers ='MIME-Version:1.0'。 \r\\\
;
$ headers。='Content-type:text / html; charset = iso-8859-1'。 \r\\\
;

$ headers。='至:'。 $ mod_params ['name']。 '<'。 $ mod_params ['email']。 '>'。 \r\\\
;

$ headers。='From:< do_not_reply@a4isp.com>'。 \r\\\
;

$ email_to = $ mod_params ['email'];

$ email_sub =以下是您要求的信息;

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

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

它通过SugarPHPMailer类运行它同样的错误。

解决方案

尝试这样:

  $ newsubject ='=? UTF-8 B = '? BASE64_ENCODE($主题)。'?; 

这样你就不用依靠PHP或MTA的编码,你做这个工作,邮件客户端应该了解它。您的新主题不会出现特殊字符,因此在发送电子邮件时不会出现问题。


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&#039;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' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

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

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

$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.

解决方案

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.

这篇关于PHP邮件编码主题行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆