Problems with emails on PHP8.0

Started by @rjen, October 10, 2022, 05:24:37 PM

Previous topic - Next topic

@rjen

SMF version 2.1.2
PHP version: 8.0

After we switched our forum to PHP8.0 we encountered problems with activation emails not being delivered to gmail accounts.

Error messages in undeliverable mails:
Diagnostic-Code: smtp; 550 5.7.1 [141.138.168.75] Messages with multiple
 addresses in From: header are not accepted.

After digging through mail headers I finally found the issue went away when switching the server back to PHP7.4

I compared the mails sent by the forum between 7.4 and 8.0 and found that somehow the mail headers under PHP 8.0 are built up incorrectly.

This is what is sent on PHP8 and causes mails to be rejected

To: [email protected]
Subject: Welkom op FJR-club Testforum
From: "FJR-club Testforum" <[email protected]>
 Return-Path: [email protected]
 Date: Mon, 10 Oct 2022 20:06:09 -0000
 Message-ID: <[email protected]>
 X-Mailer: SMF
 Mime-Version: 1.0
 content-type: multipart/alternative; boundary="SMF-2254e6435a0e2eef16bd16a70652664a"
 content-transfer-encoding: 7bit

This is the same acivation email sent on PHP7.4

To: [email protected]
Subject: Welkom op FJR-club Testforum
From: "FJR-club Testforum" <[email protected]>
X-ASG-Orig-Subj: Welkom op FJR-club Testforum
Date: Mon, 10 Oct 2022 20:21:46 -0000
Message-ID: <[email protected]>
X-Mailer: SMF
Mime-Version: 1.0
content-type: multipart/alternative; boundary="SMF-10505cf36a673b691f8c3d042ee7e465"
content-transfer-encoding: 7bit

As it seems the return path is in a completely different place in both headers.

As shown below the 8.0 version somehow mies more elements in the From: section...
The yellow highlighted part is not supposed to be in the From:...

You cannot view this attachment.

This seems prettu consistent: switch to PHP8.0 and it breaks, switch back and it works as it should.
No mods that seem to be influencing this...
 
Running SMF 2.1 with latest TinyPortal at www.fjr-club.nl

shawnb61

Thanks for this writeup, very helpful.

I am going to move this to the Bug Reports board.  Feels like a bug.
Address the process rather than the outcome.  Then, the outcome becomes more likely.   - Fripp

@rjen

It feels like that to me too, I am wondering if it can be confirmed as such? I also noticed that test emails from the forum are affected, so it seems it is a pretty considerable issue.

Anyone else experiencing the same?
Running SMF 2.1 with latest TinyPortal at www.fjr-club.nl


@rjen

Quote from: Shambles on October 11, 2022, 09:30:14 AMhttps://www.simplemachines.org/community/index.php?topic=583589.msg4134897#msg4134897

See if that helps

It does...

I changed the code and uploaded the file. Then upped PHP to 8.0 again and requested a new activation mail and the mail now arrives as it should...

The mail header now is as it was before:
To: [email protected]
Subject: Welkom op FJR-club Testforum
From: "FJR-club Testforum" <[email protected]>
X-ASG-Orig-Subj: Welkom op FJR-club Testforum
Date: Tue, 11 Oct 2022 16:48:19 -0000
Message-ID: <[email protected]>
X-Mailer: SMF
Mime-Version: 1.0
content-type: multipart/alternative; boundary="SMF-6cc05b62d0db93fdf1228a2f173e1d0d"
content-transfer-encoding: 7bit

Still seem to be some sort of bug, because the standard code only fails on PHP8.0
Running SMF 2.1 with latest TinyPortal at www.fjr-club.nl

shawnb61

@@rjen  - Were you running mail as PHP or as SMTP?
Address the process rather than the outcome.  Then, the outcome becomes more likely.   - Fripp

@rjen

PHP, have been for 10 years now
Running SMF 2.1 with latest TinyPortal at www.fjr-club.nl

Shambles

Quote from: @rjen on October 11, 2022, 12:56:56 PMStill seem to be some sort of bug, because the standard code only fails on PHP8.0

Got some spare minutes? Seems to be caused by a change to mail() in PHP8+:

https://github.com/php/php-src/issues/8086

I'd recommend SMF devops change the Subs-Post.php script to that which I linked to, above. Seems to work in all cases, not just to a gsmtp target.

shawnb61

Quote from: Shambles on October 11, 2022, 02:58:31 PM
Quote from: @rjen on October 11, 2022, 12:56:56 PMStill seem to be some sort of bug, because the standard code only fails on PHP8.0

Got some spare minutes? Seems to be caused by a change to mail() in PHP8+:

https://github.com/php/php-src/issues/8086

I'd recommend SMF devops change the Subs-Post.php script to that which I linked to, above. Seems to work in all cases, not just to a gsmtp target.

I was just reading that! 

Interesting that the php guys now say that using windows line endings are required even on linux systems...  Lots of pushback from linux folks - that bug is referenced everywhere.  But the php guys are saying "read the RFC..."
Address the process rather than the outcome.  Then, the outcome becomes more likely.   - Fripp

shawnb61

So the problem is specific to:
 - PHP 8+
 - Unix only (Windows not affected, it's already crlf...)
 - Mail type of PHP only (SMTP not affected)

I have tested Shambles's fix on linux, & it seems to work fine, even on PHP 7x, and on SMTP configurations.

Haven't explicitly tested windows yet...  But it should be fine of course, it's already crlf....  (But I'll test anyway because I'm paranoid...)
Address the process rather than the outcome.  Then, the outcome becomes more likely.   - Fripp

live627


shawnb61

Address the process rather than the outcome.  Then, the outcome becomes more likely.   - Fripp

shawnb61

Quote from: live627 on October 11, 2022, 08:53:53 PMit uses SMTP on Windows

While testing on Windows, with PHP selected as the mail type, it called the PHP mail() function, not smtp_mail()...
Address the process rather than the outcome.  Then, the outcome becomes more likely.   - Fripp

@rjen

Quote from: shawnb61 on October 11, 2022, 08:54:37 PMTests completed, PR submitted:
https://github.com/SimpleMachines/SMF/pull/7560

Thanks, @@rjen & @Shambles !

You're welcome. Just a thought: won't that change have a negative impact on forums that are using php mail and are still in PHP7.x?
Running SMF 2.1 with latest TinyPortal at www.fjr-club.nl

shawnb61

I tested all of those combinations.  Everything looked good.
Address the process rather than the outcome.  Then, the outcome becomes more likely.   - Fripp

shawnb61

On second thought, yeah, I tweaked the PR.  Best to play it safe & leave 7x as-is...
Address the process rather than the outcome.  Then, the outcome becomes more likely.   - Fripp

Chen Zhen

Good job with troubleshooting this issue.
SMF 2.0.19 will also need this applied with its next patch.

PHP 7.4 is EOL and will only get security updates for another month.
With that said IMO a patch for SMF 2.0.19 & an official update to SMF 2.1.X should be rolled out sooner than later.

ref.
https://www.php.net/supported-versions.php

My SMF Mods & Plug-Ins

WebDev

"Either you repeat the same conventional doctrines everybody is saying, or else you say something true, and it will sound like it's from Neptune." - Noam Chomsky

shawnb61

Address the process rather than the outcome.  Then, the outcome becomes more likely.   - Fripp

Advertisement: