Adding CC option to email plugin
This commit is contained in:
parent
d935c94041
commit
948d32110f
|
@ -111,13 +111,18 @@ class Email implements \PHPCI\Plugin
|
||||||
* @param string $body Email body
|
* @param string $body Email body
|
||||||
* @return array Array of failed addresses
|
* @return array Array of failed addresses
|
||||||
*/
|
*/
|
||||||
public function sendEmail($toAddresses, $subject, $body)
|
public function sendEmail($toAddresses, $ccList, $subject, $body)
|
||||||
{
|
{
|
||||||
$message = \Swift_Message::newInstance($subject)
|
$message = \Swift_Message::newInstance($subject)
|
||||||
->setFrom($this->fromAddress)
|
->setFrom($this->fromAddress)
|
||||||
->setTo($toAddresses)
|
->setTo($toAddresses)
|
||||||
->setBody($body)
|
->setBody($body)
|
||||||
->setContentType("text/html");
|
->setContentType("text/html");
|
||||||
|
|
||||||
|
if (is_array($ccList) && count($ccList)) {
|
||||||
|
$message->setCc($ccList);
|
||||||
|
}
|
||||||
|
|
||||||
$failedAddresses = array();
|
$failedAddresses = array();
|
||||||
$this->mailer->send($message, $failedAddresses);
|
$this->mailer->send($message, $failedAddresses);
|
||||||
|
|
||||||
|
@ -127,8 +132,10 @@ class Email implements \PHPCI\Plugin
|
||||||
public function sendSeparateEmails(array $toAddresses, $subject, $body)
|
public function sendSeparateEmails(array $toAddresses, $subject, $body)
|
||||||
{
|
{
|
||||||
$failures = array();
|
$failures = array();
|
||||||
|
$ccList = $this->getCcAddresses();
|
||||||
|
|
||||||
foreach ($toAddresses as $address) {
|
foreach ($toAddresses as $address) {
|
||||||
$newFailures = $this->sendEmail($address, $subject, $body);
|
$newFailures = $this->sendEmail($address, $ccList, $subject, $body);
|
||||||
foreach ($newFailures as $failure) {
|
foreach ($newFailures as $failure) {
|
||||||
$failures[] = $failure;
|
$failures[] = $failure;
|
||||||
}
|
}
|
||||||
|
@ -157,4 +164,17 @@ class Email implements \PHPCI\Plugin
|
||||||
}
|
}
|
||||||
return $addresses;
|
return $addresses;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function getCcAddresses()
|
||||||
|
{
|
||||||
|
$cc = array();
|
||||||
|
|
||||||
|
if (isset($this->options['cc'])) {
|
||||||
|
foreach ($this->options['cc'] as $address) {
|
||||||
|
$cc[] = $address;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $cc;
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue