duanli0453 2013-08-25 23:12
浏览 60
已采纳

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

I have read the similar posts about this problem but can't quite get my head around what I am doing wrong here. The 'To' email is received ok.

However, I can not get the 'CC' email to send when using the following script. Any help would be much appreciated.

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

$crlf = "
"; 
$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条回答 默认 最新

  • duanmei2805 2013-08-25 23:50
    关注

    This comment is in the pear docs on this page

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

    (If you want other options, you could try http://swiftmailer.org, I have used that on lots of projects now)

    Note by: arminfrey@gmail.com 2007-07-08 05:13 UTC In order to send e-mail to cc or bcc with smtp you have to list the cc e-mail address both as a recipient (which decides where the e-mail is sent) and in the cc header, which tells the mail client how to display it.

    Here is the code I use:

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

    $recipients = $to.", ".$cc;

    $headers['From'] = 'from@example.com'; $headers['To'] = $to; $headers['Subject'] = 'Test message'; $headers['Cc'] = 'cc@example.com'; $headers['Reply-To'] = 'from@example.com';

    $send = $mail->send($recipients, $headers, $body);

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器