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);

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

报告相同问题?

悬赏问题

  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波
  • ¥15 针对曲面部件的制孔路径规划,大家有什么思路吗
  • ¥15 钢筋实图交点识别,机器视觉代码
  • ¥15 如何在Linux系统中,但是在window系统上idea里面可以正常运行?(相关搜索:jar包)
  • ¥50 400g qsfp 光模块iphy方案
  • ¥15 两块ADC0804用proteus仿真时,出现异常
  • ¥15 关于风控系统,如何去选择