HTML电子邮件只显示为代码

时间:2011-07-28 14:38:47

标签: php html email

  

可能重复:
  Sending HTML email from PHP

使用PHP发送电子邮件。

我希望它是基于HTML的,但当我收到收件箱中的电子邮件时,它只显示原始代码。

如何将其作为HTML而不是文本进行互动?!

对于每个要求查看代码的人

<?php
//The email of the sender
$email = $_POST['email'];
//The message of the sender
$message = "<html></html>";
//The subject of the email
$subject = "Fanshawe Student Success";
$extra = $email."\r\nReply-To: ".$email."\r\n";
mail($email,$subject,$message,$extra);
?>

2 个答案:

答案 0 :(得分:7)

来自文档:http://php.net/manual/en/function.mail.php

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

显然必须将$ header传递给邮件

答案 1 :(得分:4)

你去:

// multiple recipients
$to  = 'someemail@address.com';

//subject
$subject = 'Email Template for Lazy People';

//message body
$message = "
<html>
<head>
  <title>My Title</title>
</head>
<body>
    <div>
        <b>My email body</b>
    </div>
</body>
</html>
";

//add headers
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'To: yourself<info@yourself.com>' . "\r\n";
$headers .= 'From: myself<info@myself.com>' . "\r\n";

//send mail
mail($to, $subject, $message, $headers);