php Phpmailer AddBcc 不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12777862/
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
Phpmailer AddBcc not working
提问by Vidya L
I am using phpmailer to sent email, and it works the recipients receive the mail except the bcc and cc details is not showing the mail. Someone can suggest a solution to this . the code is
我正在使用 phpmailer 发送电子邮件,它可以让收件人收到邮件,但密件抄送和抄送详细信息未显示邮件。有人可以为此提出解决方案。代码是
require_once("PHPMailer_v5.1/class.phpmailer.php");
require_once("PHPMailer_v5.1/language/phpmailer.lang-en.php");
$mailer = new PHPMailer();
$mailer->IsSMTP();
$mailer->SMTPAuth = true;
$mailer->SMTPSecure = "tls";
$mailer->Host = 'smtp.gmail.com';
$mailer->Port = 587;
$mailer->Username = "myuserid";
$mailer->Password = "mypassword";
$mailer->FromName = $fromname;
$mailer->From = "myuserid";
$mailer->AddAddress("[email protected]",$toname);
$mailer->Subject = $subject;
$mailer->Body =$content;
$mailer->AddCC("[email protected]", "bla");
$mailer->AddBCC("[email protected]", "test");
if(!$mailer->Send())
{
echo "Message was not sent";
}
else
echo "mail sent";
回答by Sujathan R
回答by GolezTrol
You never see BCC details. That's what they are BCC details for. Even the recipient of a BCC will not see his own name with the recipients.
您永远不会看到密件抄送详细信息。这就是它们的 BCC 详细信息。即使是 BCC 的收件人也不会在收件人中看到他自己的名字。
PS: You noticed you wrote addBCCinstead of AddBCC(capital A)?
PS:你注意到你写的addBCC是AddBCC(大写A)而不是(大写)?
回答by panepeter
From the phpMailer function reference:
来自 phpMailer 函数参考:
Adds a "Bcc" address. Note: this function works with the SMTP mailer on win32, not with the "mail" mailer.
添加“密件抄送”地址。注意:此功能适用于 win32 上的 SMTP 邮件程序,而不适用于“邮件”邮件程序。
This might be causing your issue.
这可能会导致您的问题。
回答by i_a
PHPMailer not sending CC or BCC
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
老问题,但我最终在这里寻找答案。刚刚在别处了解到这些函数 AddCC 和 AddBCC 仅适用于 win32 SMTP
Try using:
尝试使用:
$mail->addCustomHeader("BCC: [email protected]"); See http://phpmailer.worxware.com/?pg=methods
$mail->addCustomHeader("密件抄送:[email protected]"); 请参阅http://phpmailer.worxware.com/?pg=methods
Hope this helps someone, cheers!
希望这对某人有所帮助,干杯!
回答by Herr Barium
It′s addBCC
它是 addBCC
$email->addBCC('[email protected]', 'My Name');
See PHPMailer.php (current version 6.0.5) on line 934 (https://github.com/PHPMailer/PHPMailer/blob/master/src/PHPMailer.php#L934):
请参阅第 934 行的 PHPMailer.php(当前版本 6.0.5)(https://github.com/PHPMailer/PHPMailer/blob/master/src/PHPMailer.php#L934):
/**
* Add a "BCC" address.
*
* @param string $address The email address to send to
* @param string $name
*
* @return bool true on success, false if address already used or invalid in some way
*/
public function addBCC($address, $name = '')
{
return $this->addOrEnqueueAnAddress('bcc', $address, $name);
}
回答by Dan Mihail Matei
the bcc will never show; only TO and CC
密件抄送永远不会显示;只有 TO 和 CC
BCC=Blind Carbon Copy
BCC=密件抄送
回答by Paul Ishak
Here is a working example from the newest release, and on Office 365, I use it to send email from shared folders...
这是最新版本的一个工作示例,在 Office 365 上,我使用它从共享文件夹发送电子邮件...
<?
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require_once('./phpmailer/Exception.php');
require_once('./phpmailer/PHPMailer.php');
require_once('./phpmailer/SMTP.php');
//* Working Example As Of 09/21/2019 - Sends From Shared Mailbox With Mailbox Member
function SendO365EmailTLS($options)
{
$from = isset($options['from']) ? $options['from'] : false;
$recipients = isset($options['recipients']) ? $options['recipients'] : false;
$ccRecipeints = isset($options['ccrecipients']) ? $options['ccrecipients'] : [];
$bccRecipients = isset($options['bccrecipients']) ? $options['bccrecipients'] : [];
$attachments = isset($options['attachments']) ? $options['attachments'] : [];
$credentials = isset($options['credentials']) ? $options['credentials'] : false;
$subject = isset($options['subject']) ? $options['subject'] : '';
$body = isset($options['body']) ? $options['body'] : '';
if(!$from) throw new Exception('Cannot send email with blank \'from\' field');
if(!$recipients) throw new Exception('Cannot send email, no recipients specified!');
if(!$credentials) throw new Exception('Cannot send email, credentials not provided!');
$mail = new PHPMailer;
foreach($recipients as $recipient) $mail->addAddress( $recipient[ 'email'], $recipient['name']);
foreach($ccRecipeints as $ccRecipient) $mail->addCC( $ccRecipient[ 'email'], $ccRecipient['name']);
foreach($bccRecipients as $bccRecipient) $mail->addBCC( $bccRecipient['email'],$bccRecipient['name']);
foreach($attachments as $attachment) $mail->addAttachment($attachment[ 'path' ], $attachment['name']);
$mail->setFrom($from['email'], $from['name']);
$mail->Username = $credentials['username'];
$mail->Password = $credentials['password'];
$mail->Host = 'smtp.office365.com';
$mail->Subject = $subject;
$mail->SMTPSecure = 'tls';
$mail->Body = $body;
$mail->SMTPAuth = true;
$mail->isHTML(true);
$mail->Port = 587;
$mail->isSMTP();
$success = $mail->send();
return $success;
}
// $options = ['from'=> ['email'=>'', 'name'=>''],
// 'recipients'=> [['email'=>'', 'name'=>'']],
// 'ccrecipients'=> [['email'=>'', 'name'=>'']],
// 'bccrecipients'=>[['email'=>'', 'name'=>'']],
// 'attachments'=> [['path'=>'./attachments/file1.jpg','name'=>'1.jpg'],
// ['path'=>'./attachments/file2.jpg','name'=>'2.jpg'],
// ['path'=>'./attachments/file3.jpg','name'=>'3.jpg']],
// 'credentials'=> ['username'=>'','password'=>''],
// 'subject'=> 'Email Subject Line',
// 'body'=> '<h1>Email Body</h1><p>HTML!!!</p>'];
// $success = SendO365EmailTLS($options);
// echo $success ? 'Email Sent':'Email Not Sent';
// die();
回答by Marco Antonio
To operate the clausla BCC AddCC MUST precede as well nuloy hidden email will arrive to your recipient would otherwise happen nuna Example: ???
要操作 clausla BCC AddCC 必须先于 nuloy 隐藏的电子邮件将到达您的收件人,否则会发生 nuna 示例:???
$ mail-> AddCC ("");
$ mail-> AddBCC ("mail @ domain")

