0

我正在尝试使用 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 ?&icirc;??&icirc;&acirc;</p>

<p>&nbsp;</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 ?&icirc;??&icirc;&acirc;</p>

<p>&nbsp;</p>
test<br>
abcd<br>
test semnatura<img height=3D"1px" width=3D"1px" src=3D"******" /></body>=
</html>

--=_f11764219c81f7cdd5e1729bb3b44ca6--

请注意,当我在没有内容类型标头的情况下发送它时,电子邮件会很好,但我希望它为 utf-8 编码以用于变音符号。

4

1 回答 1

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); 
于 2013-02-22T16:37:37.850 回答