Send automatic email to user after wp_create_user

So, here is some code I came up with — It works, but now I need it to send the username and password it generated to that email address automatically ?? Also the first and last name isn’t recording ?? Thanks!!

require('wordpress/wp-blog-header.php');

$user_email = trim(isset($_POST['payer_email']) ? $_POST['payer_email'] : "");
$user_name = trim(isset($_POST['first_name']) ? $_POST['first_name'] : "");

$user_id = username_exists( $user_name );
if ( !$user_id ) {
    $random_password = wp_generate_password( 12, false );
    $user_id = wp_create_user( $user_name, $random_password, $user_email );
} else {
    $random_password = __('User already exists.  Password inherited.');
}

4 Answers
4

You can use this: wp_new_user_notification( $user_id, $random_password);

Leave a Comment