最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - Send registration email to all admins

programmeradmin0浏览0评论

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 badges
Add a comment  | 

1 Answer 1

Reset to default 0

Better 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') );
    }
}
发布评论

评论列表(0)

  1. 暂无评论