Home > Blockchain >  PHP's mail via ssmtp returns error Message is not RFC 2822 compliant
PHP's mail via ssmtp returns error Message is not RFC 2822 compliant

Time:04-02

I have the following setting in my php.ini

[mail function]
sendmail_path = /usr/sbin/sendmail -t -i

Binary /usr/sbin/sendmail comes from the installed ssmtp package on Alpine Linux. I want to relay all emails to the opensmtpd container from the private network, so my /etc/ssmtp.conf looks like this:

mailhub=opensmtpd

This is how I send the email:

$ php -r 'mail("[email protected]", "Test subject", "This is our test message", "From: [email protected]");'

and I get the following error:

sendmail: 550 5.7.1 Delivery not authorized, message refused: Message is not RFC 2822 compliant


UPDATE

Added more verbosity to the sendmail command and adjusted a bit the /etc/ssmtp.conf as follows:

mailhub=opensmtpd:25
FromLineOverride=Yes
UseTLS=No

This is how I call it

$ php -r '$headers = ["Date" => date("r", time()), "From" => "[email protected]", "Reply-To" => "[email protected]", "X-Mailer" => "PHP/" .
 phpversion()]; mail("[email protected]", "Test subject", "This is our test masdlkfjaslkdfjaslkdfjaskldjfeproiqweessage\r\n", $headers);'

And this is the output:

[<-] 220 opensmtpd-2298774033-mq2hl ESMTP OpenSMTPD
[->] HELO php-3107772150-7jj96
[<-] 250 opensmtpd-2298774033-mq2hl Hello php-3107772150-7jj96 [172.17.0.60], pleased to meet you
[->] MAIL FROM:<[email protected]>
[<-] 250 2.0.0: Ok
[->] RCPT TO:<opensmtpd:25@php-3107772150-7jj96>
[<-] 250 2.1.5 Destination address valid: Recipient ok
[->] DATA
[<-] 354 Enter mail, end with "." on a line by itself
[->] Received: by php-3107772150-7jj96 (sSMTP sendmail emulation); Fri, 01 Apr 2022 14:13:35  0000
[->] To: [email protected]
[->] Subject: Test subject
[->] Date: Fri, 01 Apr 2022 14:13:35  0000
[->] From: [email protected]
[->] Reply-To: [email protected]
[->] X-Mailer: PHP/8.0.17
[->]
[->] This is our test masdlkfjaslkdfjaslkdfjaskldjfeproiqweessage
[->]
[->]
[->] .
[<-] 550 5.7.1 Delivery not authorized, message refused: Message is not RFC 2822 compliant

I don't get it

CodePudding user response:

RFC2822 says Date: and From: headers are required (section 3.6)

CodePudding user response:

I had to prepend body message with Body:, e.g. Body: This is our test message

  • Related