Opened 6 months ago
Closed 11 hours ago
#65415 closed defect (bug) (wontfix)
WordPress 7.0 inclusion of PHPMailer 7.0.2 breaks .user.ini override of sendmail_from
| Reported by: | gmariani405 | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | Version: | 7.0 | |
| Severity: | critical | Keywords: | close |
| Cc: | Focuses: |
Description
I have created a ticket on PHPMailer here: https://github.com/PHPMailer/PHPMailer/issues/3342
But the gist is, the recent patch in PHPMailer 7.0.2 prevents the .user.ini from overriding an existing -f flag in the sendmail command. Which prevents sites from fixing the incorrect domain on certain hosts (like Nexcess/LiquidWeb) and causing all mail to no longer be deliverable. I have a workaround for now with this simple patch, but ideally PHPMailer needs to be fixed in order to allow the flexibility to override the default sendmail command.
Here is my workaround:
<?php add_action('phpmailer_init', function ($phpmailer) { $phpmailer->isSendmail(); $sendmail_from_value = ini_get('sendmail_from'); if (empty($sendmail_from_value)) return; $phpmailer->Sender = $sendmail_from_value; }, 999);
Attachments (4)
Change History (19)
This ticket was mentioned in Slack in #core by abdullahramzan. View the logs.
6 months ago
#4
@
5 months ago
- Milestone 7.0.1 → 7.0.2
As the RC for WP 7.0.1 is expected to land tomorrow we'll have to punt this to 7.0.2.
#6
@
4 months ago
Test Report
Description
Tested the issue where setting sendmail_from via ini_set() or configuration settings (such as .user.ini) is ignored by PHPMailer in WordPress 7.0+, leaving the PHPMailer $Sender property unpopulated.
Environment
- WordPress: 7.1-beta3
- Subdirectory: No
- PHP: 8.4.16
- Server: nginx/1.26.1
- Database: mysqli (Server: 8.0.35 / Client: mysqlnd 8.4.16)
- Browser: Chrome 150.0.0.0
- OS: Windows 10/11
- Theme: Twenty Twenty-Five 1.5
- MU Plugins: None activated
- Plugins:
- Test Reports 1.3.0
- WordPress Beta Tester 4.0.0
Steps taken
- Configured
sendmail_frominwp-config.phpusingini_set('sendmail_from', 'my-email@gmail.com');. - Added a logging hook to
phpmailer_initto record bothini_get('sendmail_from')and$phpmailer->Sender. - Triggered a password reset email via the WordPress login screen.
- Checked the generated debug log to verify properties.
- Issue confirmed:
sendmail_fromcorrectly captures the configured email address, but the PHPMailer Sender property remains empty:
[25-Jul-2026 11:07:29 UTC] PHP sendmail_from: my-email@gmail.com [25-Jul-2026 11:07:29 UTC] PHPMailer Sender property:
Expected result
- When
sendmail_fromis defined in PHP settings, PHPMailer should automatically populate its$Senderproperty with that value so outgoing mail correctly reflects the configured envelope sender.
Actual Results
- Reproduced:
ini_get('sendmail_from')returns the correct address, but PHPMailer leaves$phpmailer->Senderunpopulated.
Additional Notes
- This issue prevents certain hosting environments from overriding default sendmail parameters correctly via
.user.ini.
Screenshots/Screencast with results
- N/A
Support Content
- N/A
#7
@
3 months ago
- Milestone 7.0.3 → 7.2
Since the issue remains unresolved upstream and no WordPress 7.0.3 release is currently planned, I'm moving this to 7.2 for consideration.
#8
follow-up:
↓ 9
@
6 weeks ago
Hi, thanks for the detailed report and the workaround. I was able to reproduce this on trunk, and as far as I can tell it affects every WordPress 7.0.x and 7.1.x release. Below are my reproduction, what I believe causes it, and two possible fixes that I tested locally. I'd really appreciate feedback on which direction makes sense.
In short
Every email has an envelope sender (shown as Return-Path). Receiving mail servers check that it belongs to the sender's domain; when it doesn't, the email can be rejected or marked as spam.
On some hosts, the server is set up to always send with the host's own address (for example postmaster@random.nxcli.io). Site owners fix this by setting sendmail_from in .user.ini, and up to WordPress 6.9 their emails then went out with the site's address.
Since WordPress 7.0, that setting is ignored on these hosts, so emails go out with the host's address again.
Environment
- WordPress: 7.2-alpha-63166-src (trunk @ da764706f), bundled PHPMailer 7.1.1
- PHP: 8.5.3
- Server: nginx 1.26.1, PHP-FPM
- Database: MySQL 8.4.0
- Mail: Mailpit 1.24.1 as the
sendmailprogram. Like the qmail setup in the ticket description, it uses the last-fit receives.
Steps to reproduce
- In the server's PHP configuration (PHP-FPM pool or
php.ini, which sites can't change), add a-fwith a host address:sendmail_path = "/path/to/sendmail -t -i -f postmaster@host.example"
- In the site's
.user.ini:sendmail_from = me@site.example
- Trigger any WordPress email, for example Lost your password? on the login screen.
- Check the
Return-Pathof the email that was sent.
Results
| WordPress code | Bundled PHPMailer | Return-Path | Expected |
|---|---|---|---|
| trunk | 7.1.1 | postmaster@host.example ❌ | me@site.example
|
trunk, with only wp-includes/PHPMailer/PHPMailer.php replaced by the copy from 6.9.4 | 7.0.0 | me@site.example ✅ | me@site.example
|
Only the PHPMailer file differs between the two runs, so I believe the change in behaviour comes from the PHPMailer update.
Trunk (PHPMailer 7.1.1), the host's address is used:
The same email with PHPMailer 7.0.0, as bundled in 6.9.x, uses the site's address:
The sendmail command that PHPMailer runs, recorded with a stand-in program:
| Bundled PHPMailer | Command |
|---|---|
| 7.0.0 (WordPress 6.9.x) | sendmail -t -i -f postmaster@host.example -fme@site.example ✅
|
| 7.0.2 (WordPress 7.0.x) | sendmail -t -i -f postmaster@host.example ❌
|
| 7.1.1 (WordPress 7.1.x, trunk) | sendmail -t -i -f postmaster@host.example ❌
|
Affected versions
| WordPress | Bundled PHPMailer | Affected |
|---|---|---|
| 6.9.0 – 6.9.10 | 7.0.0 | No |
| 7.0.0 – 7.0.7 | 7.0.2 | Yes |
| 7.1.0 – 7.1.3 | 7.1.1 | Yes |
| trunk | 7.1.1 | Yes |
What happens, step by step
As far as I understand the code:
wp_mail()sends with PHP'smail()(pluggable.phpline 511) and does not set an envelope sender itself (setFrom( $from_email, $from_name, false ), line 455).- PHPMailer copies
sendmail_frominto itsSenderproperty (PHPMailer.phpline 2114). - PHPMailer then adds
-fwith that address only if the server'ssendmail_pathdoes not already contain-f(line 2118 on trunk, line 2114 on 7.0.x):<?php if (self::isShellSafe($this->Sender) && strpos($phpmailer_path, ' -f') === false) { $params = sprintf('-f%s', $this->Sender); }
- On these hosts it does contain
-f, so$paramsstaysnulland the site's address is never passed on.
Debugger paused at line 2118 during a Lost Password request. In the Watch panel, Sender is me@site.example and isShellSafe() is true, but the host's -f postmaster@host.example is found in sendmail_path, so strpos(...) === false is false, the whole condition is false, and $params stays null:
One step later, execution goes from line 2118 straight to line 2121 (highlighted). Line 2119 (outlined), which would add the site's -f, is skipped:
From what I could find, this check was added in PHPMailer 7.0.2 and came into core with the PHPMailer update. I believe it was meant to prevent a duplicate -f after WordPress started setting a sender by default, which caused "Could not instantiate mail function" on hosts whose sendmail rejects two -f options. WordPress later reverted that change, but the PHPMailer check remains.
- PHPMailer pull request 3283: https://github.com/PHPMailer/PHPMailer/pull/3283
- The changed line in that pull request: https://github.com/PHPMailer/PHPMailer/pull/3283/changes#diff-7f9ff1e59fad629c10da93f0d676eadc5ec86634c576f9852a41e8dba6f8afadL2065-R2114
- Changeset 61468, PHPMailer 7.0.2 in core: https://core.trac.wordpress.org/changeset/61468
- Changeset 61010, sender set by default: https://core.trac.wordpress.org/changeset/61010
- Ticket 64368, "Could not instantiate mail function": https://core.trac.wordpress.org/ticket/64368
- Changeset 61537, revert of 61010: https://core.trac.wordpress.org/changeset/61537
Additional findings
- A sender set by a plugin is ignored too. With the same server setup and no
.user.ini, a plugin that sets$phpmailer->Sender = 'bounce@site.example'inphpmailer_initgets-fbounce@site.examplewith PHPMailer 7.0.0, but only the host's-fwith 7.0.2 and 7.1.1. - Hosts without
-finsendmail_pathare not affected.sendmail_fromstill results in-fme@site.examplethere. - The workaround from the description works on trunk. Switching to
isSendmail()and settingSenderresults insendmail -fme@site.example -i -t.
Proposal
I tried two possible fixes locally. For each one, I stepped through a Lost Password request with Xdebug and checked the Return-Path in Mailpit. Both gave me@site.example. I also ran the other cases (no host -f, no site sender, the same address on both sides), and those behaved as they do on trunk today.
Option 1: fix it in PHPMailer, then update the bundled library in core
In mailSend(), PHPMailer would skip its own -f only when sendmail_path already passes the same address, instead of skipping it whenever there is any -f:
-f in sendmail_path | Sender set by the site | Command |
|---|---|---|
| none | me@site.example | -fme@site.example (unchanged)
|
postmaster@host.example | not set | no extra -f (unchanged)
|
postmaster@host.example | postmaster@host.example | no extra -f (no duplicate)
|
postmaster@host.example | me@site.example | -f postmaster@host.example -fme@site.example (as in 6.9)
|
- I believe this is the cleanest place for the fix, since the change in behaviour came from PHPMailer. Upstream issue: https://github.com/PHPMailer/PHPMailer/issues/3342
- As far as I understand, on hosts whose
sendmailrejects two-foptions, a site that sets a different address would get "Could not instantiate mail function" again, as it did in 6.9 and earlier. Since changeset 61537, WordPress no longer sets a sender by default, so I think this would only affect sites that set one themselves. - It depends on a new PHPMailer release, and the timing may be tight for 7.2.
Option 2: handle it in core, in WP_PHPMailer
WP_PHPMailer::preSend() would check, before the message is built, whether sendmail_path already contains -f and the site has set a different sender (through sendmail_from or Sender). Only in that case, it would switch to isSendmail() and keep the site's sender. This is what the workaround in the description does, done by core. The resulting command has a single -f:
/path/to/sendmail -fme@site.example -i -t
- It doesn't change the bundled PHPMailer files, and it could be removed once PHPMailer handles this itself.
- With only one
-f, I believe it also works on hosts whosesendmailrejects two-foptions. - From what I saw while debugging, the switch has to happen before
parent::preSend(). When sending withmail(), PHPMailer leaves the To and Subject headers out of the message it builds (mail()adds them). Switching later, inmailSend(), would send an email without them. - For the affected sites only, emails would be sent by PHPMailer running the program directly instead of through PHP's
mail(), so PHP settings such asmail.logandmail.add_x_headerwould not apply to them. It would be skipped whenpopen()is disabled, or whensendmail_pathdoesn't containsendmail(for example ssmtp or msmtp), so those hosts would stay as they are today. - As I understand comment 3, the fix was expected to come with an upstream release, so I'd only suggest this if a core-side change is acceptable: https://core.trac.wordpress.org/ticket/65415#comment:3
Feedback
I'd appreciate guidance on which direction is preferred:
- Option 1 only: I'd propose the change upstream with tests, and core would pick it up with a PHPMailer update.
- Option 2 for 7.2: I can attach a patch with unit tests here.
- Both: option 2 in core for now, and option 1 upstream so the core code can be removed later.
Please let me know if I've misunderstood anything, or if you'd like me to test other setups.
#9
in reply to: ↑ 8
@
6 weeks ago
Replying to sirakashaman:
I'd appreciate guidance on which direction is preferred:
- Option 1 only: I'd propose the change upstream with tests, and core would pick it up with a PHPMailer update.
- Option 2 for 7.2: I can attach a patch with unit tests here.
- Both: option 2 in core for now, and option 1 upstream so the core code can be removed later.
Personally I much prefer Option 1.
Option 2 sounds like it might not be safe for some server configurations.
#10
follow-up:
↓ 11
@
6 weeks ago
- Keywords close added; dev-feedback 2nd-opinion removed
As I explain here I'm more inclined to close this. The fix that @gmariani405 provided using the phphmailer_init hook with the isSendmail method is the perfect way to fix this edge case.
Proposing close for the 7.2 review.
What do you think, @siliconforks ?
#11
in reply to: ↑ 10
@
6 weeks ago
Replying to SirLouen:
Proposing
closefor the 7.2 review.
What do you think, @siliconforks ?
I certainly don't think there should be any changes in WordPress regarding this issue. So I'm fine with closing this.
For upstream PHPMailer - it's basically a question of whether PHPMailer wants to:
- Forbid multiple
-foptions (the current behavior) - Allow multiple
-foptions (basically reverting https://github.com/PHPMailer/PHPMailer/pull/3283 entirely) - Allow multiple
-foptions in some cases but not others (this sounds like what @sirakashaman is proposing in "Option 1" above). That might be a viable approach - but that's something that would have to be decided upstream in PHPMailer.
This ticket was mentioned in Slack in #core by im3dabasia1. View the logs.
5 days ago
#13
@
5 days ago
As per the pre-RC1 7.2 bug scrub: the discussion leans towards closing, since a workaround exists. @gmariani405, any objection?
#14
@
5 days ago
After reading both the WordPress ticket and the PHPMailer ticket, both seem in favor of just using my workaround as the official solution. Can't say that was what I was hoping for since this change broke all the sites I host (and most likely any site on nexcess/liquidweb at the time). But i realize that's still considered an edge-case in the scheme of things. I'm not familiar enough with PHPMailer to have a stronger opinion here so I'll defer to the teams judgement here. Thanks for considering my request.




Putting in the 7.0.1 milestone for tracking, but fixing this will be dependent on an upstream release