【问题标题】:PHPMailer not sending CC or BCCPHPMailer 不发送 CC 或 BCC
【发布时间】:2013-01-19 10:13:30
【问题描述】:

我已经测试以下代码几个小时了。电子邮件将发送到通过$mail->AddAddress() 添加的地址,并在收到的电子邮件中注明抄送,但抄送人没有收到电子邮件。我到处寻找,找不到解决这种情况的方法。我已经运行了测试并且所有变量都被正确地提交到这个代码中。

我的服务器正在运行 Linux Red Hat

我的代码:

require_once('../smtp/class.phpmailer.php');
//include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded
$mail = new PHPMailer(true); // the true param means it will throw exceptions on errors, which we need to catch
$mail->IsSMTP(); // telling the class to use SMTP
try {
  $mail->SMTPDebug  = 0;                     // enables SMTP debug information (for testing)
  $mail->SMTPAuth   = true;                  // enable SMTP authentication
  $mail->SMTPSecure = "tls";                 // sets the prefix to the server
  $mail->Host       = "smtp.gmail.com";      // sets GMAIL as the SMTP server
  $mail->Port       = $port;                 // set the SMTP port for the GMAIL server  465 or 587
  $mail->Username   = $username;             // GMAIL username
  $mail->Password   = $password;             // GMAIL password

  // Add each email address
  foreach($emailTo as $email){ $mail->AddAddress(trim($email)); }
  if($cc!=''){ foreach($cc as $email){ $mail->AddCC(trim($email)); } }
  if($bcc!=''){ foreach($bcc as $email){ $mail->AddBCC(trim($email)); } }

  $mail->SetFrom($emailFrom, $emailName);
  $mail->AddReplyTo($emailFrom, $emailName);
  $mail->Subject = $subject;
  $mail->AltBody = 'To view the message, please use an HTML compatible email viewer!'; // optional - MsgHTML will create an alternate automatically
  $mail->MsgHTML($content);
 // $mail->AddAttachment('images/phpmailer.gif');      // attachment
 // $mail->AddAttachment('images/phpmailer_mini.gif'); // attachment

  $mail->Send();
  echo'1';exit();
} catch (phpmailerException $e) {
  echo $e->errorMessage(); //Pretty error messages from PHPMailer
} catch (Exception $e) {
  echo $e->getMessage(); //Boring error messages from anything else!
}

【问题讨论】:

  • 你的邮件日志是怎么说的?
  • 这一行:if($cc!=''){ foreach($cc as $email){ $mail->AddCC(trim($email)); } } 显示字符串比较,然后是数组操作。你的数据是什么格式的?
  • 我发现了问题。出于某种原因,它没有发送抄送,因为我在抄送列表中有收件人电子邮件地址。出于某种原因,这是踢它。一旦我从抄送列表中删除了那个,就会完美发送。
  • Phpmailer AddBcc not working 的可能重复项

标签: php email phpmailer


【解决方案1】:

老问题,但我最终在这里寻找答案。刚刚在别处了解到这些功能 AddCC 和 AddBCC 仅适用于 win32 SMTP

尝试使用:

$mail->addCustomHeader("BCC: mybccaddress@mydomain.com"); 

见http://phpmailer.worxware.com/?pg=methods

希望这对某人有所帮助,干杯!

【讨论】:

    【解决方案2】:
    $address = "xxxxx@gmail.com";
    $mail->AddAddress($address, "technical support");
    
    
    $address = "yyyyyy@gmail.com";
    $mail->AddAddress($address, "other");
    
    
    $addressCC = "zzzzzz@gmail.com";
    $mail->AddCC($addressCC, 'cc account');
    
    
    $addressCC = "bcc@gmail.com";
    $mail->AddBCC($addressCC, 'bcc account');
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-01-22
      • 2013-10-11
      • 2011-09-12
      • 1970-01-01
      • 1970-01-01
      • 2010-12-05
      相关资源
      最近更新 更多