试着看这里,但无法解决我的问题。尝试使用PHP发送HTML电子邮件,电子邮件发送出去,但当我收到电子邮件时,它所做的只是显示实际的HTML代码。我尝试了不同的标题代码,但仍然无法正确显示。任何帮助都是极好的!我确定它很简单,我只是错过了一些简单的东西。
<?php
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-type: text/html; charset=iso-8859-1";
$headers = "From: useremail@email.com\n";
$headers .= "Reply-To: " . $_POST["email"] . "\n";
$headers .= "Return-path: " . $_POST["email"];
$sendTo = "useremail@email.com";
$subject = "Pex Heat Estimate Request from Customer {$_POST['custname']}-{$_POST['ProjectName']}:";
$message = "Here is a your Copy of Pex Heat Estimate Request from Customer {$_POST['custname']}-{$_POST['ProjectName']}";
$message .= '<html><body><table>';
foreach ($_POST as $key => $value) {
if (!is_array($value)) {
$message .= '<tr><td>' . $key . '</td><td>' . $value . '</td></tr>';
}
else {
foreach ($_POST[$key] as $itemvalue) {
$message .= '<tr><td>' . $key . '</td><td>' . $itemvalue . '</td></tr>';
}
}
}
$message .= '</body></table></html>';
mail($sendTo, $subject, $message, $headers);
?>
感谢@fred的修复! - 我现在能够开始添加html标签等。我的最后一个问题是如何添加:在$ key之后 - 只是尝试格式化电子邮件,以区分带有标签的列和实际数据在右边。
<?php
$headers = "MIME-Version: 1.0\n";
$headers .= "Content-type: text/html; charset=iso-8859-1";
$headers .= "From: jonvanasco@gmail.com\n";
$headers .= "Reply-To: " . $_POST["email"] . "\n";
$headers .= "Return-path: " . $_POST["email"];
$sendTo = "jonvanasco@gmail.com";
$subject = "Pex Heat Estimate Request from Customer {$_POST['custname']}-{$_POST['ProjectName']}:";
$message = "Here is a your Copy of Pex Heat Estimate Request from Customer {$_POST['custname']}-{$_POST['ProjectName']}";
$message .= '<html><body><p>Thank you for submitting your Estimate Request with Pexheat.com : <u></u><u></u> Please remember to fax or email a floor plan diagram to us at 631-382-8225 or <a href="mailto:quotes@pexheat.com" target="_blank">quotes@pexheat.com</a>.<u></u><u></u></p>
<p>- Pexheat.com Staff</p><br></br><div>
<center><p align="center"><h3><strong>Pexheat.com Estimate Request</strong></h3><u></u><u></u></p></center><br></br>
</div><table width="80%" align="center">';
foreach ($_POST as $key => $value) {
if (!is_array($value)) {
$message .= '<tr><td>' . $key . '</td><td>' . $value . '</td></tr>';
}
else {
foreach ($_POST[$key] as $itemvalue) {
$message .= '<tr><td>' . $key . '</td><td>' . $itemvalue . '</td></tr>';
}
}
}
$message .= '</table></body><div><h5 align="center">Pexheat.com, 30 South Ave, Smithtown, NY 11787, Phone 631-240-9173, Fax 631-382-8225 | email: <a href="mailto:quotes@pexheat.com" target="_blank">quotes@pexheat.com</a>, Website: <a href="http://www.pexheat.com/" target="_blank">www.pexheat.com</a></h5></div></html>';
mail($sendTo, $subject, $message, $headers);
?>
答案 0 :(得分:1)
中缺少(连接)点
$headers = "From: useremail@email.com\n";
^-- there
所以
$headers .= "From: useremail@email.com\n";
删除
中的那个$headers .= "MIME-Version: 1.0\n";
^-- delete that
所以
$headers = "MIME-Version: 1.0\n";
正在发生的事情是,您的标头已损坏,并且会阻止标头正确连接&#34;链接&#34;。
当(链)链接断开时,它只会被打破&#34;并且没有&#34;#34;工作&#34;了。
<?php
$headers = "MIME-Version: 1.0\n";
$headers .= "Content-type: text/html; charset=iso-8859-1";
$headers .= "From: useremail@email.com\n";
$headers .= "Reply-To: " . $_POST["email"] . "\n";
$headers .= "Return-path: " . $_POST["email"];
$sendTo = "useremail@email.com";
$subject = "Pex Heat Estimate Request from Customer {$_POST['custname']}-{$_POST['ProjectName']}:";
$message = "Here is a your Copy of Pex Heat Estimate Request from Customer {$_POST['custname']}-{$_POST['ProjectName']}";
$message .= '<html><body><table>';
foreach ($_POST as $key => $value) {
if (!is_array($value)) {
$message .= '<tr><td>' . $key . '</td><td>' . $value . '</td></tr>';
}
else {
foreach ($_POST[$key] as $itemvalue) {
$message .= '<tr><td>' . $key . '</td><td>' . $itemvalue . '</td></tr>';
}
}
}
$message .= '</body></table></html>';
mail($sendTo, $subject, $message, $headers);
?>
另外,正如Marc在他的评论中所述,我引用:
&#34;简单:不要制作自己的哑剧电子邮件。使用PHPMailer或Swiftmailer。他们将这些混乱减少到只有几行实际的邮件相关代码,剩下的只是你用html提供。&#34;
链接:
答案 1 :(得分:0)
替换此处的代码
$message .= '</body></table></html>';
到
$message .= '</table></body></html>';
您需要先关闭桌子然后再关闭身体