New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remote host said: 552 5.2.0 Message contains bare CR and is violating 822.bis section 2.3 #3012
Comments
That's a little strange! Bare CRs are only really associated with very old MacOS systems, but here it looks like it might be something that you have introduced in your message body - does it bounce in the same way if you use a minimal body, like 'test'? Line break problems are often hard to debug because editors and web forms have a habit of altering them invisibly, but we'll cross that bridge if switching to SMTP doesn't solve it. |
Thanks for your comment. I tried changing the message body to simply "Test", but received the same failure notice. Using SMTP as you suggested did allow the mail to be delivered: <?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
/**
* @param PHPMailer $mail
*
* @return void
*/
function useSMTP( PHPMailer $mail ) : void
{
$mail->SMTPDebug = SMTP::DEBUG_SERVER;
$mail->isSMTP();
$mail->Host = 'REDACTED.example.com';
$mail->SMTPAuth = true;
$mail->Username = 'REDACTED@example.com';
$mail->Password = 'REDACTED';
$mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;
$mail->Port = 465;
}
$mail = new PHPMailer;
$emailTo = 'REDACTED@wp2.kscoxmail.com';
$emailFrom = 'REDACTED@example.com';
$emailSubject = 'Test';
$emailHTML = 'Test';
$mail->IsHTML();
$mail->CharSet = 'UTF-8';
$mail->Priority = 3;
$mail->AddAddress( $emailTo );
$mail->From = $emailFrom;
$mail->AddReplyTo( $emailFrom );
$mail->Subject = $emailSubject;
$mail->Body = $emailHTML;
// if the line below is left out, the mail bounces back with "Remote host said: 552 5.2.0 Message contains bare CR and is violating 822.bis section 2.3"
useSMTP( $mail );
$result = $mail->Send();
var_dump( $result ); I haven't been able to test this on other PHP versions yet, so no idea if that is related to the issue or not. |
I'm glad you've got that working. Without a bit-perfect copy of the submitted message this is difficult to diagnose any further. |
I did some more testing in different PHP versions (on linux, using the default sendmail instead of SMTP), and the emails go fine with version 7.4, but not 8.0, 8.1, 8.2 or 8.3. I changed my sendmail_path INI setting from PHP 7.4:
PHP 8.x:
I don't know how to capture the raw output of sendmail, but from what I can tell sendmail expects line breaks to be \n, but PHP's mail() now outputs /r/n in versions 8.x. I suspect sendmail is mangling the line breaks due to being fed CRLF data. Some interesting threads I found:
So I think this is an issue between PHP and sendmail, from what I can tell. If so I'm not sure there's anything that can be done on PHPMailer's part. |
Good research, thank you. Wow, that second link! Somehow this had passed me by, and that's a pretty major breaking change. I'm surprised others are not having similar issues. Historically, it has been annoying that use PHPMailer\PHPMailer\PHPMailer;
class MyMail extends PHPMailer
{
static $LE = "\n";
} then use that class instead of the stock PHPMailer. Give that a try! |
I finally had some time to test out the subclass with \n line endings, and unfortunately it doesn't change anything. The output still has CRLF breaks. |
The mail() feature is broken in recent PHP versions. If you control this server, try setting the sendmail_path to remove CRs from whatever PHP is handing over to the mail agent.
Needs dos2unix to work. I tested this even with HTML mails and UTF-8 characters. Works in all cases for me. |
Problem description
I started receiving bounce-backs from a client recently with the error message in the title. This is on PHP 8.1.23 & PHPMailer 6.9.1.
I reduced my case down to a bare-bones example:
While this works for 99% of recipients, from this one particular client I receive the following failure notice reply:
The text was updated successfully, but these errors were encountered: