-
Notifications
You must be signed in to change notification settings - Fork 65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] (PHP8.x - mail()) Notify #1348
Comments
It would also be possible to add the "Message-ID"-Header to also improve mail for e.g. gmail sees it critical.
or use the senders domain:
or something fake:
I don't know how critical a mail provider will see each version.. best regards realizelol |
Thanks for your suggestions We can simplify this since any new code will only be run on PHP 8:
But I am unclear what we are trying to solve with these changes? When I run this exact command in 6.12.0-rc8, it sends the email just fine:
I am using |
I've just updated to stable Release 6.12, but the error still exist. /usr/local/emhttp/plugins/dynamix/scripts/notify -b -e "Test" -s "Test Subject" -i normal -d "Hello this is the short message." -m "This is the long message\nYes here is line two of the long message\n...long three."
ssmtp: 554 For explanation visit https://postmaster.gmx.net/en/case?c=hi&i=ip This error should be related to the incorrect end of lines for the headers part.
Message-Id header is complained by rspamd:
A spam-score of 2.5 is a relatively big deal, as 6 (add_header) is the default spam score: After that I did a google research and it showed up that there are also some errors with gmail after some debug - on another os:Maybe there's an issue with the actual php-cli package. I've tried the same php file on a LinuxMint and I get more or modified lines:
Message-ID + X-Provags-ID + X-Spam-Flag + UI-OutboundReport (headers) will be added to the body message. So normally the Message-ID header is added by the mailprovider, so it's not needed to be added by ourself. If not adding "\n" in front of $message the message also will be seen as header. So if adding "Subject: ..." in the message, my mail provider shows this error 554. https://postmaster.gmx.net/en/case?c=hi&i=ip -> Because I am sending two Subject headers. the tested phpfile: <?php
$message = "Line 1\r\nLine 2\r\nSubject: Line 3\r\nLoremipsumdolorsitametconsetetursadipscingelitrseddiamnonumyeirmodtemporinviduntutlaboreetdoloremagnaaliquyameratseddiam";
$message = wordwrap($message, 70, "\r\n", true);
$subject = "Test 123";
$from = "[email protected]";
$to = "[email protected]";
$headers = array(
'From' => '[email protected],
'Reply-To' => '[email protected]',
'X-Mailer' => 'PHP/' . phpversion()
);
mail($to, $subject, "\n".$message, $headers);
?> Edit: |
I've tested on a clean testing environment (6.12.0-rc2) these versions php7.4.27 with libsodium 1.0.18: and the error is gone. |
I've tested in a slackware-15.0 environment and got the same error. But I figured out that php mail will do some crazy stuff:
I think the extra empty line to the first row will break adding headers by the mail provider. Long headers field: https://datatracker.ietf.org/doc/html/rfc5322#section-2.2.3 Removing the last char of body e.g. test.txt:
Maybe gmail is not yet that restrictive as gmx actually is, but I think it should be too: The test message will add "Subject: Notification" to the body text: So it's definitively not a bug in unraid / webgui, sorry. But I will let this ticket open until I got a working solution or bug fix by the php maintainer. |
SSMTP isn't understanding the new output with CRLF of mail() since php8.0. piping the mail() output through sed (remove \r - CR LineEndings) will work: Or just use the new php option to the php.ini:
if ssmtp ever fix their behaviour we could remove the line. Source: But also remove #L71: and line #L86: These empty lines aren't needed. But |
Thanks for reporting this. It works fine with gmail, but I was able to reproduce the issue using smtp.mail.com. Working on a fix. |
In your testing, is this enough to solve the problem? Or do we need to modify the code to remove the blank line from headers? If code changes are needed, I'm thinking we should go all the way and pass an associative array of headers so that PHP handle all the line endings internally. But I'd rather hold that larger change for the next major release so it can get wider testing before being deployed. |
In my testing adding the line Also it's not necessary to edit the end of lines whether in headers nor in message body. As per specification the correct line ending for mail is "\r\n" CRLF. It's converted to CRLF by ssmtp - but it needs it's input in "\n" LF like some other MTA's, so we need the old line endings - like in php7.4 - style "\n". This are the corresponding lines to the php setting
I hope this will clarify your doubts otherwise feel free to ask me again. It even took me 3 weeks to debug and understand. |
OK I think we are both saying the same thing :) So php.ini in |
This was fixed in 6.12.2 |
Hi Limetech,
PHP8.x uses the correct line endings in mail's headers [ "\r\n" (CRLF) ] or maybe ssmtp awaits it.
Here's more info about that on php: php/php-src#8086
$line_break = (PHP_VERSION_ID < 80000) ? "\n" : "\r\n";
:This will check if php version is less than 8.0 if so use "\n" else use "\r\n".
$headers[] = "";"
:Remove newline in headers. Instead add this to the first line in body:
$body[] = "";
:Was added because otherwise the $body[] "Subject:" could also being interpreted as header.
$body = implode("\n", $body);
:Implode newlines into one string to a variable, so it can be wrapped by the next command:
$body = wordwrap($body, 70);
$headers = implode($line_break, $headers);
Don't need to be a variable but there's the
$line_break
which is needed in PHP8/SSMTP on Unraid 6.12.return mail($to, $subj, $body, $headers);
:Return only variables.
I actually using this method in these two scripts:
/usr/local/emhttp/webGui/scripts/notify
or (symlink)
/usr/local/emhttp/plugins/dynamix/scripts/notify
otherwise the malformed header may result in error 554 by mail provider (e.g. https://postmaster.gmx.net/en/case?c=hi&i=ip):
Affected function in file between line 52 and 88:
https://github.com/limetech/webgui/blob/master/emhttp/plugins/dynamix/scripts/notify#L52-L88
While WebGUI actually seems to working fine. The CLI isn't working - just give it a try by e.g.:
best regards
realizelol
The text was updated successfully, but these errors were encountered: