0

I have a problem. I've used

add_filter('wp_mail_from', 'new_mail_from');
add_filter('wp_mail_from_name', 'new_mail_from_name');

function new_mail_from($old) {
 return 'contact@mysite.hk';
}

function new_mail_from_name($old) { 
 return 'MySite.com';
}

To overwrite default From email WordPress (wordpress@mysite.com)

And this is Ok, But

Contact Form 7 Form was overwritten by the same function too. I want CF7 to send [your-name] [your-surname] <[your-email]> to email. Not MySite.com (contact@mysite.hk)

Is there a way to get rid of this bug?

2

try this one

add_filter('wp_mail_from', 'doEmailFilter');
add_filter('wp_mail_from_name', 'doEmailNameFilter');

function doEmailFilter($email_address){
    if($email_address === "wordpress@mysite.hk")
        return 'contact@mysite.hk';
    else
        return $email_address;
}
function doEmailNameFilter($email_from){
    if($email_from === "WordPress")
        return 'MySite.com';
    else
        return $email_from;
}

This checks if WP is going to send mail as a system (as wordpress@something) and if so, changes to your setting. Otherwise, is using inputs data (mail and name).

| 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.