PHPMailer不发送CC或BCC [英] PHPMailer not sending CC or BCC

查看:253
本文介绍了PHPMailer不发送CC或BCC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经测试了几个小时的以下代码。电子邮件将发送到通过 $ mail-> AddAddress()添加的地址,并在收到的电子邮件中指出cc,但是该人不会收到该电子邮件。我看到无处不在,找不到解决这个问题的解决方案。我已经运行测试,所有的变量都正确地提交给这个代码。

I have been testing the following code for hours. The email will send to the addresses added through $mail->AddAddress() and in the received email it states the cc but the person cced does not receive the email. I have looked everywhere and can not find a solution to why this is happening. I have run tests and all variables are being submitted to this code properly.

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

My server is running 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

Old question, but I ended up here looking for an answer. Just learned elsewhere that those functions AddCC and AddBCC only work with win32 SMTP

尝试使用:

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

请参阅 http://phpmailer.worxware.com/?pg=methods

希望这有助于人,欢呼!

Hope this helps someone, cheers!

这篇关于PHPMailer不发送CC或BCC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆