我已经解决了这个问题。谢谢你的大力帮助@jared cobb
function send_welcome_email_to_new_user($user_id) {
$user = get_userdata($user_id);
$user_email = $user->user_email;
// email will send only for "A" registers
if ( in_array( \'A\', $user->roles )) {
$to = $user_email;
$subject = "Hi A, welcome to our site!";
$body = \'
<h1>Dear A,</h1></br>
<p>Thank you for joining our site. Your account is now active.</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);
}
}
// email will send only for "B" registers
if ( in_array( \'B\', $user->roles )) {
$to = $user_email;
$subject = "Hi B, welcome to our site!";
$body = \'
<h1>Dear B,</h1></br>
<p>Thank you for joining our site. Your account is now active.</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);
}
}
}
add_action(\'user_register\', \'send_welcome_email_to_new_user\');