简体   繁体   English

发送HTML电子邮件的PHP邮件系统

[英]PHP mail system that sends a HTML email

So, bascially I'm trying to get an email to send from a support form, and when it sends I want it to use a specified CSS file and html. 所以,基本上我正在尝试从支持表单发送一封电子邮件,当它发送时我希望它使用指定的CSS文件和html。 The message sends and all of the PHP sector is complete, but this is how the email appears: 消息发送并且所有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>

This is my first time trying something like this aswell. 这是我第一次尝试这样的事情。 I already use the escape slash in PHP to make sure the quotations do not mess anything up, but I still can't get it to display in HTML. 我已经在PHP中使用了转义斜杠,以确保引用不会弄乱任何东西,但我仍然无法让它以HTML格式显示。 Here's the PHP file: 这是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>";
?>

Anyone know what's wrong here? 谁知道这里有什么问题?

Your headers are incorrect. 你的标题不正确。

Base yourself on the following: 基于以下内容:

$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();

as per the manual on mail() and headers() http://php.net/manual/en/function.mail.php 根据mail()headers() http://php.net/manual/en/function.mail.php上的手册

Also, do keep in mind that many email services will ignore your stylesheet, especially Google. 另外,请记住,许多电子邮件服务会忽略您的样式表,尤其是Google。

  • Use inline CSS for better results. 使用内联CSS可获得更好的结果。
 htmlspecialchars_decode($message);  

will allow special html characters to be placed in the string 将允许特殊的html字符放在字符串中

and a content type of : 和内容类型:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM