Created
May 16, 2022 11:47
-
-
Save wpdew/ca6b66b16980b42545127b85442ad0bb to your computer and use it in GitHub Desktop.
Send a welcome email to new user wordpress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//send_welcome_email | |
function send_welcome_email_to_new_user($user_id) { | |
$user = get_userdata($user_id); | |
$user_email = $user->user_email; | |
// for simplicity, lets assume that user has typed their first and last name when they sign up | |
$user_full_name = $user->user_firstname . $user->user_lastname; | |
// Now we are ready to build our welcome email | |
$to = $user_email; | |
$subject = "Hi " . $user_full_name . ", welcome to our site!"; | |
$body = ' | |
<h1>Dear user,</h1></br> | |
<p>Thank you for joining our site. Your account is now active.</p> | |
<p>Please go ahead and navigate around your account.</p> | |
<p>Let me know if you have further questions, I am here to help.</p> | |
<p>Enjoy the rest of your day!</p> | |
'; | |
$headers = array('Content-Type: text/html; charset=UTF-8'); | |
if (wp_mail($to, $subject, $body, $headers)) { | |
error_log("email has been successfully sent to user whose email is " . $user_email); | |
}else{ | |
error_log("email failed to sent to user whose email is " . $user_email); | |
} | |
} | |
add_action('user_register', 'send_welcome_email_to_new_user'); | |
//Change WordPress from Email Header | |
function res_fromname($email){ | |
$wpfrom = get_option('blogname'); | |
return $wpfrom; | |
} | |
add_filter('wp_mail_from_name', 'res_fromname'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment