php - 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
解决方案
在您的邮件中传递标头
$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.';
}
推荐阅读
- css - CSS 属性 background-image 支持的所有文件类型是什么?
- python - 如何在 Python 中更高效地分配以及它在内部是如何工作的?
- java - Selenium 正在读取占位符值
- python - 如何继续打印烂番茄中的所有前 100 部电影?
- jmeter - 有人使用 Sonarqube 来查看 loadrunner 脚本吗?
- ajax - 在 ASP.NET MVC 发布配置中未找到 ajax 错误
- laravel - 从 Laravel 中的数据库获取后如何“json_decode”单列数据?
- c# - EFcore 禁用自动向迁移添加属性
- git - 从分支中删除特定提交
- django - 在 Django 模板上渲染用户模型关系字段