PHP-不发送带有标题信息的电子邮件
当我添加标题信息时,我在发送电子邮件时遇到问题。 但是,当我删除header参数时,它就可以工作了。怎么了?是密码吗?或者我需要在web服务器管理面板上更改一些设置,比如“允许标题”之类的? 我正在尝试发送到hotmail,以防这与确定问题有关。 任何帮助都将不胜感激。谢谢 以下内容不发送电子邮件:PHP-不发送带有标题信息的电子邮件,php,email,header,Php,Email,Header,当我添加标题信息时,我在发送电子邮件时遇到问题。 但是,当我删除header参数时,它就可以工作了。怎么了?是密码吗?或者我需要在web服务器管理面板上更改一些设置,比如“允许标题”之类的? 我正在尝试发送到hotmail,以防这与确定问题有关。 任何帮助都将不胜感激。谢谢 以下内容不发送电子邮件: <?php $to = 'iputmyrealemailhere@hotmail.com'; $subject = 'the subject'; $mess
<?php
$to = 'iputmyrealemailhere@hotmail.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster@example.com';
mail($to, $subject, $message, $headers);
?>
下面发送电子邮件:
<?php
$to = 'iputmyrealemailhere@hotmail.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster@example.com';
mail($to, $subject, $message);
?>
我在我的php邮件函数中使用了这些标题,而且效果很好注意:我还使用第三方邮件路由服务来避免邮件被标记为来自垃圾邮件IP。你可能也想调查一下
$headers = 'From: '.$from.'@foo.net' . "\r\n" .
'Reply-To: '.$from.'@foo.net' . "\r\n" .
'X-Mailer: PHP/' . phpversion() . "\r\n" .
'MIME-Version: 1.0' . "\r\n" .
'Content-type: text/html; charset=iso-8859-1' . "\r\n";
我还使用可选的第五个参数来设置信封地址,例如:
$parameters = '-f '.$from.'@foo.net';
最后一个问题是:
mail($to, $subject, $message, $headers, $parameters);
您只需从标题列表中删除“FROM:”。。但真正的问题是,我如何才能将发送的电子邮件地址更改为我想要的特定电子邮件尝试发送到Gmail并在垃圾邮件中查找它。Hotmail倾向于丢弃不遵守RFC标准的电子邮件。请尝试在
$headers
的末尾添加\n
,但这只是一个猜测。@petr。实际上,他应该添加\r\n但如果不存在,服务器也应该添加。您在php错误日志中看到任何错误吗?如果在发送时捕获返回值($result=mail($to、$subject、$message、$headers);
),则返回值是真是假?说真的,您应该使用类似phpMailer的库通过php发送邮件。内置的mail()
函数有很多缺点。