clearBCCs() public method

Clear all BCC recipients.
public clearBCCs ( ) : void
return void
Example #1
0
 /**
  * Tests CharSet and Unicode -> ASCII conversions for addresses with IDN.
  */
 public function testConvertEncoding()
 {
     if (!$this->Mail->idnSupported()) {
         $this->markTestSkipped('intl and/or mbstring extensions are not available');
     }
     $this->Mail->clearAllRecipients();
     $this->Mail->clearReplyTos();
     // This file is UTF-8 encoded. Create a domain encoded in "iso-8859-1".
     $domain = '@' . mb_convert_encoding('françois.ch', 'ISO-8859-1', 'UTF-8');
     $this->Mail->addAddress('test' . $domain);
     $this->Mail->addCC('test+cc' . $domain);
     $this->Mail->addBCC('test+bcc' . $domain);
     $this->Mail->addReplyTo('test+replyto' . $domain);
     // Queued addresses are not returned by get*Addresses() before send() call.
     $this->assertEmpty($this->Mail->getToAddresses(), 'Bad "to" recipients');
     $this->assertEmpty($this->Mail->getCcAddresses(), 'Bad "cc" recipients');
     $this->assertEmpty($this->Mail->getBccAddresses(), 'Bad "bcc" recipients');
     $this->assertEmpty($this->Mail->getReplyToAddresses(), 'Bad "reply-to" recipients');
     // Clear queued BCC recipient.
     $this->Mail->clearBCCs();
     $this->buildBody();
     $this->assertTrue($this->Mail->send(), $this->Mail->ErrorInfo);
     // Addresses with IDN are returned by get*Addresses() after send() call.
     $domain = $this->Mail->punyencodeAddress($domain);
     $this->assertEquals([['test' . $domain, '']], $this->Mail->getToAddresses(), 'Bad "to" recipients');
     $this->assertEquals([['test+cc' . $domain, '']], $this->Mail->getCcAddresses(), 'Bad "cc" recipients');
     $this->assertEmpty($this->Mail->getBccAddresses(), 'Bad "bcc" recipients');
     $this->assertEquals(['test+replyto' . $domain => ['test+replyto' . $domain, '']], $this->Mail->getReplyToAddresses(), 'Bad "reply-to" addresses');
 }
Example #2
0
 /**
  * Test addressing.
  */
 public function testAddressing()
 {
     $this->assertFalse($this->Mail->addAddress(''), 'Empty address accepted');
     $this->assertFalse($this->Mail->addAddress('', 'Nobody'), 'Empty address with name accepted');
     $this->assertFalse($this->Mail->addAddress('*****@*****.**'), 'Invalid address accepted');
     $this->assertTrue($this->Mail->addAddress('*****@*****.**'), 'Addressing failed');
     $this->assertFalse($this->Mail->addAddress('*****@*****.**'), 'Duplicate addressing failed');
     $this->assertTrue($this->Mail->addCC('*****@*****.**'), 'CC addressing failed');
     $this->assertFalse($this->Mail->addCC('*****@*****.**'), 'CC duplicate addressing failed');
     $this->assertFalse($this->Mail->addCC('*****@*****.**'), 'CC duplicate addressing failed (2)');
     $this->assertTrue($this->Mail->addBCC('*****@*****.**'), 'BCC addressing failed');
     $this->assertFalse($this->Mail->addBCC('*****@*****.**'), 'BCC duplicate addressing failed');
     $this->assertFalse($this->Mail->addBCC('*****@*****.**'), 'BCC duplicate addressing failed (2)');
     $this->assertTrue($this->Mail->addReplyTo('*****@*****.**'), 'Replyto Addressing failed');
     $this->assertFalse($this->Mail->addReplyTo('*****@*****.**'), 'Invalid Replyto address accepted');
     $this->assertTrue($this->Mail->setFrom('*****@*****.**', 'some name'), 'setFrom failed');
     $this->assertFalse($this->Mail->setFrom('a@example.com.', 'some name'), 'setFrom accepted invalid address');
     $this->Mail->Sender = '';
     $this->Mail->setFrom('*****@*****.**', 'some name', true);
     $this->assertEquals($this->Mail->Sender, '*****@*****.**', 'setFrom failed to set sender');
     $this->Mail->Sender = '';
     $this->Mail->setFrom('*****@*****.**', 'some name', false);
     $this->assertEquals($this->Mail->Sender, '', 'setFrom should not have set sender');
     $this->Mail->clearCCs();
     $this->Mail->clearBCCs();
     $this->Mail->clearReplyTos();
 }
Example #3
0
 public static function sendGmail($username, $pass, array $email, $charset = 'UTF-8')
 {
     $mail = new PHPMailer();
     $mail->isSMTP();
     $mail->CharSet = $charset;
     $mail->SMTPDebug = 0;
     $mail->Host = GMAIL_HOST;
     $mail->Port = GMAIL_PORT;
     $mail->SMTPAuth = GMAIL_SMTP_AUTH;
     $mail->SMTPSecure = GMAIL_SMTP_SECURE;
     $mail->Username = $username;
     $mail->Password = $pass;
     foreach ($email as $to => $email_data) {
         $mail->clearAllRecipients();
         $mail->setFrom($username);
         $mail->addAddress($to);
         if (isset($email_data['cc'])) {
             $mail->clearCCs();
             foreach (is_array($email_data['cc']) ? $email_data['cc'] : [$email_data['cc']] as $cc) {
                 $mail->addCC($cc);
             }
         }
         if (isset($email_data['bcc'])) {
             $mail->clearBCCs();
             foreach (is_array($email_data['bcc']) ? $email_data['bcc'] : [$email_data['bcc']] as $bcc) {
                 $mail->addBCC($bcc);
             }
         }
         $mail->Subject = $email_data['subject'];
         $mail->Body = $email_data['body'];
         if (!$mail->send()) {
             throw new Exception(__METHOD__ . $mail->ErrorInfo);
         }
     }
 }
 $result = $mysqli->query($query);
 /*
 $sent_mail = "";
 while (list($user_name, $user_email, $canvas_course_id) = $result->fetch_row()) {
     $sent_mail .= $user_email . "; ";
 }
 */
 $sent_mail = 0;
 $prev_course_id = '';
 $is_new_course = true;
 while (list($user_name, $user_email, $canvas_course_id) = $result->fetch_row()) {
     $is_new_course = $prev_course_id != $canvas_course_id;
     if ($is_new_course && $prev_course_id != '') {
         $mail->send();
         $mail->clearAddresses();
         $mail->clearBCCs();
         $mail->addAddress($canvas_course_id . '@your_server.com', $course_name);
     }
     if ($is_new_course) {
         $body = "<h3>" . $course_name . " Announcement</h3>";
         $body .= "<h4>" . $title . "</h4>";
         $body .= $announcement_txt;
         $body .= '<p><a href="https://your_canvas_url/courses/' . $canvas_course_id . '">' . $course_name . '</a></p>';
         $mail->Body = $body;
         $prev_course_id = $canvas_course_id;
         $mail->addAddress($canvas_course_id . '@your_server.com', $course_name);
     }
     $mail->addBCC($user_email, $user_name);
     $sent_mail = $sent_mail + 1;
 }
 if ($sent_mail > 0) {