Phpmailer的AddBcc无法正常工作

23

我正在使用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("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";

AddBCC不是吗?而且 - 你的表述不清楚:BCC收件人是否会收到电子邮件? - HorusKol
AddBCC仍然无法正常工作,密送收件人也将会收到该邮件。 - Vidya L
9个回答

40

用作

$mailer->AddBCC("foo@gmail.com", "test");
$mailer->AddCC("something@gmail.com", "bla");

仍然没有生效...邮件已经被接收,但是暗送收件人无法查看暗送详情。 - Vidya L

18

您永远不会看到“BCC”(暗送)的细节。这就是“BCC”细节存在的原因。即使被“BCC”的收件人也不会看到自己的姓名与其他收件人。

附注:您注意到自己写成了addBCC而不是AddBCC(大写的A)吗?


我认为密送收件人可以查看所有收件人的详细信息,但是在这里,密送收件人只能查看“收件人详细信息”,而无法查看密送详细信息。 - Vidya L
这总是如此。BCC细节始终是隐藏的,即使您自己是BCC收件人。只需从您喜欢的客户端发送电子邮件,您就会看到。 - GolezTrol
5
类方法对大小写不敏感,大写字母 A 没有任何区别。 - But those new buttons though..

13

从phpMailer函数的参考资料中:

添加“Bcc”地址。注意:此功能仅适用于win32上的SMTP邮件程序,而不适用于“mail”邮件程序。

这可能导致您的问题。


9

PHPMailer未发送CC或BCC

虽然这是一个旧问题,但我也是为了寻找答案而来到这里的。我在其他地方学到,AddCC和AddBCC这些函数只适用于win32 SMTP。

尝试使用:

$mail->addCustomHeader("BCC: mybccaddress@mydomain.com"); 请参考http://phpmailer.worxware.com/?pg=methods

希望这能帮助到某人,祝好!


另一种编写方式是 $mail->addCustomHeader('BCC', 'mybccaddress@mydomain.com');$emails = array('address1@mydomain.com', 'address2@mydomain.com'); $mail->addCustomHeader('BCC', implode(',', $emails));. - WoodrowShigeru

6

It´s addBCC

$email->addBCC('my@email.com', 'My Name');

请参见PHPMailer.php(当前版本6.0.5),第934行(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);
}

4

密送不会显示;只有收件人和抄送

BCC=密送


1

这是最新版本的一个可用示例,在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();

0

-15

在操作BCC AddCC时,必须先于nuloy隐藏电子邮件,否则您的收件人将会收到该邮件。

例如:

$ mail-> AddCC ("");
$ mail-> AddBCC ("mail @ domain")

5
这个回答需要进行重述,可能需要进行格式调整。不太清楚你的意思,“nuloy”是什么?请使用提供的代码格式化工具。 - Nathaniel Ford
5
这个答案比有帮助的还要更令人困惑。 - Chris J Allen
邮件发送错误:无效地址:(抄送) - Ryuuzaki Julio

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接