PHP generated email being flagged by hotmail

433 views Asked by At

I've got a PHP page that sends email from a HTML form. The email sends, but it's being flagged by Hotmail as spam. I've replaced the actual email addresses in the code.

<?php
function clean_string($string){
  $bad = array("content-type","bcc:","to:","cc:","href");
  return str_replace($bad,"",$string);
}
$name=$_POST['name'];
$email=$_POST['email'];
$subj=$_POST['subject'];
$body=$_POST['body'];
$email_subject='Website name - '.$subj;
$email_message="<html><body><p>".clean_string($body)."</p><p>".$name."<br>".$email."</p></body></html>";
$headers[] = 'MIME-Version: 1.0';
$headers[] = 'Content-type: text/html; charset=iso-8859-1';
$headers[] = "From:[email protected]";
$headers[] = "Reply-To:".$name."<".$email.">";

$header=implode("\r\n",$headers);
if(mail('[email protected]',$email_subject,$email_message,$header)==true){header('location: http://julie-mosaics.dx.am/index.php?page=contact&result=success');} else {header('location: http://julie-mosaics.dx.am/index.php?page=contact&result=fail');}
?>

This is hotmail's error message.

Content analysis details:   (7.1 points, 7.0 required)

  pts rule name              description
 ---- ---------------------- --------------------------------------------------
  0.0 HTML_MESSAGE           BODY: HTML included in message
  1.1 MIME_HTML_ONLY         BODY: Message only has text/html MIME parts
  0.1 MISSING_MID            Missing Message-Id: header
  0.0 FROM_MISSP_DKIM        From misspaced, DKIM dependable
  1.4 MISSING_DATE           Missing Date: header
  2.5 FREEMAIL_FORGED_REPLYTO Freemail in Reply-To, but not From
  2.0 FROM_12LTRDOM          From a 12-letter domain
1

There are 1 answers

1
BeetleJuice On

It may have nothing to do with your code. If a Microsoft customer reported an email coming from your server as spam, it will affect whether hotmail accepts mail from you.

Anyway the report you received in the error message seems really helpful. In particular, it looks like setting a date header or making sure Reply-To and From headers match would get your email accepted.

$headers[] = 'Date: '. date('D, d M Y H:i:s') . ' UT';
$headers[] = "From:     $name<$email>";
$headers[] = "Reply-To: $name<$email>";