WordPress.org

Ready to get started?Download WordPress

Forums

First Last Name to New User Email Notification (2 posts)

  1. ericreynolds007
    Member
    Posted 1 year ago #

    When a new user registers on my site, as an admin, I receive an email notification that includes the username and email address. My registration form requires the new user to add his or her first and last name. How can I include the first and last name in the new user email notification?

  2. riccardo.raneri
    Member
    Posted 1 year ago #

    You can add your own custom notification, inside your theme's functions.php - it will replace the default welcome mail (for the subscriber) and the notification mail (for the admin):

    if ( !function_exists('wp_new_user_notification') ) {
            function wp_new_user_notification( $user_id, $plaintext_pass = '' ) {
                $user = new WP_User($user_id);
                $user_login = stripslashes($user->user_login);
                $user_email = stripslashes($user->user_email);
                $user_first_name = get_user_meta( $user_id, 'first_name', true );
                $user_last_name = get_user_meta( $user_id, 'last_name', true );
                $fullname = ($user_first_name." ". $user_last_name);
    
                // Admin Notification Email
                $message  = sprintf(__('New user registration on your website %s:'), get_option('blogname')) . "\r\n\r\n";
                $message .= sprintf(__('Username: %s'), $user_login) . "\r\n\r\n";
                $message .= sprintf(__('E-mail: %s'), $user_email) . "\r\n";
                $message .= sprintf(__('Full Name: %s'), $fullname) . "\r\n";
                @wp_mail(get_option('admin_email'), sprintf(__('%s - New User Registration'), get_option('blogname')), $message);
    
                if ( empty($plaintext_pass) )
                return;
    
                // Users Notification Email
                $message = "Hi $fullname," . "\r\n\r\n";
                $message .= sprintf(__("Thanks for registering your details at %s! website, your user login details are below:"), get_option('blogname')) . "\r\n\r\n";
    
                $message .= wp_login_url() . "\r\n";
                $message .= sprintf(__('Username: %s'), $user_login). "\r\n";
                $message .= sprintf(__('Password: %s'), $plaintext_pass). "\r\n\r\n";
    
                $message .= sprintf(__('If you have any questions or problems, please contact us at %s.'), get_option('admin_email')) . "\r\n\r\n";
    
                $message .= __('Thank you,'). "\r\n\r\n";
                $message .= get_option('blogname'). "\r\n";
                $message .= get_option('home'). "\r\n\r\n";
    
                wp_mail($user_email, sprintf(__('%s - Username & Password'), get_option('blogname')), $message);
    
            }
    }

Topic Closed

This topic has been closed to new replies.

About this Topic