2009-06-06 86 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格式提供。此外,您不需要与添加附件相关的部分,但为了知识的缘故,我留下了它们。