PHP mail()函数,以HTML代码发送邮件

PHP mail()函数,以HTML代码发送邮件,php,html,Php,Html,我面临一个问题,当我使用mail()发送邮件时,它会在邮件中发送HTML代码。这是我的代码: <?php $message = "<table width='100%' border='0' cellspacing='0' cellpadding='3'> <tr> <td colspan=2>Dear ".$_POST['fname']."&nbsp;".$_POST['lname'].",</td> </tr

我面临一个问题,当我使用
mail()
发送邮件时,它会在邮件中发送HTML代码。这是我的代码:

<?php
$message = "<table width='100%' border='0' cellspacing='0' cellpadding='3'>
  <tr>
    <td colspan=2>Dear ".$_POST['fname']."&nbsp;".$_POST['lname'].",</td>
  </tr>
   <tr>
    <td colspan=2>Thank you for contacting us.We will get back to you in next 48 hrs.Your Contacts Details are as follows:</td>
  </tr>
  <tr>
    <td width='28%' >Title</td>
    <td width='72%'>".$_POST['title']."</td>
  </tr>
  <tr>
    <td>Email</td>
    <td>".$_POST['email']."</td>
  </tr>
  <tr>
    <td>Your Message</td>
    <td>".$_POST['message']."</td>
  </tr>
  <tr>
    <td>How did you hear about us? </td>
    <td>".$checkBox."</td>
  </tr>
</table>
";  

$subject = "ContactUs";
$headers .= "From: ".$from_mail." \r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";

mail($_POST["coach"], $subject, $message, $headers);

?>

我在电子邮件中得到的输出如下所示:

<table width='100%' border='0' cellspacing='0' cellpadding='3'>
  <tr>
    <td colspan=2>Dear Test User,</td>
  </tr>
   <tr>
    <td colspan=2>Thank you for contacting us.Your Contacts Details are as follows:</td>
  </tr>
  <tr>
    <td width='28%' >Title</td>
    <td width='72%'>Mr.</td>
  </tr>
  <tr>
    <td>Email</td>
    <td>test@example.com</td>
  </tr>
  <tr>
    <td>Your Message</td>
    <td>Test Message</td>
  </tr>
  <tr>
    <td>How did you hear about us? </td>
    <td>www.example.com</td>
  </tr>
</table>

尊敬的测试用户:,
感谢您与我们联系。您的联系方式如下:
标题
先生
电子邮件
test@example.com
你的信息
测试消息
你是怎么听说我们的?
www.example.com
我不知道为什么会这样。任何建议都将不胜感激。

试试这个

$header  = "MIME-Version: 1.0\r\n";
$header .= "Content-type: text/html; charset: utf8\r\n";
还可以试试:

试试这个

$header  = "MIME-Version: 1.0\r\n";
$header .= "Content-type: text/html; charset: utf8\r\n";
同时尝试:

使用

html_实体_解码()

使用

html_实体_解码()


在标题部分添加以下代码

<?php
$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
?>

在标题部分添加以下代码

<?php
$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
?>


@Tornado yours非常欢迎您也检查,但我需要确认,如果我使用
内容类型:text/html,为什么会发生这种情况;charset=iso-8859-1\r\n
@Tornado您需要使用mime类型发送html,请检查我以前的链接comment@Tornado非常欢迎您的检查,但我需要确认,如果我使用
内容类型:text/html,为什么会发生这种情况;charset=iso-8859-1\r\n
@Tornado您需要使用mime类型发送html,请查看我以前的评论链接