I am trying to send a custom email to all admins when a user registers. I have the following code, but it only sends to the email listed in the Administration Email Address. I need it to send to all admins.
add_filter('wp_new_user_notification_email_admin', 'cmc_custom_user_reg_admin_email', 10, 3);
function cmc_custom_user_reg_admin_email($wp_new_user_notification_email, $user, $blogname) {
$id = $user->ID;
$name = $user->first_name . " " . $user->last_name;
$username = $user->nickname;
$newmail = "
<p><b>Name:</b> $name</p>
<p><b>Username:</b> $username</p>
<p><a href='https://intranet/departments/residency/index.php/confirm-email/?id=$id'>Click Here to confirm the registration.</a></p>
";
// Set the message, subject and headers for the email
$wp_new_user_notification_email['message'] = $newmail;
$wp_new_user_notification_email['subject'] = "Family Medicine Residency Site Registration";
$wp_new_user_notification_email['headers'] = 'Content-Type: text/html; charset=UTF-8';
//error_log("email has been successfully sent to user whose email is " . $user_email);
return $wp_new_user_notification_email;
}
I am trying to send a custom email to all admins when a user registers. I have the following code, but it only sends to the email listed in the Administration Email Address. I need it to send to all admins.
add_filter('wp_new_user_notification_email_admin', 'cmc_custom_user_reg_admin_email', 10, 3);
function cmc_custom_user_reg_admin_email($wp_new_user_notification_email, $user, $blogname) {
$id = $user->ID;
$name = $user->first_name . " " . $user->last_name;
$username = $user->nickname;
$newmail = "
<p><b>Name:</b> $name</p>
<p><b>Username:</b> $username</p>
<p><a href='https://intranet/departments/residency/index.php/confirm-email/?id=$id'>Click Here to confirm the registration.</a></p>
";
// Set the message, subject and headers for the email
$wp_new_user_notification_email['message'] = $newmail;
$wp_new_user_notification_email['subject'] = "Family Medicine Residency Site Registration";
$wp_new_user_notification_email['headers'] = 'Content-Type: text/html; charset=UTF-8';
//error_log("email has been successfully sent to user whose email is " . $user_email);
return $wp_new_user_notification_email;
}
Share Improve this question asked Feb 6 at 19:33 Darth Mikey DDarth Mikey D 931 silver badge9 bronze badges1 Answer
Reset to default 0Better try something like this:
add_action( 'register_new_user', 'send_admin_registration_email', 99, 1 );
function send_admin_registration_email( $user_id ) {
$user_info = get_userdata( $user_id );
$first_name = $user_info->first_name;
$last_name = $user_info->last_name;
$user_login = $user_info->user_login;
$subject = 'Family Medicine Residency Site Registration';
$message = '<p><b>Name:</b> ' . esc_html( $first_name ) . ' ' . esc_html( $last_name ) . '</p>';
$message .= '<p><b>Username:</b> ' . esc_html( $user_login ) . '</p>';
$message .= '<p><a href="https://intranet/departments/residency/index.php/confirm-email/?id=' . esc_attr( $user_id ) . '">Click Here to confirm the registration.</a></p>';
$admins = get_users( array('role' => 'administrator') );
$admin_emails = wp_list_pluck( $admins, 'user_email' );
if ( ! empty( $admin_emails ) ) {
wp_mail( $admin_emails, $subject, $message, array('Content-Type: text/html; charset=UTF-8') );
}
}