【问题标题】:PHP mail system that sends a HTML email发送 HTML 电子邮件的 PHP 邮件系统
【发布时间】:2013-11-29 15:40:53
【问题描述】:

所以,基本上我正在尝试从支持表单发送一封电子邮件,当它发送时我希望它使用指定的 CSS 文件和 html。消息发送完毕,所有 PHP 扇区都已完成,但电子邮件是这样显示的:

<html>
<head>
   <link rel="stylesheet" type="text/css" href="http://jake-brunton.com/wtf/corner/contact/mailerCss.css">
</head>
<body>
<div id="top">A new query &#92; question!</div>
<br />
<div id="mBody">
    <b> Email </b>: tester@testmail.net<br />
    <b> Subject </b>: Test Subject<br />
    <b> Name </b>: Jake Bdawg<br />
    <b> Message</b>: <br /> Jkat is my other name
</div>
</body>
</html>

这也是我第一次尝试这样的事情。我已经在 PHP 中使用了转义斜线来确保引号不会弄乱任何东西,但我仍然无法让它在 HTML 中显示。这是 PHP 文件:

<?php
$email = $_POST['email'];
$subjectName = $_POST['subject'];
$name = $_POST['name'];
$messageText = $_POST['message'];

$to = "test@weeshare.ws"; 
$from = " $email ";
$subject = " $subject ";

$message ="<html>
<head>
<link rel=\"stylesheet\" type=\"text/css\" href=\"http://jake-brunton.com/wtf/corner/contact/mailerCss.css\">
</head>
<body>
<div id=\"top\">A new query &#92; question!</div>
<br />
<div id=\"mBody\">
<b> Email </b>: $email<br />
<b> Subject </b>: $subjectName<br />
<b> Name </b>: $name<br />
<b> Message</b>: <br /> $messageText
</div>
</body>
</html>";

$headers = "MIME-Version: 1.0rn"; 
$headers .= "Content-type: text/html; charset=iso-8859-1rn"; 
$headers  .= "From: $from\r\n"; 
mail($message);

echo "<center>Message Sent Successfully! We\'ll reply within 2 to 4 business days. Please return to the <a href=\"http://jake-brunton.com/wtf/corner\">Home page</a>";
?>

有人知道这里有什么问题吗?

【问题讨论】:

标签: php html css email


【解决方案1】:

您的标题不正确。

立足于以下几点:

$headers = "MIME-Version: 1.0\n";
$headers .= "Content-Type: text/html; charset=iso-8859-1\n";
$headers .= "From: $email" . "\r\n" .
            "Reply-To: $email" . "\r\n" .
            'X-Mailer: PHP/' . phpversion();

根据mail()headers() http://php.net/manual/en/function.mail.php 上的手册

另外,请记住,许多电子邮件服务会忽略您的样式表,尤其是 Google。

  • 使用内联 CSS 以获得更好的结果。

【讨论】:

    【解决方案2】:
     htmlspecialchars_decode($message);  
    

    将允许在字符串中放置特殊的 html 字符

    内容类型为:

     Content-Type: text/plain; charset=us-ascii
    

    【讨论】:

      猜你喜欢
      • 2011-03-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-17
      相关资源
      最近更新 更多