Make WordPress Core

Opened 12 days ago

Last modified 12 days ago

#49687 new defect (bug)

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: 2nd-opinion has-patch dev-feedback
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 (https://www.php.net/manual/en/function.mail.php) 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 https://core.trac.wordpress.org/browser/trunk/src/wp-includes/pluggable.php?rev=47494#L358).

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

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


Change History (1)

#1 @vbbp
12 days ago

Btw, a quick fix is the installation of the plugin provided at https://www.webdezign.co.uk/avoid-wordpress-emails-ending-spam-folder/, but the obvious question remains whether and why the envelope sender is on purpose NOT set.

Note: See TracTickets for help on using tickets.