Skip to content

Commit 1885bee

Browse files
committed
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 #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. git-svn-id: https://develop.svn.wordpress.org/trunk@61010 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 4e64b4a commit 1885bee

File tree

2 files changed

+7
-10
lines changed

2 files changed

+7
-10
lines changed

src/wp-includes/pluggable.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ function wp_mail( $to, $subject, $message, $headers = '', $attachments = array()
432432
$from_name = apply_filters( 'wp_mail_from_name', $from_name );
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' );
438438
$mail_error_data['phpmailer_exception_code'] = $e->getCode();

tests/phpunit/tests/pluggable/wpMail.php

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -408,21 +408,18 @@ public function test_wp_mail_addresses_arent_encoded() {
408408
}
409409

410410
/**
411-
* Test that the Sender field in the SMTP envelope is not set by Core.
411+
* Test that the Sender field in the SMTP envelope is set by Core.
412412
*
413-
* Correctly setting the Sender requires knowledge that is not available
414-
* to Core. An incorrect value will often lead to messages being rejected
415-
* by the receiving MTA, so it's the admin's responsibility to
416-
* set it correctly.
413+
* A missing Sender field can lead to messages failing DMARC SPF checks.
417414
*
418-
* @ticket 37736
415+
* @ticket 49687
419416
*/
420-
public function test_wp_mail_sender_not_set() {
421-
wp_mail( '[email protected]', 'Testing the Sender field', 'The Sender field should not have been set.' );
417+
public function test_wp_mail_sender_set() {
418+
wp_mail( '[email protected]', 'Testing the Sender field', 'The Sender field should have been set.' );
422419

423420
$mailer = tests_retrieve_phpmailer_instance();
424421

425-
$this->assertSame( '', $mailer->Sender );
422+
$this->assertSame( '[email protected]', $mailer->Sender );
426423
}
427424

428425
/**

0 commit comments

Comments
 (0)