我正在尝试使用PEAR发送UTF-8电子邮件,但每当我设置内容类型标头时,发送的电子邮件都会以一种奇怪的方式被破坏。
这些是我用于标题和梨本身的设置:
$headers = array (
'From' => $emailAdresa,
'To' => $emailDest,
'Subject' => $subiect,
'Return-Path' => '****@****.eu',
'X-Codent' => '['.$codent_header.']',
'X-Ent' => '['.$ent_header.']',
'X-Bzd' => '['.$baza_date.']',
'X-Email' => '['.$email['Email'].']',
'Content-Type' => 'text/html; charset=UTF-8'
);
$hdrs = $mime->headers($headers, true);
$smtp = Mail::factory('smtp',
array ('host' => $emailServer,
'auth' => true,
'port' => ''.$emailPort.'',
'username' => $emailUtilizator,
'password' => $emailParola));
$mail = $smtp->send($emailDest, $hdrs, $body);
这是我在设置Content-type标头时收到的电子邮件:
Return-Path: <*******>
Received: from localhost ([93.114.43.202])
by mx.google.com with ESMTPS id fy17sm687802bkc.6.2013.02.22.06.23.42
(version=TLSv1 cipher=RC4-SHA bits=128/128);
Fri, 22 Feb 2013 06:23:43 -0800 (PST)
Message-ID: <51277f6f.9178cd0a.600a.2b1c@mx.google.com>
Date: Fri, 22 Feb 2013 06:23:43 -0800 (PST)
Content-Type: text/html; charset=UTF-8
MIME-Version: 1.0
From: ******
To: ******
Subject: test
Return-Path: ******
X-Codent: [230802]
X-Ent: [Note]
X-Bzd: [1]
X-Email: [******]
--=_f11764219c81f7cdd5e1729bb3b44ca6
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset=ISO-8859-1
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www=
=2Ew3.org/TR/REC-html40/loose.dtd">
<html><body><p>test ?î??îâ</p>
<p> </p>
test<br>
abcd<br>
test semnatura<img height=3D"1px" width=3D"1px" src=3D"******" /></body>=
</html>
--=_f11764219c81f7cdd5e1729bb3b44ca6
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset=ISO-8859-1
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www=
=2Ew3.org/TR/REC-html40/loose.dtd">
<html><body><p>test ?î??îâ</p>
<p> </p>
test<br>
abcd<br>
test semnatura<img height=3D"1px" width=3D"1px" src=3D"******" /></body>=
</html>
--=_f11764219c81f7cdd5e1729bb3b44ca6--
请注意,当我发送没有内容类型标题时,电子邮件就可以了,但我希望它为变音符号编码utf-8。
答案 0 :(得分:0)
您还需要设置从$ mime对象返回的正文内容的编码。
// set encoding and specify charsets
$mimeparams=array();
$mimeparams['text_encoding']="8bit";
$mimeparams['text_charset']="UTF-8";
$mimeparams['html_charset']="UTF-8";
$mimeparams['head_charset']="UTF-8";
// set the content
$mime->setTXTBody($text);
$mime->setHTMLBody($html);
// retrieve the body
$body = $mime->get($mimeparams);