diff --git a/src/wp-includes/pluggable.php b/src/wp-includes/pluggable.php index 511e6acac6..5c7747774b 100644 --- a/src/wp-includes/pluggable.php +++ b/src/wp-includes/pluggable.php @@ -349,7 +349,7 @@ function wp_mail( $to, $subject, $message, $headers = '', $attachments = array() */ $from_name = apply_filters( 'wp_mail_from_name', $from_name ); - $phpmailer->setFrom( $from_email, $from_name ); + $phpmailer->setFrom( $from_email, $from_name, false ); // Set destination addresses if ( !is_array( $to ) ) diff --git a/tests/phpunit/tests/mail.php b/tests/phpunit/tests/mail.php index 9f9dd01a93..d3e7698f07 100644 --- a/tests/phpunit/tests/mail.php +++ b/tests/phpunit/tests/mail.php @@ -342,4 +342,22 @@ class Tests_Mail extends WP_UnitTestCase { $this->assertEquals( $expected[ $header ], array_pop( $target_headers ) ); } } + + /** + * Test that the Sender field in the SMTP envelope is not 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. + * + * @ticket 37736 + */ + 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.' ); + + $mailer = tests_retrieve_phpmailer_instance(); + + $this->assertEquals( '', $mailer->Sender ); + } }