0

我正在使用 wordpress 中的功能在角色更改时向用户发送电子邮件。我需要在其中插入一些 html,$message但它只是作为电子邮件中的文本出现。如何正确使用消息中的 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);
4

1 回答 1

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);
于 2012-05-04T20:10:25.447 回答