php headers mail headers "554 Message not allowed - Headers are not RFC compliant[291]"

6.5k views Asked by At

I'm having problems sending email to yahoo.com email addresses, the mail I send from my php script works perfectly for every other domain i send it to apart from one of our users who insists on keeping her yahoo email.

here are my headers

    $headers = array();
$headers[] = "MIME-Version: 1.0";
$headers[] = "Content-type: text/plain; charset=iso-8859-1";
$headers[] = "Date: $date";
$headers[] = "From: 'DSAC Events' <$from>";
$headers[] = "Reply-To:  <$replyto>"; 
$headers[] = "Subject: {$subject}";
$headers[] = "Return-Path: <$from>";
$headers[] = "X-Priority: 3";//1 = High, 3 = Normal, 5 = Low
$headers[] = "X-Mailer: PHP/" . phpversion();

mail($to, $subject, $msg, implode("\r\n", $headers));

I've read lots posts about people with the same problem, I've tried adding a message-id and return-path I've added the date: after reading that might be the problem and various other things to no avail.

Here is an example of the bounced mail source.

Return-path: <>
Envelope-to: [email protected]
Delivery-date: Sat, 08 Nov 2014 14:41:32 +0000
Received: from mailnull by zeus1.easy-internet.co.uk with local (Exim 4.82)
    id 1Xn7Cm-001cxb-8a
    for [email protected]; Sat, 08 Nov 2014 14:41:32 +0000
X-Failed-Recipients: [email protected]
Auto-Submitted: auto-replied
From: Mail Delivery System <[email protected]>
To: [email protected]
Subject: Mail delivery failed: returning message to sender
Message-Id: <[email protected]>
Date: Sat, 08 Nov 2014 14:41:32 +0000

This message was created automatically by mail delivery software.

A message that you sent could not be delivered to one or more of its
recipients. This is a permanent error. The following address(es) failed:

  [email protected]
    SMTP error from remote mail server after end of data:
    host mta6.am0.yahoodns.net [63.250.192.46]: 554 Message not allowed - Headers are not RFC compliant[291]

------ This is a copy of the message, including all the headers. ------

Return-path: <[email protected]>
Received: from d11dsa by zeus1.easy-internet.co.uk with local (Exim 4.82)
    (envelope-from <[email protected]>)
    id 1Xn7Ci-001cl4-9S
    for [email protected]; Sat, 08 Nov 2014 14:41:29 +0000
To: [email protected]
Subject: 
X-PHP-Script: www.dsa.co.uk/eventmail.php for 2.218.47.72
MIME-Version: 1.0
Content-type: text/plain; charset=iso-8859-1
Date: Sat, 08 Nov 2014 14:41:28 +0000
From: DSACEvents <[email protected]>
Reply-To:  <[email protected]>
Subject: 
X-Priority: 3
3

There are 3 answers

1
hippytyre On BEST ANSWER

Thanks for the reply and you're right. Here's what I eventually ended up with which works perfectly.

    function generateMessageID()
{
  return sprintf(
    "<%s.%s@%s>",
    base_convert(microtime(), 10, 36),
    base_convert(bin2hex(openssl_random_pseudo_bytes(8)), 16, 36),
    $_SERVER['SERVER_NAME']
  );
}

        $headers = array();
$headers[] = "MIME-Version: 1.0";
$headers[] = "Content-type: text/plain; charset=iso-8859-1";
$headers[] = "Mesaage-id: " .generateMessageID();
$headers[] = "From: 'DSAC Events' <$from>";
$headers[] = "Reply-To: $Arranger <$replyto>"; 
$headers[] = "Date: $date";
$headers[] = "Return-Path: <$from>";
$headers[] = "X-Priority: 3";//1 = High, 3 = Normal, 5 = Low
$headers[] = "X-Mailer: PHP/" . phpversion();


mail($to, $subject, $message, implode("\r\n", $headers));
1
Lars Martin On

I had the same problems with yahoo. Only the double 'subject' was the problem. Great Job, works fine for me.

0
priscah malo On

According to the error message, it seems Yahoo servers are rejecting email from your domain SMTP server. This can be caused by several reasons including the ones below:

  • If there are no Message-ID or Date headers in the messages being sent by your program

  • If the attachments do not follow the exact structure for that file type, these are also considered suspicious and hence quarantined, just in case they pose any form of threat.

  • If the message has 2 subjects the mail can be rejected.