我正在尝试用 PHP 创建电子邮件,但在构建标头时遇到问题。
我希望From是 admin@example.com,其他标头设置如下所示。
问题是,当我发送这封电子邮件时,电子邮件客户端中的“发件人”部分显示为:
“admin@example.com rnReply-To:admin@example.com rnMIME-版本:1.0 rnContent-Type:text/html”
这也会无意中破坏电子邮件的其余部分,因为它无法将其识别为 html。
// email headers
$headers = 'From: admin@example.com \r\n';
$headers .= 'Reply-To: admin@example.com \r\n';
$headers .= 'MIME-Version: 1.0 \r\n';
$headers .= 'Content-Type: text/html; charset=UTF-8 \r\n';
Run Code Online (Sandbox Code Playgroud)
关于如何修复这些标头有什么想法吗?谢谢。
更改如下:
$headers = 'From: admin@example.com \r\n';
$headers .= 'Reply-To: admin@example.com \r\n';
$headers .= 'MIME-Version: 1.0 \r\n';
$headers .= 'Content-Type: text/html; charset=UTF-8 \r\n';
Run Code Online (Sandbox Code Playgroud)
对此:
$headers = "From: admin@example.com \r\n";
$headers .= "Reply-To: admin@example.com \r\n";
$headers .= "MIME-Version: 1.0 \r\n";
$headers .= "Content-Type: text/html; charset=UTF-8 \r\n";
Run Code Online (Sandbox Code Playgroud)
因为\r\n应该在""(双引号)中。
| 归档时间: |
|
| 查看次数: |
916 次 |
| 最近记录: |