|  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
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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: php at shyim dot de
New email:
PHP Version: OS:


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

- Mailhog
- 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      = '';
        $subject = 'the subject';
        $message = 'hello';
        $headers = 'From:' . "\r\n" .
            'Reply-To:' . "\r\n" .
            'X-Mailer: PHP/' . phpversion();

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

Taken from

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


Add a Patch

Pull Requests

Add a Pull Request


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:
 [2021-06-17 20:40 UTC]
Please keep in mind that CRLF for email headers is what's specified in the email RFC.
 [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]
-Type: Bug +Type: Documentation Problem
 [2021-06-17 21:26 UTC]
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: Thu Sep 16 18:03:36 2021 UTC