gpt4 book ai didi

php - 在 PHP 邮件函数中设置 $headers 数组时出现问题

转载 作者:可可西里 更新时间:2023-11-01 00:43:22 24 4
gpt4 key购买 nike

当我将 $headers 数组指定为时,我无法通过 PHP 邮件函数发送电子邮件

$headers = array (
'From' => "info@mysite.com",
'Content-type' => "text/html;charset=UTF-8"
);

$headers=array(
'From: "info@mysite.com',
'Content-Type:text/html;charset=UTF-8',
'Reply-To: "info@mysite.com'
);

这是代码

 <?php
$email = 'test@test.com';
$headers=array(
'From: "info@mysite.com',
'Content-Type:text/html;charset=UTF-8',
'Reply-To: info@mysite.com'
);

$msg= 'This is a Test';

mail($email, "Call Back Requert Confirmation", $msg, $headers);
?>

你能告诉我为什么会这样吗?我该如何解决这个问题?

最佳答案

如果你想通过数组发送$headers,那么你需要在每个header值的末尾添加\r\n并将数组转换成一个字符串

您的代码应该是:

$headers = array(
'From: <info@mysite.com>',
'Content-Type:text/html;charset=UTF-8',
'Reply-To: <info@mysite.com>'
);
$headers = implode("\r\n", $headers);

关于php - 在 PHP 邮件函数中设置 $headers 数组时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27478307/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com