0

How can I send username and password of new registration to admin using email.

1

You can use an action to do that, but you can't get the password because it's encrypted, unless you catch the password when the registration form is submitted but that's not a good practice.

Why do you need to get the passwords on admin email? You can always reset password if the user forgot the password.

To send user information when a new user is registered:

add_action( 'user_register', 'send_new_user_info_to_email', 10, 1 );

function send_new_user_info_to_email( $user_id ) {

    $user_info = get_userdata( $user_id );

    $to = get_bloginfo('admin_email');
    $subject = 'New User';
    $body = 'User email:' . $user_info->user_email . '<br>User pass (encrypted):' . $user_info->user_pass ;
    $headers = array('Content-Type: text/html; charset=UTF-8');

    wp_mail( $to, $subject, $body, $headers );

}
1

You cannot send passwords via email because Wordpress encrypts them prior to storage. That's a behavior that can be changed, but you really shouldn't do it. If the admin needs to log into an user's account, you could code something using the wp_set_current_user function, or you can use the User Switcher plugin.

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.