5

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 [email protected] 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 [email protected]

Plugins, themes, etc. need updating, all emails go to JUST [email protected]

2 Answers 2

6

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( '[email protected]', 'New User registration', $message );
}
add_action('user_register', 'so174837_registration_email_alert');
6
  • Hi Krishna, Thanks for your swift reply. Are you telling me to install the plugin as well as your script? Or instead of? Commented Jan 14, 2015 at 15:00
  • I didn't install the plugin and just used the snippet you put and this appears to work perfectly. Commented Jan 14, 2015 at 15:05
  • Great, Happy to know that.
    – krishna
    Commented Jan 14, 2015 at 15:06
  • what is to put in strip_tags($_POST['user_login']) section ?? Commented Nov 27, 2015 at 10:51
  • i cant get email and user name there .. Commented Nov 27, 2015 at 10:52
3

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'] = '[email protected]';
    }
    return $args;
}

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