php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #81158 Mails sent by mail function broken since PHP 8.0
Submitted: 2021-06-17 20:13 UTC Modified: 2021-06-17 21:26 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: php at shyim dot de Assigned:
Status: Open Package: Mail related
PHP Version: 8.0.7 OS: Debian 10 (Docker)
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
29 + 12 = ?
Subscribe to this entry?

 
 [2021-06-17 20:13 UTC] php at shyim dot de
Description:
------------
Setup:

- Mailhog
- SSMTP
- Configured php.ini to ssmtp -t

Execute the test script with 7.4 and 8.0. The email looks correct in 7.4 and its totally broken on 8.0. The headers are in the body in PHP 8.0.

Test script:
---------------
$to      = 'nobody@example.com';
        $subject = 'the subject';
        $message = 'hello';
        $headers = 'From: webmaster@example.com' . "\r\n" .
            'Reply-To: webmaster@example.com' . "\r\n" .
            'X-Mailer: PHP/' . phpversion();

        mail($to, $subject, $message, $headers);

Taken from https://www.php.net/manual/en/function.mail

Expected result:
----------------
The mail is the same on both PHP versions

Actual result:
--------------
It's totally different. The PHP 8.0 doesn't have a subject. I guess it has something done with https://github.com/php/php-src/commit/6983ae751cd301886c966b84367fc7aaa1273b2d#diff-c6922cd89f6f75912eb377833ca1eddb7dd41de088be821024b8a0e340fed3df

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-06-17 20:15 UTC] php at shyim dot de
Here is a screenshot of the sent mail. The headers have always two new lines instead one:
https://i.imgur.com/iQEaUyi.png
 [2021-06-17 20:40 UTC] tiffany@php.net
Please keep in mind that CRLF for email headers is what's specified in the email RFC.

https://datatracker.ietf.org/doc/html/rfc2822#section-2.2
 [2021-06-17 21:13 UTC] php at shyim dot de
The headers are in CRLF in the example. Or was it a general comment?
 [2021-06-17 21:26 UTC] cmb@php.net
-Type: Bug +Type: Documentation Problem
 [2021-06-17 21:26 UTC] cmb@php.net
The fix for the bug, which has been reported more than ten years
ago, had deliberately been delayed to PHP 8 (a new major version).
It should probably get a changelog entry, but I am against
reverting this fix.  If your mail software replaces CRLF with
CRLFCRLF, or whatever, in mail headers, consider to report that
bug upstream.
 [2021-06-17 22:03 UTC] php at shyim dot de
You are correct. ssmtp and busybox sendmail doesn't care about CRLF. Where the postfix sendmail does the job correct.
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Fri Sep 24 10:03:36 2021 UTC