默认情况下,Wordpress会在提交注册后向用户发送欢迎电子邮件,同时发送电子邮件验证电子邮件 . 是否可以在他们点击该电子邮件验证链接以激活其帐户后发送该欢迎电子邮件?这是我在插件中添加的代码;它的工作原理是在注册后立即发送:
function send_welcome_email_to_new_user($user_id) {
$user = get_userdata($user_id);
$user_email = $user->user_email;
$username = $user->user_login;
$to = $user_email;
$subject = "Welcome to our site!";
$body = '
<h1>Dear ' . $username . ',</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>
<p>Kind Regards,</p>
<p>Site Administrator</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');
任何人都可以帮我指出正确的方向吗?
干杯
1 回答
试试这个