Quantcast
Channel: Active questions tagged email - Stack Overflow
Viewing all articles
Browse latest Browse all 30082

PHP: 554 Message not allowed - Headers are not RFC compliant[291]

$
0
0

This can be duplicated post but please read before you flag it.

I using one mail function what I made and work a while until I not start receiving error messages from Yahoo.com and SkyNet.be.

Now I know that this error is realated to Message-ID or Date header inside email but my fealing is that Message-ID is main problem and need to solve that part.

Here is my code how I generate Message-ID:

// Generate secure unique message ID
$msgID = sprintf(
    "<%s.%s@%s>",
    base_convert(microtime(), 10, 36),
    base_convert(bin2hex(
        function_exists('random_bytes') ? random_bytes(8) : (
                function_exists('openssl_random_pseudo_bytes') ? openssl_random_pseudo_bytes(8) : decbin(rand(100,819))
        )
    ), 16, 36),
    $_SERVER['SERVER_NAME']
);

Like you see above, I first checking is there PHP7.x solution for generating random bytes using random_bytes() function. If is version PHP5.x i use standard openssl_random_pseudo_bytes() function and if that function is not enabled or PHP version is 4.x or lower I use simple decbin() with rand().

Here is also my header setup:

// Preferences for Subject field
if(function_exists('iconv_mime_encode')){
    $subject_preferences = array(
        "input-charset"     => 'utf-8',
        "output-charset"    => 'utf-8',
        "line-length"       => 76,
        "line-break-chars"  => PHP_EOL
    );

    $mime_subject = iconv_mime_encode("Subject", $subject, $subject_preferences);
}
else
    $mime_subject = mb_encode_mimeheader("Subject: {$subject}", strtoupper('utf-8'), 'B', "\r\n", strlen('Subject: '));

// Headers
$headers = array(
   "Content-type: text/html; charset=utf-8",
    $mime_subject,
    "From: {$from_name} <{$from_email}>",
    "Reply-To: {$from_email}",
    "X-Mailer: PHP/" . phpversion(),
    "X-Sender: {$from_name} <{$from_email}>",
    "X-Priority: 1 (Higuest)",
    "X-MSMail-Priority: High",
    "Importance: High",
    "Content-Transfer-Encoding: 8bit ",
    "Date: " . date("r (T)") . "",
    "Message-ID: {$msgID}",
    "In-Reply-To: {$msgID}",
    "References: {$msgID}",
    "Return-Path: {$from_email}",
    "MIME-Version: 1.0 "
);
$header = join(PHP_EOL, $headers);

Now main question is: -Why I getting error:

SMTP error from remote mail server after end of data: 554 Message not allowed - Headers are not RFC compliant[291]

???


Viewing all articles
Browse latest Browse all 30082

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>