From 948d32110f3f06cc1e24760679697d61b91d23da Mon Sep 17 00:00:00 2001 From: Dan Cryer Date: Tue, 25 Feb 2014 16:03:00 +0000 Subject: [PATCH] Adding CC option to email plugin --- PHPCI/Plugin/Email.php | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/PHPCI/Plugin/Email.php b/PHPCI/Plugin/Email.php index 77f884e3..05dbe4c0 100644 --- a/PHPCI/Plugin/Email.php +++ b/PHPCI/Plugin/Email.php @@ -111,13 +111,18 @@ class Email implements \PHPCI\Plugin * @param string $body Email body * @return array Array of failed addresses */ - public function sendEmail($toAddresses, $subject, $body) + public function sendEmail($toAddresses, $ccList, $subject, $body) { $message = \Swift_Message::newInstance($subject) ->setFrom($this->fromAddress) ->setTo($toAddresses) ->setBody($body) ->setContentType("text/html"); + + if (is_array($ccList) && count($ccList)) { + $message->setCc($ccList); + } + $failedAddresses = array(); $this->mailer->send($message, $failedAddresses); @@ -127,8 +132,10 @@ class Email implements \PHPCI\Plugin public function sendSeparateEmails(array $toAddresses, $subject, $body) { $failures = array(); + $ccList = $this->getCcAddresses(); + foreach ($toAddresses as $address) { - $newFailures = $this->sendEmail($address, $subject, $body); + $newFailures = $this->sendEmail($address, $ccList, $subject, $body); foreach ($newFailures as $failure) { $failures[] = $failure; } @@ -157,4 +164,17 @@ class Email implements \PHPCI\Plugin } return $addresses; } + + protected function getCcAddresses() + { + $cc = array(); + + if (isset($this->options['cc'])) { + foreach ($this->options['cc'] as $address) { + $cc[] = $address; + } + } + + return $cc; + } } \ No newline at end of file