Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

defaultMailer func, LF used in headers instead of recommended CRLF #584

Closed
Reloecc opened this issue Aug 26, 2024 · 2 comments
Closed

defaultMailer func, LF used in headers instead of recommended CRLF #584

Reloecc opened this issue Aug 26, 2024 · 2 comments

Comments

@Reloecc
Copy link

Reloecc commented Aug 26, 2024

Version: 2.10.8 (and many before)

Bug Description

Php manual says that input to mail function "must obey" RFC2822
https://www.php.net/manual/en/function.mail.php
http://www.faqs.org/rfcs/rfc2822.html

There is stated in this RFC that:
2.2. Header Fields
Header fields are lines composed of a field name, followed by a colon
(":"), followed by a field body, and terminated by CRLF.

Tracy in its defaultMailer replaces everything to just LF.

$parts = str_replace(
["\r\n", "\n"],
["\n", PHP_EOL],

Currently, it has caused some trouble on PHP 8.1.24 - emails are not received as the mail server detects multiple 'from' addresses in one mail header because it can't properly split headers by '\n'. I admit I have not really tested what specifically causes the bug - whether it's some configuration, this particular PHP version, or something else (we tested that PHP 8.2 and 8.3 do not cause this issue). However, I have verified that CRLF works correctly. Since it is described as a 'must obey' rule, I am reporting this as a bug. I can also PR it if we have no reason to persist with LF endings. Opinions?

Steps To Reproduce

Not needed imo and hard to do so, based on server config / php version.

Expected Behavior

obey the rfc

Possible Solution

alter line endings during replacements in defaultMailer function

@jarorehu
Copy link

Example of headers related to described bug:

Subject: PHP: An error occurred on the server lk**********5
From: php-lotinfo@10.10.44.37 X-Mailer: Tracy Content-Type: text/plain, charset=UTF-8 Content-Transfer-Encoding: 8bit
Message-Id: <E1sjxJG-006pmM-2M@LK************5.CORP.LOCAL>

PHP 8.2.20 NTS
Tracy 2.10.7

@jarorehu
Copy link

By manual for PHP mail() function: multiple headers should be separated by CRLF.

Successfully tested by pulling headers to separate variable and using CRLF

		$headers = implode("\r\n", [
					'From: ' . ($this->fromEmail ?: "noreply@$host"),
					'X-Mailer: Tracy',
					'Content-Type: text/plain; charset=UTF-8',
					'Content-Transfer-Encoding: 8bit',
		]);
		mail($email, $parts['subject'], $parts['body'], $headers);

I hope replacing line endings by LF is important for body of message.

@dg dg closed this as completed in 00b5060 Oct 4, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants