PHP编译器AddBcc不工作
我正在使用phpmailer发送电子邮件,除了密件抄送和抄送详细信息不显示邮件外,收件人收到邮件也有效。有人可以提出解决办法 . 代码是PHP编译器AddBcc不工作,php,phpmailer,Php,Phpmailer,我正在使用phpmailer发送电子邮件,除了密件抄送和抄送详细信息不显示邮件外,收件人收到邮件也有效。有人可以提出解决办法 . 代码是 require_once("PHPMailer_v5.1/class.phpmailer.php"); require_once("PHPMailer_v5.1/language/phpmailer.lang-en.php"); $mailer = new PHPMailer(); $mailer->IsSMTP();
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("to@gmail.com",$toname);
$mailer->Subject = $subject;
$mailer->Body =$content;
$mailer->AddCC("something@gmail.com", "bla");
$mailer->AddBCC("foo@gmail.com", "test");
if(!$mailer->Send())
{
echo "Message was not sent";
}
else
echo "mail sent";
你永远看不到密件抄送的细节。这就是他们的密件抄送详情。即使是密件抄送的收件人也无法在收件人中看到自己的姓名 PS:您注意到您编写了
addBCC
而不是addBCC
(大写A
)?用作
$mailer->AddBCC("foo@gmail.com", "test");
$mailer->AddCC("something@gmail.com", "bla");
要操作此条款,BCC AddCC必须在之前,并且nuloy隐藏的电子邮件将到达您的收件人,否则将发生nuna 例子:
从phpMailer函数参考: 添加“密件抄送”地址。注意:此函数适用于win32上的SMTP邮件程序,而不是“邮件”邮件程序
这可能会导致您的问题。密件抄送将永远不会显示;仅发送至和抄送 密件抄送=盲复写 老问题,但我最终在这里寻找答案。刚刚在别处了解到,那些函数AddCC和AddBCC仅适用于win32 SMTP 尝试使用: $mail->addCustomHeader(“密件抄送:mybccaddress@mydomain.com"); 看 希望这对某人有帮助,干杯 这是addBCC
$email->addBCC('my@email.com', 'My Name');
请参见第934行()上的PHPMailer.php(当前版本6.0.5):
这是最新版本的一个工作示例,在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();
请检查编辑的问题是否添加BCC?另外-您不清楚:密件抄送收件人是否收到电子邮件?添加密件抄送仍不工作,密件抄送收件人也将收到邮件我认为密件抄送收件人可以查看所有收件人详细信息,但这里密件抄送收件人不能查看密件抄送详细信息,只有“收件人详细信息”可以查看始终如此。密件抄送的详细信息总是隐藏的,当您自己是密件抄送收件人时也是如此。只要从您最喜欢的客户端发送一封邮件,您就会看到。也许它只是猜测,因为您收到了mail.class方法不区分大小写。资本A没什么区别,仍然不起作用。。。邮件已收到,但密件抄送收件人无法查看密件抄送详细信息。此答案需要重新编写,可能还需要格式化。你的意思真的不清楚。“努洛伊”?此外,请使用提供的代码格式工具。这个答案比有用的答案更令人困惑。邮件错误:无效地址:(cc)编写此内容的替代方法是$mail->addCustomHeader('BCC','mybccaddress@mydomain.com');代码>和$emails=array('address1@mydomain.com', 'address2@mydomain.com'); $mail->addCustomHeader('BCC',内爆(',',$emails))代码>。
/**
* 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);
}
<?
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();