Phpmailer AddBcc not working
Asked Answered
N

9

23

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

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";
Nils answered 8/10, 2012 at 8:25 Comment(2)
isn't AddBCC? also - you're not clear: do the BCC recipients receive the email?Scriptural
AddBCC still not working, bcc recipients will also receive the mailNils
B
40

Use as

$mailer->AddBCC("[email protected]", "test");
$mailer->AddCC("[email protected]", "bla");
Brumby answered 8/10, 2012 at 8:55 Comment(1)
still not working... the mail recieves, but the bcc recipient cant view the bcc detailsNils
M
18

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.

PS: You noticed you wrote addBCC instead of AddBCC (capital A)?

Mciver answered 8/10, 2012 at 8:49 Comment(3)
I think the bcc recipient can view all the recipient details, but here the bcc recipient can't view the bcc details only 'to details' can viewNils
That is always so. BCC details are always hidden, also when you are yourself the BCC recipient. Just send a mail from your favorite client and you'll see.Mciver
class methods are case insensitive. Capital A makes no difference.Varicotomy
T
13

From the phpMailer function reference:

Adds a "Bcc" address. Note: this function works with the SMTP mailer on win32, not with the "mail" mailer.

This might be causing your issue.

Thwack answered 27/6, 2014 at 16:7 Comment(0)
P
9

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

Try using:

$mail->addCustomHeader("BCC: [email protected]"); See http://phpmailer.worxware.com/?pg=methods

Hope this helps someone, cheers!

Palaearctic answered 13/7, 2017 at 3:20 Comment(1)
Alternative ways to write this are $mail->addCustomHeader('BCC', '[email protected]'); and $emails = array('[email protected]', '[email protected]'); $mail->addCustomHeader('BCC', implode(',', $emails));.Mcclanahan
B
7

It´s 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):

/**
 * 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);
}
Ball answered 17/5, 2018 at 13:57 Comment(0)
S
4

the bcc will never show; only TO and CC

BCC=Blind Carbon Copy

Saipan answered 11/6, 2015 at 7:57 Comment(0)
A
1

Here is a working example from the newest release, and on Office 365, I use it to send email from shared folders...

<?
    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();
Aarhus answered 22/9, 2019 at 1:4 Comment(0)
C
0

$mail->addCC('[email protected]');//Carbon copy $mail->addBCC('[email protected]');//Blind Carbon copy

Please Read This https://github.com/PHPMailer/PHPMailer

Chrissychrist answered 26/7, 2021 at 12:55 Comment(0)
P
-15

To operate the clausla BCC AddCC MUST precede as well nuloy hidden email will arrive to your recipient would otherwise happen nuna Example:    

$ mail-> AddCC ("");
$ mail-> AddBCC ("mail @ domain")
Pacorro answered 16/9, 2013 at 20:40 Comment(3)
This answer needs major rewording, and possibly formatting. It's really unclear what you mean. "nuloy"? Also, please use the code formatting tools provided.Baltimore
this answer is more confusing than it is helpful.Reunionist
Mailer Error: Invalid address: (cc)Pleuropneumonia

© 2022 - 2024 — McMap. All rights reserved.