wp_new_user_notifications to notify user and admin about new user registration

If you’re operating under the assumption that wp_insert_user() sends the notification, then that’s where the problem is. That function just inserts the user – it does not by itself send any emails.

You can use the function wp_send_new_user_notifications( $user_id ) to send user notification. However, you need to trigger it based on the result of your wp_insert_user(). Check to make sure you have a user ID and not an error in your result:

if ( ! is_wp_error( $user_id ) ) {
     wp_send_new_user_notifications( $user_id );
} else {
     // you have an error...
}

Note that the wp_send_new_user_notifications() function will send to the user and an admin notification by default (so you don’t have to specify “both”).

tech