The accepted answer is now obsolete. The answer using wp_new_user_notification() works and will send a WordPress-like mail.
Still, you might want to send your own mail as David Gard suggested. Here is a bit of code that does this. You can use it as a function, or as a method in a class.
/**
* Send mail with a reset password link
*
* @param int $user_id User ID
*/
function notify_new_user( $user_id )
{
$user = get_userdata( $user_id );
$subject = '[website] Connection details';
$mail_from = get_bloginfo('admin_email');
$mail_to = $user->user_email;
$headers = array(
'Content-Type: text/html; charset=UTF-8',
'From: ' . $mail_from,
);
$key = get_password_reset_key( $user );
if ( is_wp_error( $key ) ) {
return;
}
$url_password = network_site_url( "wp-login.php?action=rp&key=$key&login=" . rawurlencode( $user->user_login ) );
$body = '<p>HTML body in your own style.</p>';
$body .= '<p>It must include the login identifier: ' . $user->user_login . '</p>';
$body .= '<p>And the link: ' . $url_password . '</p>';
wp_mail( $mail_to, $subject, $body, $headers );
}
If you don’t want to have the HTML content in the function, you can use a template engine. Here is an example you could add to the above code.
// Set up Mustache
$path = get_stylesheet_directory() . '/mails';
$dir = wp_get_upload_dir();
$m = new \Mustache_Engine( [
'cache' => $dir['basedir'] . '/mustache_cache',
'loader' => new \Mustache_Loader_FilesystemLoader( $path ),
'partials_loader' => new \Mustache_Loader_FilesystemLoader( $path . '/layouts' ),
] );
// Variable data in the mail
$data['mail']['title'] = $subject; // {{mail.title}}
$data['identifier'] = $user->user_login; // {{identifier}}
$data['url-password'] = $url_password; // {{url-password}}
$body = $m->render( 'mail-template-new-user', $data );
Mustache tags documentation.