0

i tried nearly anything to change the From / Reply-to name for the wp_mail() function.

Here is my code:

$headers  = "From: \"FROM NAME\" <from-mail@from.com>\n";
$headers .= "Return-Path: <yes-dashboard-alerts@finanztrends.info>\n";
$headers .= "Reply-To: \"FROM NAME\" <from-mail@from.com>\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "X-Mailer: PHP" . phpversion() . "\n";
$headers .= "Content-Type: text/plain; charset=\"". get_bloginfo('charset') . "\"\n";


add_filter('wp_mail_from','yoursite_wp_mail_from');
function yoursite_wp_mail_from($content_type) {
    return 'from-mail@from.com';
}
add_filter('wp_mail_from_name','yoursite_wp_mail_from_name');
function yoursite_wp_mail_from_name($name) {
     return 'FROM NAME';
}

wp_mail("receipient@website.com", "Subject", "Content", $headers);

I also tried to move the filters to the functions.php. But it doesn't matter what I try it is always the same from address when I receive the email. It seems that a plugin overrides the filters & headers because it is not the standard wordpress@your-site.com address but I've searched through all plugins with the plugin String Locator and I can't find it though.

Do you have any advice?

Thanks in advance!

  • Check with your host to see if they override the "from". Although limited, there are some hosts that do this. Also, as an initial test, try setting the priority for the filters to a later number. If there's another filter overriding you, it would be loaded after yours, so setting a later priority would check this - i.e. add_filter('wp_mail_from','yoursite_wp_mail_from', 999); – butlerblog Dec 13 '19 at 13:00
  • 1
    "It seems that a plugin overrides the filters & headers" - deactivate plugins one by one and try again, there may be various ways to do this, so a string search can give false negatives – kero Dec 13 '19 at 13:05
  • thank you for your help, but unfortunately both solutions haven't worked out for me. I don't think my host has anything to do with it, but I will ask him. – Till Meier Dec 13 '19 at 13:41
  • "I don't think my host has anything to do with it" - a big assumption... You don't know unless you ask. I've learned this by experience when debugging things only to find out later there was something on the hosting side that was responsible. Find out for sure before continuing or you may be banging your head against the wall for nothing. Debugging issues is easier when you can eliminate specific possibilities. – butlerblog Dec 13 '19 at 17:09
0

Try changing your headers from \n to \r\n

Note from here that:

Each line should be separated with a CRLF (\r\n). Lines should not be larger than 70 characters.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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