【发布时间】:2015-12-22 13:49:06
【问题描述】:
这里是php mail()函数代码的简单使用:
<?php
$from = "From email goes here";
$to = "To email goes here";
ini_set("display_errors", "On");
ini_set("sendmail_from", $from);
ini_set("SMTP", "localhost");
ini_set("smtp_port", "25");
$subject = "Hello, This is subject";
$message = "<p style='color: green;font-weight: bold;'>Hello World, This is Body</p>";
$headers = 'MIME-Version: 1.0' . "\r\n";
//$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'Content-Type: text/html; Charset=UTF-8' . "\r\n";
$headers .= 'From: Birthday Reminder <' . $from . '>' . "\r\n";
$headers .= 'To: Mary <' . $to . '>' . "\r\n";
$headers .= 'Reply-To: Birthday Reminder <' . $from . '>' . "\r\n";
$headers .= 'X-Mailer: PHP/' . phpversion();
if(mail($to, $subject, $message,$headers))
{
echo("<p style='color: blue;font-weight: bold;'>Email Sent :D</p>");
}
else
{
echo("<p style='color: red;font-weight: bold;'>Email Message delivery failed...</p>");
}
?>
为什么使用这些代码发送的电子邮件总是进入垃圾邮件文件夹?
标题的顺序可以吗?
我应该使用哪些额外的标头来防止垃圾邮件?
编辑:
我知道堆栈中有一些关于此的线程。
但我正在寻找更新的答案。
所以它不是重复。
【问题讨论】:
-
很可能是因为任何人都可以发送这样的“常规”电子邮件,您需要设置服务器以“确认”您是谁/增加一些可信度,查看SPF 和 DKIM