I’m using a function in wordpress to send emails to users when a role is changed. I need to insert some html into the $message but it just comes out as text in the email. How can I use html tags inside the message correctly?
function user_role_update( $user_id, $new_role ) {
$site_url = get_bloginfo('wpurl');
$user_info = get_userdata( $user_id );
if (user_can( $user_id, 'capability' ) ) {
$to = $user_info->user_email;
$subject = "Role changed: ".$site_url."";
$message = "Hello " .$user_info->display_name . " your role has changed on ".$site_url.", congratulations you are now an " . $new_role;
wp_mail($to, $subject, $message);
} elseif (user_can( $user_id, 'capability' ) ) {
// etc...
}
}
add_action( 'set_user_role', 'user_role_update', 10, 2);
You will need to add a content-type to the headers of your mail message denoting that it is to be formatted in HTML: