首页 > 解决方案 > HTML 标签显示在邮件中

问题描述

我正在尝试在 php 中通过邮件发送文本。消息放置在 HTML 标记内。发送时,邮件部分有效,但我收到的文本中有 HTML 标签。

这是更好地理解我的问题的代码:

$car = "1223455667";
$to = "something@sample.com";
$subject = 'Test Mail';
$message = '<p>' . $car . '</p>';

$from = 'mymail@sample.com';

if(mail($to, $subject, $message )){
    echo 'success';
}else{
    echo 'Unable to send the email. Please try again.';
}

我在邮件中收到的输出:

在此处输入图像描述

我希望输出是这样的:1223455667

标签: phphtml-email

解决方案


在您的邮件中传递标头

$headers = "MIME-Version: 1.0" . "\r\n"; 
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n"; 

if(mail($to, $subject, $message, $headers )){
    echo 'success';
}else{
    echo 'Unable to send the email. Please try again.';
}

推荐阅读