Make WordPress Core

Opened 23 months ago

Last modified 4 months ago

#49687 new enhancement

wp_mail() - Why is no envelope sender defined?

Reported by: vbbp Owned by:
Milestone: Awaiting Review Priority: normal
Severity: minor Version: 5.4
Component: Mail Keywords: dev-feedback needs-testing
Focuses: Cc:


As just figured out, some (mail) servers require the envelope sender to be set in order to accept outgoing emails.

For the PHP built-in mail() function ( this can be done using the additional parameter (e.g. "-fwebmaster@…) as explained in example 4 of the PHP manual page.

In order to use that option and set the envelope sender in PHPmailer either the sender attribute of the phpmailer object needs to be set ($phpmailer->Sender = "sender@…") or when using the setFrom() method of PHPmailer, the 3rd parameter needs to be set to true (=default).

Unfortunately, the current implementation of wp_mail() explicitly sets that 3rd parameter to false, which prevents the envelope sender from being set (see

Is there any reason for doing so and could we change L358 to

$phpmailer->setFrom( $from_email, $from_name, true );


Change History (8)

#1 @vbbp
23 months ago

Btw, a quick fix is the installation of the plugin provided at, but the obvious question remains whether and why the envelope sender is on purpose NOT set.

#2 @vbbp
20 months ago

  • Keywords needs-testing added; 2nd-opinion has-patch removed

#3 @cbutlerjr
18 months ago

  • Type changed from defect (bug) to enhancement

It's quite likely that a suggestion of this nature would be that "this is plugin territory." wp_mail() is a pluggable function, and if it was necessary in a given instance, then you could implement a plugged version of the function.

I would agree, though that it's worth a review. But the other thing to consider is that WP 5.5. is including an upgrade to phpMailer. So it might be something that needs to be looked at in the course of that improvement.

#4 @SergeyBiryukov
17 months ago

#51206 was marked as a duplicate.

#5 in reply to: ↑ description @SergeyBiryukov
17 months ago

Hi there, welcome to WordPress Trac! Thanks for the report.

Replying to vbbp:

Unfortunately, the current implementation of wp_mail() explicitly sets that 3rd parameter to false, which prevents the envelope sender from being set (see

Just noting that this was an intentional change in [38286] / #37736.

#6 follow-up: @lordandy1984
17 months ago

Not sure why this was added, because both options might cause issues on some environments (although I would stick with the PhpMailer default).

So the only solution is to use the phpmailer-init action in a small plugin?

add_action( 'phpmailer_init', 'xyz_add_phpmailer_setfrom' );

function xyz_add_phpmailer_setfrom( $phpmailer ) {
    'My Sender' // From name.

#7 in reply to: ↑ 6 @piskvorky
8 months ago

Also bitten by this. I tracked DMARC failures down to this "feature" where envelope sender is not set properly in wp_mail.

FWIW, a return to the default setFrom value (true) would fix the issue for us. That "intentional change" to false in probably broke more things than helped.

Most people wouldn't be aware that the emails they're sending out from Wordpress are broken, and that some action (a plugin) is needed. This true=>false change alone, five years ago, must have contributed to the online noise in global email tremendously.

Last edited 8 months ago by piskvorky (previous) (diff)

#8 @jamieburchell
4 months ago

Just wanted to add myself to the list of people who can't fathom why this intentional change was made to purposely alter PHPMailer's default by not setting the envelope sender.

Reading through the other thread, the gist seems to be "because it breaks some server setups" but it doesn't make sense not to set the proper headers.

I have full control over the server/postfix setup I use to host my WordPress projects, with sender dependent relay and authentication settings. Without the proper envelope sender, the default (wrong) hostname is used.

To please everyone, why not add the from address/name/envelope sender fields to the WordPress settings area?

Note: See TracTickets for help on using tickets.