Bug #54298 [Com]: Using empty additional_headers adding extraneous CRLF

From: Date: Tue, 07 Jan 2020 13:16:17 +0000
Subject: Bug #54298 [Com]: Using empty additional_headers adding extraneous CRLF
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-224752@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=54298&edit=1 ID: 54298 Comment by: anrdaemon at yandex dot ru Reported by: anrdaemon at freemail dot ru Summary: Using empty additional_headers adding extraneous CRLF Status: Closed Type: Bug Package: Mail related Operating System: Win32/*NIX32 PHP Version: Irrelevant Assigned To: cmb Block user comment: N Private report: N New Comment: Submitted: 2011-03-17 18:28 UTC [2020-01-06 13:51 UTC] cmb@php.net -Status: Verified +Status: Closed *khm* Many thanks for this Christmas gift. Previous Comments: ------------------------------------------------------------------------ [2020-01-06 13:51:59] cmb@php.net Automatic comment on behalf of cmbecker69@gmx.de Revision: http://git.php.net/?p=php-src.git;a=commit;h=ae2150692a9a2e0878314385d03826f160e6a76a Log: Fix #54298: Using empty additional_headers adding extraneous CRLF ------------------------------------------------------------------------ [2020-01-05 14:19:33] cmb@php.net The following pull request has been associated: Patch Name: Fix #54298: Using empty additional_headers adding extraneous CRLF On GitHub: https://github.com/php/php-src/pull/5055 Patch: https://github.com/php/php-src/pull/5055.patch ------------------------------------------------------------------------ [2020-01-05 14:19:13] cmb@php.net As of PHP 7.2.0, there's no need anymore to implode() the array, since $additional_headers accepts an array in the first place. Doing so won't add the extraneous line break, so this issue is partially resolved. Still, when passing an empty string, there should be no extraneous line break. ------------------------------------------------------------------------ [2011-03-17 18:28:09] anrdaemon at freemail dot ru Description: ------------ Using the code sample below, you could see that it adds a "\r\n" to the end of the mail headers irrelevant to $additional_headers containing a meaningful value. Even using an empty($addParams) ? NULL/false : implode() replacement, it does not fix the problem. The resulting message will still start from second line. Which is bad for look. To beat it, you're forced to check for empty($addParams) before invoking mail() (and to have two separate mail() lines in your code, which does not lead to the code clarity)... Test script: --------------- <?php $addParams = array(); mail('someuser@example.com', 'testsubj', 'Body part', implode("\r\n", $addParams)); ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=54298&edit=1

« previous php.bugs (#224752) next »