所以,基本上我正在尝试从支持表单发送一封电子邮件,当它发送时我希望它使用指定的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 \ 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 \ 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>";
?>
有人知道这里有什么问题吗?
答案 0 :(得分:2)
您的标头不正确。
基于以下内容:
$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。
答案 1 :(得分:0)
htmlspecialchars_decode($message);
将允许将特殊的html字符放在字符串
中和内容类型:
Content-Type: text/plain; charset=us-ascii