2009-06-06 15 views
1

我在發送波斯語電子郵件的問題。在Gmail上沒問題,所有的文字都顯示正常。但在像雅虎,cPanel網絡郵件等命令我收到未知的字符。我應該怎麼做才能解決這個問題?發送電子郵件的問題,未知的字符!

這裏是我的代碼:

<?php 
function emailHtml($from, $subject, $message, $to) { 
    require_once "Mail.php"; 

    $headers = array ('MIME-Version' => "1.0", 'Content-type' => "text/html; charset=utf-8;", 'From' => $from, 'To' => $to, 'Subject' => $subject); 

    $m = Mail::factory('mail'); 

    $mail = $m->send($to, $headers, $message); 
    if (PEAR::isError($mail)){ 
     return 0; 
    }else{ 
     return 1; 
    } 
} 
?> 

我使用PEAR郵件發送電子郵件。

回答

2

您需要實例化一個Mail_Mime,設置標題和正文HTML,從您的MIME實例中檢索它們並將它們傳遞給您的Mail實例。以從文檔引用example

<?php 
include('Mail.php'); 
include('Mail/mime.php'); 

$text = 'Text version of email'; 
$html = '<html><body>HTML version of email</body></html>'; 
$file = '/home/richard/example.php'; 
$crlf = "\n"; 
$hdrs = array(
       'From' => '[email protected]', 
       'Subject' => 'Test mime message', 
       'Content-Type' => 'text/html; charset="UTF-8"' 
      ); 

$mime = new Mail_mime($crlf); 

$mime->setTXTBody($text); 
$mime->setHTMLBody($html); 
$mime->addAttachment($file, 'text/plain'); 

//do not ever try to call these lines in reverse order 
$body = $mime->get(); 
$hdrs = $mime->headers($hdrs); 

$mail =& Mail::factory('mail'); 
$mail->send('[email protected]', $hdrs, $body); 
?> 

我已經編輯上述文檔示例爲包括Content-Type頭。如果客戶端不支持HTML,建議您將郵件正文以純文本格式和HTML格式提供。此外,您不需要與添加附件相關的部分,但爲了知識的緣故,我留下了它們。