Make WordPress Core


Ignore:
Timestamp:
10/21/2025 08:04:22 AM (8 weeks ago)
Author:
dmsnell
Message:

wp_mail(): Set sender address by default.

WordPress has been calling $phpmailer->setFrom() with a false value for an attribute telling it to set the sender address for each message. This sender address is also known by other names: Envelope-From, MAIL FROM, Return-Path, etc... Unfortunately, this configuration can easily lead to mail being rejected by numerous mail hosts due to an invalid domain being generated by the local mail server/MTA.

The flag was originally added with the note that its absence “causes outgoing email to fail on some server environments.” However, it is likely that this led to the opposite effect, as evidenced by numerous reports, plugins, and workarounds over the years.

In this patch the flag is being removed, which has the effect of letting $phpmailer set the Sender value, which it does by default using the domain “where the front end is accessible” and which is is likely correct.

After this change there is a chance of mail failure for sites with SPF configured but which does not allow mail to be sent on behalf of this domain and if those sites also do not have a properly configured DKIM and DMARC setup. Those sites should review their SPF policies or the wp_mail_from filter.

Developed in https://github.com/WordPress/wordpress-develop/pull/9412
Discussed in https://core.trac.wordpress.org/ticket/49687

Follow-up to [38286].

Props cbutlerjr, dmsnell, jamieburchell, knutsp, kub1x, lordandy1984, piskvorky, SergeyBiryukov, siliconforks, SirLouen, stankea, vbbp, websupporter.

Fixes #49687.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/pluggable.php

    r60989 r61010  
    433433
    434434        try {
    435             $phpmailer->setFrom( $from_email, $from_name, false );
     435            $phpmailer->setFrom( $from_email, $from_name );
    436436        } catch ( PHPMailer\PHPMailer\Exception $e ) {
    437437            $mail_error_data                             = compact( 'to', 'subject', 'message', 'headers', 'attachments' );
Note: See TracChangeset for help on using the changeset viewer.