Description
Description
The following code:
<?php
mail("someone@example.com", "This is the subject", "This is the body");
?>
Resulted in this output of the DATA part of the communication from tcpdump on the receiving SMTP server when building container "FROM php:8.0.14-fpm-alpine" or "FROM php:fpm-alpine":
Received: by f3de6efeb3a0 (sSMTP sendmail emulation); Sat, 12 Feb 2022 06:28:10 +0100\r\n
From: "Linux User" <www-data@f3de6efeb3a0>\r\n
Date: Sat, 12 Feb 2022 06:28:10 +0100\r\n
To: redacted@example.com\r
\r\n
Subject: This is the subject\r
\r\n
\r
\r\n
This is the Body\r
\r\n
\r\n
And this is the resulting mail headers of the mail on the receiving SMTP server:
Return-Path: <www-data@f3de6efeb3a0>
X-Envelope-To: redacted@example.com
Message-ID: <3966183578-2392@mail.example.com>
Received: from localhost ([127.0.0.1])
by mail.example.com with SMTP
for redacted@example.com;
Sat, 12 Feb 2022 06:28:10 +0100
Received: by f3de6efeb3a0 (sSMTP sendmail emulation); Sat, 12 Feb 2022 06:28:10 +0100
From: "Linux User" <www-data@f3de6efeb3a0>
Date: Sat, 12 Feb 2022 06:28:10 +0100
To: redacted@example.com
This is the output using the exact same environment, just that the container is build using "FROM php:7.4-fpm-alpine":
Received: by ae23725475da (sSMTP sendmail emulation); Sat, 12 Feb 2022 06:27:33 +0100\r\n
From: "Linux User" <www-data@ae23725475da>\r\n
Date: Sat, 12 Feb 2022 06:27:33 +0100\r\n
To: redacted@example.com\r\n
Subject: This is the subject\r\n
\r\n
This is the Body\r\n
And this is the resulting mail headers of the mail on the receiving SMTP server:
Return-Path: <www-data@ae23725475da>
X-Envelope-To: redacted@example.com
Message-ID: <3966147578-2389@mail.example.com>
Received: from localhost ([127.0.0.1])
by mail.example.com with SMTP
for redacted@example.com;
Sat, 12 Feb 2022 06:27:33 +0100
Received: by ae23725475da (sSMTP sendmail emulation); Sat, 12 Feb 2022 06:27:33 +0100
From: "Linux User" <www-data@ae23725475da>
Date: Sat, 12 Feb 2022 06:27:33 +0100
To: redacted@example.com
Subject: This is the subject
The result is that when using PHP 8 there are some invalid "\r" which makes the mail format invalid and so the headers are not processed correctly on the receiving SMTP server. The result is that the email does not have a subject. I've also tried setting additional headers, but they are all invalid and not processed due to the invalid "\r".
I've tried using both sendmail and ssmtp in the container. It yields the same result.
My php.ini setting are:
sendmail_path = '/usr/sbin/sendmail -t -i -S myserver:25'
Something has changed in the PHP mail() function between PHP 7 and PHP 8
PHP Version
PHP 8.0.14 and newer
Operating System
Docker php:8.0.14-fpm-alpine and php:fpm-alpine