-1

我有以下 php 代码:

 <?php
header('Content-Type: text/html; charset=utf-8');
if (isset($_POST['email']))
//if "email" is filled out, send email
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$message = $_POST['message'];
$formcontent="<html><body>
<span style='background-color: #cdcdcd'>
text: $name
</span>
text: $phone
<span style='background-color: #cdcdcd'>
text: $email
</span>
text: $message </html><body/>";
$recipient = "email@email.com";
$subject = "text text text ";
$headers = "From: $email" . "\r\n" .
    "Reply-To: $email" . "\r\n" .
    'X-Mailer: PHP/' . phpversion();
mail($recipient, $subject, $formcontent, $headers) or die("Error!");
echo "Thank You!";
?>

问题是当我收到电子邮件时,我看到电子邮件正文中的所有 HTML 标记,并且电子邮件没有样式。

我的问题是我该如何解决?

4

3 回答 3

3

您实际上并未在电子邮件标头变量中设置 Content-type 标头

$headers = "From: $email" . "\r\n" .
"Reply-To: $email" . "\r\n" .
"X-Mailer: PHP/" . phpversion() . "\r\n" .
"Content-Type: text/html; charset=utf-8";

在连接字符串时也可以使用单引号或双引号

于 2013-09-01T10:55:15.773 回答
0

你不需要$headers_text/htmlheader('Content-Type: text/html; charset=utf-8');

如果你没有得到更好的答案,我稍后会改进我的。目前时间紧。

于 2013-09-01T10:52:15.670 回答
0

试试看 -

删除线

header('Content-Type: text/html; charset=utf-8');

并更换

$headers = "From: $email" . "\r\n" .
            "Reply-To: $email" . "\r\n" .
            'X-Mailer: PHP/' . phpversion();

经过

$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();
于 2013-09-01T10:59:32.373 回答