【问题标题】:HTML email just shows as Code [duplicate]HTML 电子邮件仅显示为代码 [重复]
【发布时间】:2011-10-15 04:55:18
【问题描述】:

可能重复:
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);
?>

【问题讨论】:

标签: php html email


【解决方案1】:

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

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

显然 $headers 必须传递给邮件

【讨论】:

  • 我认为问题要深得多:D
【解决方案2】:

给你:

// 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);

【讨论】:

  • 谢谢大家,当我们检查邮件脚本时,我们的教授从不检查标题,所以对我来说不是那么明显。但非常感谢!
  • 这对我有帮助。谢谢
猜你喜欢
  • 1970-01-01
  • 2017-01-22
  • 1970-01-01
  • 2011-09-10
  • 2022-07-23
  • 1970-01-01
  • 2018-07-04
  • 2019-10-14
  • 2012-06-27
相关资源
最近更新 更多