特定服务器上的 php 函数邮件的其他标头问题
我在 php 中有一个电子邮件功能:
function send_mail($to, $from, $objet, $message) {
$entetemail = 'MIME-Version: 1.0' . "\r\n";
$entetemail .= 'Content-type: text/plain; charset=UTF-8' . "\r\n";
$entetemail .= 'From: '.$from. "\r\n";
$entetemail .= 'Cc: ' . "\r\n";
$entetemail .= 'Bcc: ' . "\r\n";
$entetemail .= 'Reply-To: '.$from .''. "\r\n";
$entetemail .= 'X-Mailer: PHP/' . phpversion() . "\r\n" ;
$entetemail .= 'Date: '. date("D, j M Y H:i:s -0600");
return mail($to, $objet, $message, $entetemail);
}
$to 是一个有效的电子邮件地址。 $from 看起来像:
Firstname name <[email protected]>
$objet 和 $message 分别来自输入文本和文本区域。
我没有遇到 PHP 错误,并且邮件给我发了错误的回复。
回声后,我的标头在两台服务器上看起来像:
MIME-Version: 1.0
Content-type: text/plain; charset=UTF-8
From: Firstname Name
Cc:
Bcc:
Reply-To: Firstname Name
X-Mailer: PHP/4.4.9
Date: Fri, 18 Feb 2011 23:35:58 -0600
在我的本地服务器上一切都很好。但在生产环境中,From 行由于 $from 变量而出现问题。该电子邮件将不会被发送。 我做错了什么吗?是否有一个服务器配置会破坏一切?
I have an email function in php:
function send_mail($to, $from, $objet, $message) {
$entetemail = 'MIME-Version: 1.0' . "\r\n";
$entetemail .= 'Content-type: text/plain; charset=UTF-8' . "\r\n";
$entetemail .= 'From: '.$from. "\r\n";
$entetemail .= 'Cc: ' . "\r\n";
$entetemail .= 'Bcc: ' . "\r\n";
$entetemail .= 'Reply-To: '.$from .''. "\r\n";
$entetemail .= 'X-Mailer: PHP/' . phpversion() . "\r\n" ;
$entetemail .= 'Date: '. date("D, j M Y H:i:s -0600");
return mail($to, $objet, $message, $entetemail);
}
$to is a valid email address.
$from looks like:
Firstname name <[email protected]>
$objet and $message come respectivelly from an input texte and a textarea.
I've got no PHP errors and mail send me false back.
After an echo, my header looks like on bothe servers:
MIME-Version: 1.0
Content-type: text/plain; charset=UTF-8
From: Firstname Name
Cc:
Bcc:
Reply-To: Firstname Name
X-Mailer: PHP/4.4.9
Date: Fri, 18 Feb 2011 23:35:58 -0600
On my local server everything is fine. But on the production one, the From line gives an issue because of the $from variable. The email will not be send.
Have I done something wrong? Is there a server configuration which break everything?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
事实上它确实有效。
我只是用假电子邮件地址进行了所有测试。看起来生产服务器不喜欢它,但我的本地服务器并不关心。
我想知道怎么做,但稍后我会看到这一点。
It in fact does work.
I just did all my tests with fake email addresses. It seems the production server didn't like it but my local didn't care.
I'd like to know how, but I'll see this later.