Search code examples
phpgmailmailgunpostfix-mta

php mail using mailgun smtp blocked by gmail; error RFC 5322


I am getting the following intermittent error that has started in the last 24 hours from gmail servers (When sending to gsuite accounts or gmail accounts). It doesn't happen to all messages. Even the same message failed once and then worked later. I am looking for a way to fix this. I am not sure if it is the headers or something gmail did as a mistake.

I have a dedicated IP with mailgun and aren't getting any other errors except gmail.

This is the error:

5.7.1 [69.72.33.194 11] Our system has detected that this message is 5.7.1 not RFC 5322 compliant: 5.7.1 'From' header is missing. 5.7.1 To reduce the amount of spam sent to Gmail, this message has been 5.7.1 blocked. Please visit 5.7.1 https://support.google.com/mail/?p=RfcMessageNonCompliant 5.7.1 and review RFC 5322 specifications for more information. p18si54042ood.13 - gsmtp

Code to send email: (Via postfix using mailgun)

$lead_email = BCC_EMAIL;
$cc_email = LEAD_CC_NOTIFICATION_EMAIL;

$message = <<<MSG
    <p>Hi PHP POS Admin,</p>
    <p>You have received a TRIAL CONVERSION from the customer below: </p>

    <ul>
    <li>Company: $data[company]</li>
    <li>Name: $data[name]</li>
    <li>E-Mail: $data[email]</li>
    <li>Phone: $data[phone]</li>
    <li>Provider: $data[payment_provider]</li>
    <li>Address: <strong>$data[country]</strong> $data[address_1] $data[address_2] $data[city] $data[state], $data[zip]</li>
    <li>IP Address: $data[ip_address]</li>
    <li>IP Address Location: $data[ip_geo]</li>
    </ul>

    Regards<br>
    </p>
MSG;

    $from = $lead_email;
    $subject = 'SUBJECT';
    $headers = 'MIME-Version: 1.0' . "\r\n";
    $headers .= "From: ".$from . "\r\n";

    $headers .= 'Content-type: text/html; charset=UTF-8' . "\r\n";
    mail($lead_email, $subject, $message, $headers);

Raw MIME:

Received: by REDACTED (Postfix, from userid 48)
    id 91F58812D2; Tue, 19 May 2020 17:51:59 +0000 (UTC)
To: REDACTED
Subject: REDACTED
X-PHP-Originating-Script: 500: REDACTED
MIME-Version: 1.0
From: example@example.com
Content-type: text/html; charset=UTF-8
Message-Id: < REDACTED >
Date: Tue, 19 May 2020 17:51:59 +0000 (UTC)

    <p>Hi PHP POS Admin,</p>
    <p>You have received a TRIAL CONVERSION from the customer below: </p>

    <ul>
    <li>Company: REDACTED</li>
    <li>Name: REDACTED </li>
    <li>E-Mail: REDACTED </li>
    <li>Phone: REDACTED </li>
    <li>Provider: braintree</li>
    <li>Address: <strong> REDACTED </strong>    , REDACTED </li>
    <li>IP Address: REDACTED </li>
    <li>IP Address Location: , , </li>
    </ul>

    Regards,<br>
    PHP Point Of Sale Team
    </p>

Solution

  • I ended up using phpmailer as this manages all the headers. So far it has worked