我正在使用phpmailer类发送电子邮件。目前gmail和yahoo不会将电子邮件标记为垃圾邮件,但Hotmail始终如此。我怎么能阻止这个?我的代码如下。
require_once('../PHPMailer/class.phpmailer.php');
//include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded
$mail = new PHPMailer();
$mail->IsSMTP(); // set mailer to use SMTP
$mail->Host = "mail.example.com"; // specify main and backup server
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "xxx"; // SMTP username -- CHANGE --
$mail->Password = "xxx"; // SMTP password -- CHANGE --
$mail->Port = "25"; // SMTP Port
$mail->From = "no-repy@example.com"; //From Address -- CHANGE --
$mail->FromName = "xxx"; //From Name -- CHANGE --
$mail->AddAddress($email, $passerusername); //To Address -- CHANGE --
$mail->AddReplyTo("no-reply@example.com", "xxx"); //Reply-To Address -- CHANGE --
$mail->WordWrap = 50; // set word wrap to 50 characters
$mail->IsHTML(false); // set email format to HTML
$mail->Subject = "AuthSMTP Test";
$mail->Body = "AuthSMTP Test Message!";
if(!$mail->Send())
{
echo "Message could not be sent. <p>";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}
echo "Message has been sent";
答案 0 :(得分:17)
这涉及设置几个邮件标题以击败过滤器。
我在php mailers CreateHeader方法的最开始添加了以下内容......
$result = '';
$result .= $this->HeaderLine("Organization" , SITE);
$result .= $this->HeaderLine("Content-Transfer-encoding" , "8bit");
$result .= $this->HeaderLine("Message-ID" , "<".md5(uniqid(time()))."@{$_SERVER['SERVER_NAME']}>");
$result .= $this->HeaderLine("X-MSmail-Priority" , "Normal");
$result .= $this->HeaderLine("X-Mailer" , "Microsoft Office Outlook, Build 11.0.5510");
$result .= $this->HeaderLine("X-MimeOLE" , "Produced By Microsoft MimeOLE V6.00.2800.1441");
$result .= $this->HeaderLine("X-Sender" , $this->Sender);
$result .= $this->HeaderLine("X-AntiAbuse" , "This is a solicited email for - ".SITE." mailing list.");
$result .= $this->HeaderLine("X-AntiAbuse" , "Servername - {$_SERVER['SERVER_NAME']}");
$result .= $this->HeaderLine("X-AntiAbuse" , $this->Sender);
这是前段时间做的 - 我认为我已经有一年没有重访了!试试吧,如果还有问题,请回来。