为什么PHP邮件不能发送给多个收件人?
问题描述:
当使用PHP的mail()
功能,我收到的电子邮件到两个帐户时“到”参数设置为:为什么PHP邮件不能发送给多个收件人?
"[email protected],[email protected]"
,但是当我换他们圆:
"[email protected],[email protected]"
的电子邮件时到[email protected]
但不是[email protected]
。如果指定为CC或BCC标题,它也不会收到电子邮件。
有人可以提出为什么这可能是这种情况?直到几个星期前,它工作良好。据我所知,我的服务器上没有任何变化,虽然它是共享主机,所以它可能会有。
注意事项:无论顺序如何,mail()
函数始终返回true
。 example1.com
也是发送服务器。
我的代码如下:
$from = '[email protected]';
$headers = '';
$headers .= 'From: My Site <' . $from . ">\r\n" .
'Reply-To: ' . $_POST["Email"] . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$body = 'Message goes here';
$to = '[email protected],[email protected]'; // will not send to [email protected], though will if the addresses are swapped
if (mail($to, 'Subject goes here', $body, $headers, '-f ' . $from)) {
$url = "/contact/?message=sent";
} else {
$url = "/contact/?message=failed";
}
header("Location: $url");
答
纵观PHP手册,我看到的例子有逗号后的空间.. 尝试
$to = '[email protected], [email protected]';
你也可以用你的头部分添加一个CC
$headers .= 'Cc: [email protected]' . "\r\n";
+0
正如我的问题所指出的,CC(非BCC)头也不工作。我用逗号后面的空格试过,但那也不起作用。谢谢您的好意。 – b4tch
调试邮件传递就像给猫洗澡一样。但如果你有权访问服务器邮件日志,那就是我要开始的地方。 – nogad
是否确定电子邮件没有被发送,而是被垃圾邮件过滤器拦截? –
查看PHP手册,我注意到这个例子在逗号后有一个空格。'$ to ='[email protected],[email protected]';' 您也可以使用您的标题部分添加一个CC '$ headers。='抄送:[email protected]'。 “\ r \ n”;' –