Send a custom email to new registered user in wordpress
You can send a custom welcome email to new user and a confirmation mail to admin in WordPress after user registration.
Since WordPress 4.9.0 you can use following filters :
wp_new_user_notification_email – customize email sent to User
wp_new_user_notification_email_admin – customize email sent to Admin
If you allow user registration on your WordPress site, then each new user receives an email to set up their WordPress password. However, after registration user don’t receive a proper format welcome email specific to your website.
To send a user message open your functions.php file and paste this code –
add_filter( 'wp_new_user_notification_email_admin', 'custom_wp_new_user_notification_email', 10, 3 );
function custom_wp_new_user_notification_email( $wp_new_user_notification_email, $user, $blogname ) {
$wp_new_user_notification_email['subject'] = sprintf( '[%s] New user %s registered.', $blogname, $user->user_login );
$wp_new_user_notification_email['message'] = sprintf( "%s ( %s ) has registerd to your blog %s.", $user->user_login, $user->user_email, $blogname );
return $wp_new_user_notification_email;
}
To send message to admin , open your functions.php file and paste this code –
add_filter( 'wp_new_user_notification_email', 'custom_wp_new_user_notification_email', 10, 3 );
function custom_wp_new_user_notification_email( $wp_new_user_notification_email, $user, $blogname ) {
$key = get_password_reset_key( $user );
$message .= "Hi " . $user->user_login . "\r\n\n";
$message = sprintf(__('Welcome to the your blog name Community ,')) . "\r\n\r\n";
$message .= 'To set your password, visit the following address:' . "\r\n\r\n";
$message .= network_site_url("wp-login.php?action=rp&key=$key&login=" . rawurlencode($user->user_login), 'login') . "\r\n\r\n";
$message .= "After this you can login to your member Dashboard!" . "\r\n\r\n";
$message .= 'Login from here:' . "\r\n\r\n";
$message .= network_site_url("wp-login.php") . "\r\n\r\n";
$message .= "Kind regards," . "\r\n\n";
$message .= "Support Office Team" . "\r\n";
$message .= "Your Blog Name" . "\r\n";
$wp_new_user_notification_email['message'] = $message;
$wp_new_user_notification_email['headers'] = 'From: Your Blog Name<example@domain.ext>';
return $wp_new_user_notification_email;
}