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
This commit is contained in:
Boone Gorges 2016-08-20 02:16:54 +00:00
parent ba9eda1a9b
commit 54b51f1a26
2 changed files with 19 additions and 1 deletions

View File

@ -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 ) )

View File

@ -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 );
}
}