简体   繁体   中英

PHP Pear Email Text Encoding not being excepted

How do I correctly set the text encoding for a multi-part email using Pear ?

I've looked at many examples and I believe I am setting it correctly. However, When sending emails they are arriving with charset=ISO-8859-1 even though I specify UTF-8 .

This problem began when I decided to send a multi-part email with both text and HTML parts. I have tried setting a content type but it does not appear to make a difference.

Below is the code I am using. Any suggestions appreciated.

function send_html_email($to, $from, $subject, $html, $plainTxt ) {
    require_once "Mail.php";
    require_once "Mail/mime.php";    

    $host = "ssl://secure.xxx.com";
    $port = "xxx";
    $username = "xxx";
    $password = "xxx";

    $headers = array (
    'charset' => 'UTF-8',
    'From' => $from,
            'To' => $to,
            'Subject' => $subject,
        'MIME-Version' => "1.0"
             );  

    $crlf = "\n";
            $mime = new Mail_mime($crlf);

    $mime->setHTMLBody($html); 
    $mime->setTXTBody($plainTxt); 
            $body = $mime->get();
            $headers = $mime->headers($headers);

            $smtp = Mail::factory('smtp', array ('host' => $host,
    'port' => $port,
    'auth' => true,
    'username' => $username,
    'password' => $password)); 

            $mail = $smtp->send($to, $headers, $body);
}

Try headers like such:

$headers['Content-Type'] = "text/plain; charset=\"UTF-8\"";
$headers['Content-Transfer-Encoding'] = "8bit";

Reference: http://pear.php.net/manual/en/package.mail.mail.factory.php#13207

As a side note, Pear is "a framework and distribution system for reusable PHP components". The Mail component is just one of the many available through Pear.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM