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:
parent
ba9eda1a9b
commit
54b51f1a26
@ -349,7 +349,7 @@ function wp_mail( $to, $subject, $message, $headers = '', $attachments = array()
|
|||||||
*/
|
*/
|
||||||
$from_name = apply_filters( 'wp_mail_from_name', $from_name );
|
$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
|
// Set destination addresses
|
||||||
if ( !is_array( $to ) )
|
if ( !is_array( $to ) )
|
||||||
|
@ -342,4 +342,22 @@ class Tests_Mail extends WP_UnitTestCase {
|
|||||||
$this->assertEquals( $expected[ $header ], array_pop( $target_headers ) );
|
$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 );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user