Send email when a user registers Rest api

You don’t know the type of content that might be passed for the $user parameter, so let’s test it out.

You will want to expand on these conditions and responses. This is just an example of the tests you probably want to make.

function user_registered( $user ) {
    // Check to make sure it's not an error.
    if ( is_wp_error( $user ) ) {
        return;
    }
    // This is how WordPress checks to make sure the user exists.
    // This could also apply to many other objects, though. 
    if ( ! isset( $user->ID ) ) {
        return; 
    }
    // This checks to make sure you're getting the expected user object fields.
    if ( ! isset( $user->user_email ) ) {
        // If you have a correct ID, you can still retrieve the user's fields.
        $user = get_user_by( 'ID', $user->ID );
        // If the user doesn't exist, stop where you are.
        if ( ! $user ) {
            return false;
        }
    }

    $headers = array(
        'Content-Type: text/html; charset=UTF-8',
        'From: WordPress Website <[email protected]>',
    );
    wp_mail( $user->user_email, 'Subject of email', 'Email body', $headers );
}