我試圖在PHP中發送HTML電子郵件,但它始終顯示電子郵件程序中電子郵件的源代碼。但它應該將html電子郵件呈現爲html,而不是將源代碼顯示爲電子郵件內容。嘗試使用sendmail發送/發送html電子郵件,但顯示電子郵件的源代碼
我把我的郵件是這樣的:
$fd = popen("/var/qmail/bin/sendmail -t","w") or die("Couldn't Open Sendmail");
fputs($fd, "To: ".$to2." \n");
fputs($fd, "From: \"Test <[email protected]>\" \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」)或死(「無法打開 Sendmail」); fputs($ fd,「To:」。$ to1。「\ n」); fputs($ fd,「From: \」Test \「\ n」); fputs($ fd,「Subject:」。$ 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」); fds($ fd,「 - 」。$ mime_boundary。「\ n」); fputs($ fd,「Content-Type: text/html; charset = \」utf-8 \「\ n」); fputs($ fd, 「Content-Transfer-Encoding:quoted-printable \ n」); fputs($ fd,「 \ n」); fputs($ fd,$ sendmail_body。「\ n」); fputs($ fd, 「 - 」。$ mime_boundary。「 - \ n」); pclose函數($ FD);
而我的html文件的第一行是空的,或者我在html內容前添加一個\ n。
不得不編輯我的問題,因爲我忘了一些行 –