Simple Machines Community Forum

SMF Development => Bug Reports => Fixed or Bogus Bugs => Topic started by: @rjen on October 10, 2022, 05:24:37 PM

Title: Problems with emails on PHP8.0
Post by: @rjen on October 10, 2022, 05:24:37 PM
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:...

2022-10-10_232200.jpg

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...
 
Title: Re: Problems with emails on PHP8.0
Post by: shawnb61 on October 10, 2022, 05:49:28 PM
Thanks for this writeup, very helpful.

I am going to move this to the Bug Reports board.  Feels like a bug.
Title: Re: Problems with emails on PHP8.0
Post by: @rjen on October 11, 2022, 03:07:23 AM
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?
Title: Re: Problems with emails on PHP8.0
Post by: Shambles on October 11, 2022, 09:30:14 AM
https://www.simplemachines.org/community/index.php?topic=583589.msg4134897#msg4134897

See if that helps
Title: Re: Problems with emails on PHP8.0
Post by: @rjen on October 11, 2022, 12:56:56 PM
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
Title: Re: Problems with emails on PHP8.0
Post by: shawnb61 on October 11, 2022, 01:59:36 PM
@@rjen  - Were you running mail as PHP or as SMTP?
Title: Re: Problems with emails on PHP8.0
Post by: @rjen on October 11, 2022, 02:34:55 PM
PHP, have been for 10 years now
Title: Re: Problems with emails on PHP8.0
Post by: 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.
Title: Re: Problems with emails on PHP8.0
Post by: shawnb61 on October 11, 2022, 03:04:39 PM
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..."
Title: Re: Problems with emails on PHP8.0
Post by: shawnb61 on October 11, 2022, 04:43:31 PM
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...)
Title: Re: Problems with emails on PHP8.0
Post by: live627 on October 11, 2022, 08:53:53 PM
it uses SMTP on Windows
Title: Re: Problems with emails on PHP8.0
Post by: shawnb61 on October 11, 2022, 08:54:37 PM
Tests completed, PR submitted:
https://github.com/SimpleMachines/SMF/pull/7560

Thanks, @@rjen & @Shambles !
Title: Re: Problems with emails on PHP8.0
Post by: shawnb61 on October 11, 2022, 09:07:34 PM
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()...
Title: Re: Problems with emails on PHP8.0
Post by: @rjen on October 12, 2022, 01:20:07 AM
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?
Title: Re: Problems with emails on PHP8.0
Post by: shawnb61 on October 12, 2022, 01:27:07 AM
I tested all of those combinations.  Everything looked good.
Title: Re: Problems with emails on PHP8.0
Post by: shawnb61 on October 12, 2022, 09:16:45 PM
On second thought, yeah, I tweaked the PR.  Best to play it safe & leave 7x as-is...
Title: Re: Problems with emails on PHP8.0
Post by: Chen Zhen on October 16, 2022, 12:31:06 AM
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
Title: Re: Problems with emails on PHP8.0
Post by: shawnb61 on November 25, 2022, 03:22:19 PM
Fixed in 2.1.3.