如何在使用php mail()函数发送的邮件中显示正确的html输出?

如何在使用php mail()函数发送的邮件中显示正确的html输出?,php,ajax,email,html-table,Php,Ajax,Email,Html Table,我有一张忘记密码的表格 我正在使用电子邮件ID发送邮件 HTML代码: <form action="#" method="post"> <table border="0" width="" id="forgot_password"> <tr> <td>Enter Email ID:</td> <td><input type="email"

我有一张忘记密码的表格

我正在使用电子邮件ID发送邮件

HTML代码:

<form action="#" method="post">
     <table border="0" width="" id="forgot_password">
         <tr>
             <td>Enter Email ID:</td>
             <td><input type="email" name="email_id" id="email_id"/></td>
         </tr>
         <tr>
             <td colspan="2"><span class="message validation"></span></td>
         </tr>
         <tr>
             <td></td>
             <td><input type="button" name="forgot" class="myButton" value="Submit"/></td>
         </tr>
     </table>
</form>
我收到邮件,但html正在打印,因为它是在邮件中

所以,如何以用户可读的形式打印它,就像我们在浏览器中显示的那样

请帮我解决这个问题


提前感谢。

请在下面的行中尝试$headers

$boundary = "nextPart";
$headers = "MIME-Version: 1.0\r\n";
$headers .= "From: Me <youeemail>\r\n";
$headers .= "Content-Type: multipart/alternative; boundary = $boundary\r\n";
//text version
$headers .= "\n--$boundary\n"; // beginning \n added to separate previous content
$headers .= "Content-type: text/plain; charset=iso-8859-1\r\n";
$headers .= "This is the plain version";
//html version
$headers .= "\n--$boundary\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "This is the <b>HTML</b> version";

你的脑子里可能有问题headers@KarthickKumarGanesh:我尝试在标题中使用iso-8859-1,但无法以正确的格式显示html输出。我也尝试了UTF-8,但结果是一样的。你用的是什么邮件客户端?什么配置?有些客户端被显式设置为不呈现html。从服务器端看,您对html没有任何控制权-具体取决于每个用户如何配置其客户端。这些设置是否可用以及在何处/如何访问它们取决于客户端。我看不出您的代码有任何错误。如果你有另一个网站,邮件可以正常工作-只需从该网站复制代码即可。我尝试在标题中使用iso-8859-1,但无法以正确的格式显示html输出。我也尝试了UTF-8,但结果是一样的。字符集对输出没有影响。
<?php
   $uemail = $_POST['email'];

    $user_emailid = mysql_query("SELECT * FROM user_details WHERE email_id = '$uemail'");

    if(mysql_num_rows($user_emailid) == 1){
        $row = mysql_fetch_array($user_emailid);

        $email_id = $row['email_id'];
        $username = $row['uname'];
        $password = $row['upassword'];

        $to      = $email_id;
        $subject = 'login credentials';
        $message = "<html>
                        <body>
                            <table>
                                <tr>
                                    <td>Login credentials:</td>
                                    <td></td>
                                </tr>
                                <tr>
                                    <td>Username:</td>
                                    <td>$username</td>
                                </tr>
                                <tr>
                                    <td>Password</td>
                                    <td>$password</td>
                                </tr>
                            </table>
                        </body>
                    </html>";

                    //echo $message; die;

        $headers = 'MIME-Version: 1.0' . "\r\n";
        $headers .= 'Content-Type: text/html; charset=iso-8859-1' . "\r\n";
        $headers .= "From: Fairmacs";
        mail($to, $subject, $message, $header);
    }
    else{
        echo '1';
    }
?>
$boundary = "nextPart";
$headers = "MIME-Version: 1.0\r\n";
$headers .= "From: Me <youeemail>\r\n";
$headers .= "Content-Type: multipart/alternative; boundary = $boundary\r\n";
//text version
$headers .= "\n--$boundary\n"; // beginning \n added to separate previous content
$headers .= "Content-type: text/plain; charset=iso-8859-1\r\n";
$headers .= "This is the plain version";
//html version
$headers .= "\n--$boundary\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "This is the <b>HTML</b> version";
 $headers = 'MIME-Version: 1.0' . "\r\n";
 $headers .= 'Content-Type: text/html; charset=UTF-8' . "\r\n";