我的PHP脚本向用户发送电子邮件,当电子邮件到达其邮箱时,主题行($subject
)包含a^£
添加到主题文本末尾的字符.这显然是编码问题.电子邮件内容本身很好,只是主题行被打破.
我已经搜遍了所有,但无法找到如何正确编码我的主题.
这是我的标题.请注意,我使用Content-Type
同charset=utf-8
和 Content-Transfer-Encoding: 8bit
.
//set all necessary headers
$headers = "From: $sender_name<$from>\n";
$headers .= "Reply-To: $sender_name<$from>\n";
$headers .= "X-Sender: $sender_name<$from>\n";
$headers .= "X-Mailer: PHP4\n"; //mailer
$headers .= "X-Priority: 3\n"; //1 UrgentMessage, 3 Normal
$headers .= "MIME-Version: 1.0\n";
$headers .= "X-MSMail-Priority: High\n";
$headers .= "Importance: 3\n";
$headers .= "Date: $date\n";
$headers .= "Delivered-to: $to\n";
$headers .= "Return-Path: $sender_name<$from>\n";
$headers .= "Envelope-from: $sender_name<$from>\n";
$headers .= "Content-Transfer-Encoding: 8bit\n";
$headers .= "Content-Type: …
Run Code Online (Sandbox Code Playgroud) 当我尝试从PHP发送HTML编码的电子邮件时,如果主题行包含特殊字符"Here's the information you requested"
,则PHP将其编码为读取"Here's the information you requested."
我该如何解决?
以下是使用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);
Run Code Online (Sandbox Code Playgroud)
它提供了与通过SugarPHPMailer类运行它相同的错误.
我正在使用PHP的邮件功能发送带有阿拉伯语内容的电子邮件.假设我有这个简单的阿拉伯字符串:
بريد
我已经尝试了几种方法来使用标题,但是电子邮件内容仍然最终会出现以下内容:X*X1X(X1Y X/
.但是,如果我使用阿拉伯字符,电子邮件主题将被正确编码(感谢base64_encode,请参阅下面的函数)
这是我尝试过的电子邮件功能之一
function sendSimpleMail($to,$from,$subject,$message) {
$headers = 'MIME-Version: 1.0' ."\r\n";
$headers .= 'To: '.$to ."\r\n";
$headers .= 'From: '.$from . "\r\n";
$headers .= 'Content-type: text/plain; charset=UTF-8; format=flowed' . "\r\n";
$headers .= 'Content-Transfer-Encoding: 8bit'."\r\n";
mail($to, '=?UTF-8?B?'.base64_encode($subject).'?=',$message, $headers);
}
Run Code Online (Sandbox Code Playgroud)
关于实现这一目标的替代方法的任何建议?