0

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.

1
  • The sender email information wont change based on the client that READS the email, that's impossible. Unless I've misunderstood what you've written...
    – Paul G.
    Commented May 12, 2021 at 15:35

2 Answers 2

3

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

0

Switched the Mailer Type from PostSMTP to PHPMailer and it fixed the issue.

2
  • Please be kind enough to mark my answer, as i did state to disable PostSMTP and then perform override if necessary. you can also have shortcodes that change the senders email and name based on the form that you are using etc, like hooking into GRavity/Ninja forms etc.
    – dExIT
    Commented May 13, 2021 at 11:42
  • Many thanks for the points :)
    – dExIT
    Commented May 14, 2021 at 14:28

Not the answer you're looking for? Browse other questions tagged or ask your own question.