gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 04:15:34 24 4
gpt4 key购买 nike

所以,基本上我正在尝试从支持表单中获取要发送的电子邮件,当它发送时我希望它使用指定的 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>";
?>

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

最佳答案

您的 header 不正确。

基于以下几点:

$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 以获得更好的结果。

关于发送 HTML 电子邮件的 PHP 邮件系统,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20014754/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com