【问题标题】:Problem With sending Email in , Unknown Characters !发送电子邮件的问题,未知字符!
【发布时间】:2009-06-06 20:56:42
【问题描述】:

我在用波斯语发送电子邮件时遇到问题。 gmail上没问题,所有文字都很好。但在 yahoo、cpanel webmail 等订单中,我收到了未知字符。我应该怎么做才能解决这个问题?

这是我的代码:

<?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 邮件发送电子邮件。

【问题讨论】:

    标签: php email


    【解决方案1】:

    您需要实例化一个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'    => 'you@yourdomain.com',
                  '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('postmaster@localhost', $hdrs, $body);
    ?>
    

    我已编辑上述文档示例以包含 Content-Type 标头。建议将您的消息正文作为纯文本和 HTML 提供,以防客户端不支持 HTML。此外,您不需要与添加附件相关的部分,但为了知识,我已经留下了它们。

    【讨论】:

      猜你喜欢
      • 2012-01-02
      • 1970-01-01
      • 2015-10-16
      • 1970-01-01
      • 2020-04-26
      • 2016-08-12
      • 2013-04-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多