HTML电子邮件只显示为代码

Phi*_*ide 3 html php email

可能重复:
从PHP发送HTML电子邮件

使用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);
?>
Run Code Online (Sandbox Code Playgroud)

Tim*_*han 7

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

$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
Run Code Online (Sandbox Code Playgroud)

显然$ header必须传递给邮件


小智 5

干得好:

// 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);
Run Code Online (Sandbox Code Playgroud)