diff --git a/src/wp-includes/pluggable.php b/src/wp-includes/pluggable.php index 1dbac5e1d707c..cb118be41c4b1 100644 --- a/src/wp-includes/pluggable.php +++ b/src/wp-includes/pluggable.php @@ -406,7 +406,7 @@ function wp_mail( $to, $subject, $message, $headers = '', $attachments = array() $from_name = apply_filters( 'wp_mail_from_name', $from_name ); try { - $phpmailer->setFrom( $from_email, $from_name, false ); + $phpmailer->setFrom( $from_email, $from_name ); } catch ( PHPMailer\PHPMailer\Exception $e ) { $mail_error_data = compact( 'to', 'subject', 'message', 'headers', 'attachments' ); $mail_error_data['phpmailer_exception_code'] = $e->getCode(); diff --git a/tests/phpunit/tests/pluggable/wpMail.php b/tests/phpunit/tests/pluggable/wpMail.php index 7b88d739add22..f3254d26d15ae 100644 --- a/tests/phpunit/tests/pluggable/wpMail.php +++ b/tests/phpunit/tests/pluggable/wpMail.php @@ -408,21 +408,18 @@ public function test_wp_mail_addresses_arent_encoded() { } /** - * Test that the Sender field in the SMTP envelope is not set by Core. + * Test that the Sender field in the SMTP envelope is set by Core. * - * Correctly setting the Sender requires knowledge that is not available - * to Core. An incorrect value will often lead to messages being rejected - * by the receiving MTA, so it's the admin's responsibility to - * set it correctly. + * A missing Sender field can lead to messages failing DMARC SPF checks. * - * @ticket 37736 + * @ticket 49687 */ - public function test_wp_mail_sender_not_set() { - wp_mail( 'user@example.org', 'Testing the Sender field', 'The Sender field should not have been set.' ); + public function test_wp_mail_sender_set() { + wp_mail( 'user@example.org', 'Testing the Sender field', 'The Sender field should have been set.' ); $mailer = tests_retrieve_phpmailer_instance(); - $this->assertSame( '', $mailer->Sender ); + $this->assertSame( 'wordpress@example.org', $mailer->Sender ); } /**