The question:
I’m using the Post SMTP Plugin, but I manually send email via the wp_mail()
function.
The gmail client shows the correct From:, but when I switch to outlook or another email client, shows the different Sender: (the one that has been set up in the Post SMTP From: setting)
I have tried these filters, but only the wp_mail_from_name
works:
add_filter( 'wp_mail_from', create_function('', 'return sanitize_email("[email protected]"); ') );
add_filter( 'wp_mail_from_name', create_function('', 'return "Test Testov"; ') );
How can I force-change that sender?
EDIT:
Paul G., in Gmail I see this: from: Correct Name <[email protected]>
and in another email client this:
From: Correct Name
Sender: [email protected]
<—- This is wrong.
The Solutions:
Below are the methods you can try. The first solution is probably the best. Try others if the first one doesn’t work. Senior developers aren’t just copying/pasting – they read the methods carefully & apply them wisely to each case.
Method 1
First Disable PostSMTP plugin and delete if not used anymore it should cleanup.
Then in functions.php add the following lines
// Function to change email address
function sender_email( $original_email_address ) {
return '[email protected]';
}
// Function to change sender name
function sender_name( $original_email_from ) {
return 'Tim Smith';
}
// Hooking up our functions to WordPress filters
add_filter( 'wp_mail_from', 'sender_email' );
add_filter( 'wp_mail_from_name', 'sender_name' );
Taken from : WPBeginner
Method 2
Switched the Mailer Type from PostSMTP to PHPMailer and it fixed the issue.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0