我正在尝试发送一封既包含文本又包含HTML的邮件,但我无法正确发送正确的头信息。特别地,我想设置Content-Type头信息,但我找不到如何分别为HTML和文本部分设置它的方法。
这是我的代码:
这是我的代码:
$headers = array(
'From' => 'info@mydomain.com',
'Return-Path' => 'info@mydomain.com',
'Subject' => 'mysubject',
'text_encoding' => '7bit',
'text_charset' => 'UTF-8',
'html_charset' => 'UTF-8',
'head_charset' => 'UTF-8',
'Content-Type' => 'text/html; charset=UTF-8'
);
$mime = new Mail_mime();
$html = '<html><body><b>my body</b></body></html>';
$text = 'my body';
$mime->setTXTBody($text);
$mime->setHTMLBody($html);
$body = $mime->get();
$headers = $mime->headers($headers);
$mail_object =& Mail::factory('smtp', $GLOBALS['pear_mail_config']);
$mail_object->send('test@mydomain.com', $headers, $body);
这是我收到的电子邮件:
From: info@mydomain.com
Subject: mysubject
text_encoding: 7bit
text_charset: UTF-8
html_charset: UTF-8
head_charset: UTF-8
Content-Type: multipart/alternative;
boundary="=_7adf2d854b1ad792c802a9db31084520"
Message-Id: <.....cut.....>
Date: Mon, 8 Oct 2012 15:40:54 +0200 (CEST)
To: undisclosed-recipients:;
--=_7adf2d854b1ad792c802a9db31084520
Content-Transfer-Encoding: 7bit
Content-Type: text/plain; charset="ISO-8859-1"
my body
--=_7adf2d854b1ad792c802a9db31084520
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset="ISO-8859-1"
<html><body><b>my body</b></body></html>
--=_7adf2d854b1ad792c802a9db31084520--
看起来我设置的Content-Type标头完全被忽略了。我曾经期望有一些setHTMLHeaders和setTXTHeaders函数,但似乎没有这样的东西。我错过了什么吗?如何将两个Content-Type标头都设置为UTF-8?
require_once 'Mail/mime.php';
。 - Knu