From 54b51f1a26eabd9842d4bca2e6edfb918e2eac8e Mon Sep 17 00:00:00 2001 From: Boone Gorges Date: Sat, 20 Aug 2016 02:16:54 +0000 Subject: [PATCH] Mail: Don't set Sender field when setting From. [38058] changed `wp_mail()` so that it used PHPMailer's `setFrom()` method rather than setting the From and FromName headers directly. See behavior of setting the `Sender` field. This causes `mail` to be called with the `-f` flag, which causes outgoing email to fail on some server environments. Props Clorith, iandunn, DrewAPicture. Fixes #37736. git-svn-id: https://develop.svn.wordpress.org/trunk@38286 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/pluggable.php | 2 +- tests/phpunit/tests/mail.php | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) 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 ); + } }