我在wordpress中使用一个函数,在角色发生变化时向用户发送电子邮件。我需要在$message
中插入一些html,但它只是作为电子邮件中的文本出现。如何正确使用消息中的html标签?
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);
答案 0 :(得分:1)
您需要在邮件的标题中添加内容类型,表示它将以HTML格式化:
$to = $user_info->user_email;
$subject = "Role changed: ".$site_url."";
$headers = "Content-Type: text/html\r\n";
$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, $headers);