getToAddresses() public method

Allows for public read access to 'to' property.
public getToAddresses ( ) : array
return array
Example #1
16
 /**
  * Tests removal of duplicate recipients and reply-tos.
  */
 public function testDuplicateIDNRemoved()
 {
     if (!$this->Mail->idnSupported()) {
         $this->markTestSkipped('intl and/or mbstring extensions are not available');
     }
     $this->Mail->clearAllRecipients();
     $this->Mail->clearReplyTos();
     $this->Mail->CharSet = 'utf-8';
     $this->assertTrue($this->Mail->addAddress('test@françois.ch'));
     $this->assertFalse($this->Mail->addAddress('test@françois.ch'));
     $this->assertTrue($this->Mail->addAddress('test@FRANÇOIS.CH'));
     $this->assertFalse($this->Mail->addAddress('test@FRANÇOIS.CH'));
     $this->assertTrue($this->Mail->addAddress('*****@*****.**'));
     $this->assertFalse($this->Mail->addAddress('*****@*****.**'));
     $this->assertFalse($this->Mail->addAddress('*****@*****.**'));
     $this->assertTrue($this->Mail->addReplyTo('test+replyto@françois.ch'));
     $this->assertFalse($this->Mail->addReplyTo('test+replyto@françois.ch'));
     $this->assertTrue($this->Mail->addReplyTo('test+replyto@FRANÇOIS.CH'));
     $this->assertFalse($this->Mail->addReplyTo('test+replyto@FRANÇOIS.CH'));
     $this->assertTrue($this->Mail->addReplyTo('*****@*****.**'));
     $this->assertFalse($this->Mail->addReplyTo('*****@*****.**'));
     $this->assertFalse($this->Mail->addReplyTo('*****@*****.**'));
     $this->buildBody();
     $this->assertTrue($this->Mail->send(), $this->Mail->ErrorInfo);
     // There should be only one "To" address and one "Reply-To" address.
     $this->assertEquals(1, count($this->Mail->getToAddresses()), 'Bad count of "to" recipients');
     $this->assertEquals(1, count($this->Mail->getReplyToAddresses()), 'Bad count of "reply-to" addresses');
 }
 /**
  * Constructor.
  * Note PHPMailer is *NOT* namespaced.
  * @param \PHPMailer $phpmailer A preconfigured PHPMailer instance to use for sending.
  */
 public function __construct($phpmailer)
 {
     if (!$phpmailer instanceof \PHPMailer) {
         throw new InvalidArgumentException('Must be an instance of \\PHPMailer', 1);
     }
     if (count($phpmailer->getToAddresses()) < 1) {
         throw new InvalidArgumentException('No valid email address set in \\PHPMailer');
     }
     $this->phpmailer = $phpmailer;
 }
Example #3
0
 /**
  * Send a custom message created with chainable methods like to(), subject(),
  * etc.
  */
 public function send()
 {
     // Need to create a Message object to use a template
     $this->message = new Message(NULL, FALSE);
     $this->message->resetCustomVariables($this->customVariables);
     // Assuming the to address is the only one
     $to = $this->mailer->getToAddresses();
     $toName = $to[0][1];
     // Set custom variables
     $vars = ['FULL_NAME' => $toName, 'CONTENT_BODY' => $this->mailer->Body, 'SUBJECT' => $this->mailer->Subject];
     $this->message->setDefaultVars($vars);
     // Set subject and message body. They are applied to a template already
     // TODO: If the message chain is called twice (eg, creating the mail, setting the to address,
     // setting the subject, sending, setting another to address, sending again, this could cause
     // the subject and message to nest recursively, or not render correctly the second time around.
     $this->subject($this->message->getSubject());
     $this->message($this->message->getMessage());
     // Actual send
     return $this->sendMessage();
 }