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.');
}

Solutions Collecting From Web of "Send automatic email to user after wp_create_user"

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

There’s the user_register hook, which runs at the end of user insertion and has $user_id as a parameter, you could leverage that to send the username and password, but you have to update_user_meta() before you can get first name and stuff, so it might be better to do it at the end of the user creation and usermeta insertion.

The only thing creating a user does is insert the user into the DB, you need to use update_user_meta() to add the user values. get_the_author_meta() has a list of the default usermeta values, if you insert something with the key of one of those, it will show up in profile.php by default, otherwise you will have to extend the user profile to display it.

Also, just a note, it seems as though you’re setting $random_password to a non-random value and also, probably more importantly, setting it AFTER it’s been used.

I would use wp_insert_user instead of wp_create_user so you can add as much user data as you like in the first instance. Check the WordPress codex for all that you can insert. (wp_create_user simply calls this function anyway!)
To send out the user login details you can call wp_mail($user_email, $subject, $message);
Of course you will want to set $message to include the username and password in the body of the message text.
Another thing, I think you can create the function wp_new_user_notification which is a pluggable function and is called on new user registration, you can put the mail function in that, I know plugins such as Register Plus Redux and Pie Register do it this way.

I Think this is you are looking for.
This will add first name and last name to user meta and send a mail to user about first name and last name addition.

 add_action('user_register', 'add_user_custom_meta');

function add_user_custom_meta($user_id) {
    $user_info=get_userdata( $user_id );
if ( isset( $_POST['first_name'] ) )
    update_user_meta($user_id, 'first_name', $_POST['first_name']);

if ( isset( $_POST['last_name'] ) )
    update_user_meta($user_id, 'last_name', $_POST['last_name']);

wp_mail($user_info->user_email, 'User first and last name', sprintf('Hi we have added your first name :-% and last name:- % to our site.',$_POST['first_name'],$_POST['last_name']));
}