Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在发送电子邮件的函数中使用html_Html_Wordpress_Email - Fatal编程技术网

在发送电子邮件的函数中使用html

在发送电子邮件的函数中使用html,html,wordpress,email,Html,Wordpress,Email,我正在使用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, 'cap

我正在使用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);

您需要将内容类型添加到邮件消息的标题中,以指示将以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);