php邮件仍然可以查看html标签

时间:2012-09-22 23:51:10

标签: php html email header tags

这是我目前的代码,但在发送时会继续显示html标签:(帮助?

<?php
    $personip = $_POST['name'];
    $personip = getenv("REMOTE_ADDR");
    $typesup = $_POST['typesupport'];
    $timesent = date("F j, Y, g:i a");
    $personemail = $_POST['email'];
    $message = $_POST['message'];
    $headers = "MIME-Version: 1.0\r\n";
    $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

    $body = "<html><body>"."Support Request - iSter"."<br>"."Sent from IP:"."$personip"." "."from:"."$personemail"."At time:"."$timesent"."<br>"."Message:"."<br>"."$message";


    $to      = 'jon*******5@gmail.com, anotheruser@example.com';
    $subject = "Request on $typesup"." from $personemail";

    $headers = 'From: support@mysite.im';

    mail($to, $subject, $body, $headers);
?>

2 个答案:

答案 0 :(得分:1)

您在发送之前覆盖了标题:

$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

$body = "<html><body>"."Support Request - iSter"."<br>"."Sent from IP:"."$personip"." "."from:"."$personemail"."At time:"."$timesent"."<br>"."Message:"."<br>"."$message";


$to      = 'jon*******5@gmail.com, anotheruser@example.com';
$subject = "Request on $typesup"." from $personemail";

$headers = 'From: support@mysite.im'; // THIS LINE IS OVERWRITING IT! 

将=更改为a。=

希望有所帮助。

答案 1 :(得分:0)

您需要正确关闭html标记:

$body = "<html><body>"."Support Request - iSter"."<br>"."Sent from IP:"."$personip"." "."from:"."$personemail"."At time:"."$timesent"."<br>"."Message:"."<br>"."$message</body></html>";

您在放完邮件后忘记添加</body></html>