PHPMailer不发送CC或BCC

前端之家收集整理的这篇文章主要介绍了PHPMailer不发送CC或BCC前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我已经测试了以下代码几个小时了.电子邮件将发送到通过$mail-> AddAddress()添加的地址,并在收到的电子邮件中说明cc,但是cced的人没有收到电子邮件.我到处寻找,无法找到解决方案的原因.我已经运行了测试,并且正确地将所有变量提交给此代码.

我的服务器正在运行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!
}
老问题,但我最终在这里寻找答案.刚才在其他地方了解到,这些函数AddCC和AddBCC仅适用于win32 SMTP

尝试使用:

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

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

希望这有助于某人,欢呼!

原文链接:https://www.f2er.com/php/130919.html

猜你在找的PHP相关文章