【发布时间】:2012-01-06 06:27:39
【问题描述】:
我正在尝试用 PHP 发送一封 HTML 电子邮件,但它总是在电子邮件程序中显示电子邮件的源代码。但它应该将 html 电子邮件呈现为 html,而不是将源代码显示为电子邮件内容。
我这样发送电子邮件:
$fd = popen("/var/qmail/bin/sendmail -t","w") or die("Couldn't Open Sendmail");
fputs($fd, "To: ".$to2." \n");
fputs($fd, "From: \"Test <test@test.com>\" \n");
fputs($fd, "Subject: ".$subject." \n");
fputs($fd, "X-Mailer: PHP5 \n");
fputs($fd, "Mime-Version: 1.0 \n");
fputs($fd, " \n");
fputs($fd, "--".$mime_boundary."");
fputs($fd, "Content-Type: text/html; charset=\"utf-8\"; boundary=\"".$mime_boundary."\" \n");
fputs($fd, "Content-Transfer-Encoding: quoted-printable \n");
fputs($fd, " \n");
fputs($fd, $sendmail_body." \n");
fputs($fd, "".$mime_boundary."--");
pclose($fd);
html文件的内容是这样的:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de" lang="de">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Test</title>
<style type="text/css">
body { font: normal 12px Verdana, Arial, Helvetica, sans-serif; }
</style>
</head>
<body>
</body>
</html>
现在可以了:
$fd = popen("/var/qmail/bin/sendmail -t","w") 或 die("无法打开 发送邮件"); fputs($fd, "收件人: ".$to1." \n"); fputs($fd, "发件人: \"测试\" \n"); fputs($fd, "主题: ".$subject." \n"); fputs($fd, "X-Mailer: PHP5 \n"); fputs($fd, "Mime-Version: 1.0 \n"); fputs ($fd, "Content-Type: multipart/alternative; boundary=\"".$mime_boundary."\" \n"); fputs($fd, "\n"); fputs($fd, "--".$mime_boundary."\n"); fputs($fd, "内容类型: 文本/html;字符集=\"utf-8\"\n"); fputs($fd, “内容传输编码:引用打印\n”); fputs($fd, " \n"); fputs($fd, $sendmail_body." \n"); fputs($fd, "--".$mime_boundary."--\n"); pclose($fd);
而且我的html文件的第一行是空的或者我在html内容前加了一个\n。
【问题讨论】:
-
因为我忘记了一些行,所以不得不编辑我的问题
标签: php sendmail html-email