-1

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

Here is my code:

$headers  = "From: \"FROM NAME\" <[email protected]>\n";
$headers .= "Return-Path: <[email protected]>\n";
$headers .= "Reply-To: \"FROM NAME\" <[email protected]>\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 '[email protected]';
}
add_filter('wp_mail_from_name','yoursite_wp_mail_from_name');
function yoursite_wp_mail_from_name($name) {
     return 'FROM NAME';
}

wp_mail("[email protected]", "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 [email protected] 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!

5
  • 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
    Commented Dec 13, 2019 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
    Commented Dec 13, 2019 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
    Commented Dec 13, 2019 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
    Commented Dec 13, 2019 at 17:09

1 Answer 1

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.

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.