php PHPMailer 不发送抄送或密件抄送

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14691373/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 07:48:57  来源:igfitidea点击:

PHPMailer not sending CC or BCC

phpemailphpmailer

提问by Douglas Cottrell

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.

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

My server is running Linux Red Hat

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

My Code:

我的代码:

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!
}

回答by i_a

Old question, but I ended up here looking for an answer. Just learned elsewhere that those functions AddCCand AddBCConly work with win32 SMTP

老问题,但我最终在这里寻找答案。刚刚在别处了解到这些函数AddCCAddBCC仅适用于win32 SMTP

Try using:

尝试使用:

$mail->addCustomHeader("BCC: [email protected]"); 

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

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

Hope this helps someone, cheers!

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

回答by user2823361

$address = "[email protected]";
$mail->AddAddress($address, "technical support");


$address = "[email protected]";
$mail->AddAddress($address, "other");


$addressCC = "[email protected]";
$mail->AddCC($addressCC, 'cc account');


$addressCC = "[email protected]";
$mail->AddBCC($addressCC, 'bcc account');