Skip to content

Commit

Permalink
Send to multiple recipients.
Browse files Browse the repository at this point in the history
  • Loading branch information
JASchilz committed Feb 3, 2017
1 parent ba403f3 commit b1d074a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
20 changes: 17 additions & 3 deletions src/Emailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,26 @@ protected function doSend($body, EmailInterface $email)
/** @var SendGridEmail $sendgridEmail */
$sendgridEmail = new SendGridEmail();

foreach (explode(';', $email->getTo()) as $to) {
$sendgridEmail->addTo(trim($to));
}

foreach (explode(';', $email->getCc()) as $cc) {
$sendgridEmail->addCc(trim($cc));
}

foreach (explode(';', $email->getBcc()) as $bcc) {
$sendgridEmail->addBcc(trim($bcc));
}

if (((string)$email->getReplyTo()) !== "") {
$sendgridEmail->setReplyTo($email->getReplyTo());
}

$sendgridEmail
->addTo($email->getTo())
->setReplyTo($email->getReplyTo())
->setFrom($email->getFrom())
->setSubject($email->getSubject())
->addCc($email->getCc())
->setBcc($email->getBcc())
->setHtml($body);

/** @var Response $res */
Expand Down
9 changes: 5 additions & 4 deletions test/EmailerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
use Athens\Core\Email\EmailBuilder;
use Athens\Core\Email\EmailInterface;

use Athens\Core\Writer\EmailWriter;

use PHPUnit_Framework_TestCase;

/**
Expand Down Expand Up @@ -46,7 +48,7 @@ public function testExceptionRaisedIfAPIKeyNotDefined()

$email = $this->makeEmail();

$emailer = new MockEmailer();
$emailer = new MockEmailer([new EmailWriter()]);

$emailer->send($email);
}
Expand All @@ -67,12 +69,11 @@ public function testReturnTrueIfResponseCode200()

$email = $this->makeEmail();

$emailer = new MockEmailer();
$emailer = new MockEmailer([new EmailWriter()]);

$result = $emailer->send($email);

$this->assertTrue($result);

}

/**
Expand All @@ -91,7 +92,7 @@ public function testReturnFalseIfResponseCodeNot200()

$email = $this->makeEmail();

$emailer = new MockEmailer();
$emailer = new MockEmailer([new EmailWriter()]);

$result = $emailer->send($email);

Expand Down

0 comments on commit b1d074a

Please sign in to comment.