[php-src] Issue #7902: mb_send_mail sends broken header in PHP 8.0 (possible cause: Content-Transfer-Encoding added without CRLF separation)

From: Date: Fri, 07 Jan 2022 09:12:36 +0000
Subject: [php-src] Issue #7902: mb_send_mail sends broken header in PHP 8.0 (possible cause: Content-Transfer-Encoding added without CRLF separation)
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-238840@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/7902 Author: tbali0524 ### Description The following code: ```php <?php mb_internal_encoding("UTF-8"); $to = "omittedvalidaddress@example.com"; $subject = "test mail"; $message = "body of testing php mail"; $header["Mime-Version"] = "1.0"; $header["Content-Type"] = "text/html; charset=UTF-8"; $header["From"] = "omittedvalidaddress2@example.com"; $header["X-Mailer"] = "PHP/" . phpversion(); mb_send_mail($to, $subject, $message, $header); ``` Resulted in this output: ``` Ym9keSBvZiB0ZXN0aW5nIHBocCBtYWls (body of email) ``` But I expected this output instead: ``` body of testing php mail ``` The mail is sent with proper base64 encoded body, but because of a problem in mail header the receiving client cannot decode it. It seems that mb_send_mail() adds a Content-Transfer-Encoding element to the mail header without any linefeed separation after the user supplied header elements: Part of received mail header: ``` X-Mailer: PHP/8.0.12 Content-Transfer-Encoding: BASE64 ``` Should have been: ``` X-Mailer: PHP/8.0.12 Content-Transfer-Encoding: BASE64 ``` Notes: * I tried to add extra trailing LF or extra CRLF to my $header and tried both array and string concatenated versions, but it seems php strips any user-supplied trailing linefeeds. * Works in PHP 7.4 * A similar bug was reported in 2021/06 at <https://bugs.php.net/bug.php?id=81158> and was reclassified as documentation problem, but imho my above bug report is slightly different and I could not circumwent it because Content-Transfer-Encoding is not set by me but the php function. ### PHP Version PHP 8.0.12 ### Operating System Cloudlinux (hosted by a provider)

« previous php.bugs (#238840) next »