PHP 电子邮件转 HTML 问题
我正在尝试使用 PHP 发送电子邮件,但收到一个奇怪的错误。
在 PHP 中,我有:
<?php
mail($email_to, $email_subject, $headers, $message);
$email_to = '[email protected]';
$email_subject = 'Hello World';
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$message = '<html><body>';
$message .= '<table rules="all" style="border-color: #666;" cellpadding="10">';
$message .= "<tr><td><strong>Email:</strong> </td><td>" . strip_tags($_POST['test1']) . "</td></tr>";
$message .= "<tr><td><strong>Message:</strong> </td><td>" . strip_tags($_POST['test2']) . "</td></tr>";
$message .= "</table>";
$message .= '</body></html>';
if(mail($email_to, $email_subject, $headers, $message)){
echo 'sent';
}else{
echo 'failed';
}
?>
有了这个,我收到纯文本:
<html><body><table rules="all" style="border-color: #666;" cellpadding="10"><tr><td>
<strong>Email:</strong> </td><td>[email protected]</td></tr><tr><td>
<strong>Message:</strong> </td><td>hello world</td></tr></table></body></html>
From: [email protected]
MIME-Version: 1.0
Content-Type: text/html; charset=ISO-8859-1
谁能发现我做错了什么?我在两台不同的服务器上进行了测试,结果相同。
I am trying to send an email with PHP but I get a weird error.
In the PHP I have:
<?php
mail($email_to, $email_subject, $headers, $message);
$email_to = '[email protected]';
$email_subject = 'Hello World';
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$message = '<html><body>';
$message .= '<table rules="all" style="border-color: #666;" cellpadding="10">';
$message .= "<tr><td><strong>Email:</strong> </td><td>" . strip_tags($_POST['test1']) . "</td></tr>";
$message .= "<tr><td><strong>Message:</strong> </td><td>" . strip_tags($_POST['test2']) . "</td></tr>";
$message .= "</table>";
$message .= '</body></html>';
if(mail($email_to, $email_subject, $headers, $message)){
echo 'sent';
}else{
echo 'failed';
}
?>
With this I receive as a plain text:
<html><body><table rules="all" style="border-color: #666;" cellpadding="10"><tr><td>
<strong>Email:</strong> </td><td>[email protected]</td></tr><tr><td>
<strong>Message:</strong> </td><td>hello world</td></tr></table></body></html>
From: [email protected]
MIME-Version: 1.0
Content-Type: text/html; charset=ISO-8859-1
Can anyone spot what I'm I doing wrong? I tested this on 2 different servers with the same results.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
应该是
You've got $message and $headers in the bad order.
It should be
You've got $message and $headers in the wrong order.
您混淆了 $message 和 $headers 的位置。试试这个
mail($email_to, $email_subject, $message, $headers)
http://php.net/manual/en/function.mail.php
You have mixed up the position of the $message and $headers. Try this instead
mail($email_to, $email_subject, $message, $headers)
http://php.net/manual/en/function.mail.php