CC电子邮件不会使用PEAR发送

时间:2013-08-25 23:12:37

标签: php email pear

我已经阅读了有关此问题的类似帖子,但无法完全了解我在这里做错了什么。收到'收件人'电子邮件确定。

但是,使用以下脚本时,我无法收到'CC'电子邮件。 任何帮助将不胜感激。

// Require Pear Mail Packages 
require_once ("Mail.php"); 
require_once ("Mail/mime.php");
require_once ("Mail/mail.php");

$crlf = "\n"; 
$from = "Company <admin@example.com>";
$to =  $purchasersName . "<" . $purchasersEmail . ">";
$cc = "Company <admin@example.com>";
$subject = "Company Order Confirmation";

$host = "localhost";
$port = "25";
$username = "the username";
$password = "the password";

$hdrs = array ('From' => $from,
'To' => $to,
'Cc' => $cc,
'Subject' => $subject);

$mime = new Mail_mime(array('eol' => $crlf));
$mime->setHTMLBody($mailBody);
$body = $mime->get();
$hdrs = $mime->headers($hdrs);

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

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

1 个答案:

答案 0 :(得分:5)

此评论位于此页面上的梨形文档中

http://pear.php.net/manual/en/package.mail.mail.send.php

(如果你想要其他选项,你可以尝试http://swiftmailer.org,我现在已经在很多项目中使用过它了)

  

备注:arminfrey@gmail.com 2007-07-08 05:13 UTC为了发送   用smtp发送电子邮件到cc或bcc,你必须列出cc电子邮件地址   作为收件人(决定发送电子邮件的位置)和收件人   cc标头,告诉邮件客户端如何显示它。

     

以下是我使用的代码:

     

$ to ='to@example.com'; $ cc ='cc@example.com';

     

$ recipients = $ to。“,”。$ cc;

     

$ headers ['From'] ='from@example.com'; $ headers ['To'] = $ to;   $ headers ['Subject'] ='测试消息'; $ headers ['Cc'] =   'cc@example.com'; $ headers ['Reply-To'] ='from@example.com';

     

$ send = $ mail-&gt;发送($ recipients,$ headers,$ body);

相关问题