2

So I've got a couple of different plugins which I'm attempting to change the from address of the email header. I've tried using the filters, but it's simply sending the email as the admin user account on the site.

add_filter( 'wp_mail_from_name', 'my_mail_from_name' ); 
function my_mail_from_name( $name ) 
{ 
    return "My Name"; 
} 

add_filter( 'wp_mail_from', 'my_mail_from' ); 
function my_mail_from( $email ) 
{ 
    return "[email protected]"; 
} 

I've tried setting an array, and passing that to wp_mail directly. And that doesn't work either.

$header[] = 'From: "test" <[email protected]>';
$header[] = 'Content-Type: text/plain'."\r\n";

Can anyone see what I've done wrong here? I'm stumped.

6
  • Are you definitely using the default implementation of wp_mail as opposed to e.g. a SendGrid or Postmark plugin? Could there be any more implementations of those filters? Can you tell if they're definitely being hit, i.e. that's not in a file that isn't being loaded?
    – Rup
    Jul 1, 2014 at 17:07
  • @Rup Yes, they're being hit. It's the only function with wp_mail in it and I'm getting the email, just with the wrong from address and name. It's the default wp_mail as the site as been around for a while and there's no other plugins which would modify it installed (I checked).
    – mrdenny
    Jul 1, 2014 at 17:31
  • As best I can tell the mail then goes to wp-includes/class-phpmailer, and then on to one of a few different routes out of the system (mail, sendmail, direct SMTP). It might be possible one of those is overriding the from address. Is it a clean WP installation, or is there a chance any of these classes have been modified? If you chance the admin's email address in the site does the new address get used as the send address or is it fixed to the old address somewhere?
    – Rup
    Jul 2, 2014 at 8:39
  • I can change the email address of user ID 1 and it changes what's being sent out. I'll look at see if GoDaddy (my host) has modified class-phpmailer.
    – mrdenny
    Jul 3, 2014 at 3:33
  • 3
    And I've found the problem. Because I'm on GoDaddy I have to use something to configure WordPress to use SMTP instead of native PHP mail. And it appears that this is hard coded to use the name and email address from user ID 1 to send from. Guess I'll raise that issue with the guy who wrote that plugin. What a pain, thanks.
    – mrdenny
    Jul 3, 2014 at 3:42

1 Answer 1

-1

Here is a better WordPress SMTP mailer. https://wordpress.org/plugins/postman-smtp/

1
  • This is not an answer to the question. Feb 5, 2018 at 10:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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