Html Email on user role change from Subscriber to Member
-
Hi Have set up an extra user role for members. So when someone registers they are automatically added with the user role type Subscriber. Once we verify their payment we change the user role to member. What I need help with is sending an HTML email to the person on their role change to member to inform them of the role change. Normal Buddy press emails including activation emails work great. Using the code snippet below when I change a user from Subscriber to Member the email does not trigger. Any ideas? Is there a way to set up an email on role change using the Buddy press emails rather than adding code to functions.php?
//NOTIFY USER when their Role has Been Changed to Member
// (A) HEADER – HTML MAIL
$mailHead = implode(” “, [
“MIME-Version: 1.0”,
“Content-type: text/html; charset=utf-8”
]);
// (B) FUNCTION
function user_role_update( $user_id, $new_role ) {
if ($new_role == ‘Member’) {
$site_url = get_bloginfo(‘wpurl’);
$user_info = get_userdata( $user_id );// (C) MAIL SETTINGS
$to = $user_info->user_email;
$setFrom(‘members@offroadcamping.co.za’) ;// (D) SET IMAGE
$img = “https://beta.offroadcamping.co.za/wp-content/uploads/2023/02/Logo-72-1.webp”;// (E) SET SUBJECT LINE
$subject = “Role changed: “.$site_url.””;// (F) MAIL MESSAGE
$message = “Welcome ” . $user_info->display_name. ” you have been added as a “. $new_role.” on offroadcamping.co.za. Congratulations you can now access the members area, make posts, and make online camp bookings on the Camp Page. You can access the site here: “.$site_url.””;
“<br>”;$message = “$AddEmbeddedImage(‘$img’)”;
“<br>”;
//$message .= “Can’t see the image? Click Here.“;
// (G) SEND
wp_mail($to, $subject, $message, $mailHead);
}
}
add_action( ‘set_user_role’, ‘user_role_update’, 10, 2);
- You must be logged in to reply to this topic.