3

I've scoured the web for the solution to this small issue, but I keep getting results that tell me how to customise the notification e-mail not the email address.

I have the admin email address in the WP settings as abc@xyz.tld which is great, but all new user registrations I want to go to a different email address.

e.g.

New user registered, email is sent to def@hij.td

Plugins, themes, etc. need updating, all emails go to JUST abc@xyz.tld

4

Yes, you can Change email address by using wp_mail function. You can check this how to do this http://www.butlerblog.com/2011/07/14/changing-the-wp_mail-from-address-with-a-plugin/

Use this plugin for user management it supports email address when new user registers https://wordpress.org/plugins/wp-members/

Use this code in your functions.php file.

function so174837_registration_email_alert( $user_id ) {
    $user    = get_userdata( $user_id );
    $email   = $user->user_email;
    $message = $email . ' has registered to your website.';
    wp_mail( 'youremail@example.com', 'New User registration', $message );
}
add_action('user_register', 'so174837_registration_email_alert');
  • Hi Krishna, Thanks for your swift reply. Are you telling me to install the plugin as well as your script? Or instead of? – David Pearce Jan 14 '15 at 15:00
  • I didn't install the plugin and just used the snippet you put and this appears to work perfectly. – David Pearce Jan 14 '15 at 15:05
  • Great, Happy to know that. – krishna Jan 14 '15 at 15:06
  • what is to put in strip_tags($_POST['user_login']) section ?? – Mayur Devmurari Nov 27 '15 at 10:51
  • i cant get email and user name there .. – Mayur Devmurari Nov 27 '15 at 10:52
2

I was led to this post while doing a Google search for a particular email question. Funny thing was that the posted answer references one of my blog posts and my plugin. That's kind of awesome - except that I don't think in this case that really answers the OP.

The question was that all notifications to the admin need to go to the specified email address, EXCEPT one - the new user notification.

My approach to that (provided the process was the WP native registration) would be to use a filter on wp_mail() (which, BTW, has a filter at the end of the entire process).

I would use that filter to look at the content of the message and if it was the email being sent for new user notification, then use the filter to change the "to" address.

In this example, the subject is examined to see if it contains 'New User Registration' which is part of the subject line in the WP default admin notification email. If that is the case, then the "to" email address is changed to the desired address. Otherwise, all other cases pass through the filter untouched.

add_filter( 'wp_mail', 'my_wp_mail_filter' );
function my_wp_mail_filter( $args ) {
    // Check the message subject for a known string in the notification email.
    if ( strpos( $args['subject'], 'New User Registration' ) ) {
        // This is the notification email, so change the "to" address.
        $args['to'] = 'def@hij.td';
    }
    return $args;
}

protected by Community Jun 6 '17 at 5:39

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

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