Opened 4 years ago
Last modified 22 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: | Keywords: | dev-feedback needs-testing | |
Focuses: | Cc: |
Description
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 (10)
#3
@
4 years 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.
#5
in reply to:
↑ description
;
follow-up:
↓ 9
@
4 years 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 https://core.trac.wordpress.org/browser/trunk/src/wp-includes/pluggable.php?rev=47494#L358).
Just noting that this was an intentional change in [38286] / #37736.
#6
follow-up:
↓ 7
@
4 years 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?
<?php add_action( 'phpmailer_init', 'xyz_add_phpmailer_setfrom' ); function xyz_add_phpmailer_setfrom( $phpmailer ) { $phpmailer->setFrom( 'mysender@example.com', 'My Sender' // From name. ); }
#7
in reply to:
↑ 6
@
3 years 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 https://core.trac.wordpress.org/changeset/38286 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.
#8
@
3 years 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?
#9
in reply to:
↑ 5
@
3 years ago
Replying to SergeyBiryukov:
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 https://core.trac.wordpress.org/browser/trunk/src/wp-includes/pluggable.php?rev=47494#L358).
Just noting that this was an intentional change in [38286] / #37736.
Without the envelope sender being set (falling back to some default value), the requests are being rejected. Namely "sezman.cz" and "ovh.net" SMTP servers do reject those messages (log line below). Gmail won't look at the envelope sender and gladly accept the header from the message header.
Mar 10 10:36:52 localhost sm-mta[1763825]: 229JUjTK112345: to=<myemailaddress@seznam.cz>, ctladdr=<www-data@localhost.localdomain> (33/33), delay=14:06:07, xdelay=00:00:00, mailer=esmtp, pri=7770908, relay=mx2.seznam.cz., dsn=4.0.0, stat=Deferred: 451 4.4.8 Unroutable email address.
To me it causes just more harm. Only harm to be correct ;) Removing the false fixes everything in my case. But still have to go with coding it into plugin using the phpmailer_init action to keep the change permanent...
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.