PHP无法发送UTF-8的消息
我有以下的PHP代码:PHP无法发送UTF-8的消息
<?php $to = '[email protected]';
$subject = date("d/m/Y");
$message = 'Hey 123 [email protected]# αβγ';
$headers = "From: testsite <[email protected]>\n";
$headers .= "Cc: testsite <[email protected]>\n";
$headers .= "X-Sender: testsite <[email protected]>\n";
$headers .= 'X-Mailer: PHP/' . phpversion();
$headers .= "X-Priority: 1\n"; // Urgent message!
$headers .= "Return-Path: [email protected]\n"; // Return path for errors
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=iso-8859-1\n";
mail($to,$subject,$message,$headers);
echo "<script type='text/javascript'>alert('Message sent! We will get back to you soon!');</script>";
echo "<script>window.location.href = 'http://example.com';</script>";
?>
邮件被发送罚款。问题是αβγ
(Unicode字符)没有正确收到邮件收件人的结尾。
这是收件人看到的是:Hey 123 [email protected]# αβγ
这是他应该明白:Hey 123 [email protected]# αβγ
我到处找用尽一切方法,改变标题,将我的字符串为Unicode等等等等,但什么事都没有工作。也许我做错了什么?
回答:
使用UTF-8
字符集标题,例如:
$headers .= "Content-Type: text/html; charset=iso-8859-1\n";
业大:
$headers .= "Content-Type: text/html; charset=UTF-8\n";
以上是 PHP无法发送UTF-8的消息 的全部内容, 来源链接: utcz.com/qa/266501.html