Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
934 views
in Technique[技术] by (71.8m points)

php - PHPmailer sending mail to spam in hotmail. how to fix?

I'm using the phpmailer class to send emails. Currently gmail and yahoo do not mark emails as spam, but hotmail always does. How can I prevent this? My code is below.

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";
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This involves setting a few mail headers to beat the filters.

I have added the following to the very start of php mailers CreateHeader method...

$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);

that was done some time ago - I haven't revisited for about a year I think! Try it and come back if you still have problems.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...