Change the Sender(not From) on wp_mail() function

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("<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="5125342225113033277f3336">[email protected]</a>"); ') );
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.

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

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 '<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="780c1115560b15110c10381d00191508141d561b1715">[email protected]</a>';
}
 
// 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

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x