diff --git a/module/VuFind/src/VuFind/Controller/AbstractRecord.php b/module/VuFind/src/VuFind/Controller/AbstractRecord.php index 8d5b5b5bf22bb46f3e9937febd2b6ac25bd84334..a8a14d301acdadf0798622a3525bd492e69b2868 100644 --- a/module/VuFind/src/VuFind/Controller/AbstractRecord.php +++ b/module/VuFind/src/VuFind/Controller/AbstractRecord.php @@ -370,18 +370,12 @@ class AbstractRecord extends AbstractBase if ($this->formWasSubmitted('submit', $view->useRecaptcha)) { // Attempt to send the email and show an appropriate flash message: try { + $cc = $this->params()->fromPost('ccself') && $view->from != $view->to + ? $view->from : null; $mailer->sendRecord( $view->to, $view->from, $view->message, $driver, - $this->getViewRenderer(), $view->subject + $this->getViewRenderer(), $view->subject, $cc ); - if ($this->params()->fromPost('ccself') - && $view->from != $view->to - ) { - $mailer->sendRecord( - $view->from, $view->from, $view->message, $driver, - $this->getViewRenderer(), $view->subject - ); - } $this->flashMessenger()->setNamespace('info') ->addMessage('email_success'); return $this->redirectToRecord(); diff --git a/module/VuFind/src/VuFind/Controller/AjaxController.php b/module/VuFind/src/VuFind/Controller/AjaxController.php index 78c6925de49ac2e1532142ec7c2013e144d838e1..2da971d4b5a0ebdb36ecb16f926cbebeced0ee45 100644 --- a/module/VuFind/src/VuFind/Controller/AjaxController.php +++ b/module/VuFind/src/VuFind/Controller/AjaxController.php @@ -1036,18 +1036,12 @@ class AjaxController extends AbstractBase null, $mailer->getDefaultRecordSubject($record) ); $mailer->setMaxRecipients($view->maxRecipients); + $cc = $this->params()->fromPost('ccself') && $view->from != $view->to + ? $view->from : null; $mailer->sendRecord( $view->to, $view->from, $view->message, $record, - $this->getViewRenderer(), $view->subject + $this->getViewRenderer(), $view->subject, $cc ); - if ($this->params()->fromPost('ccself') - && $view->from != $view->to - ) { - $mailer->sendRecord( - $view->from, $view->from, $view->message, $record, - $this->getViewRenderer(), $view->subject - ); - } return $this->output( $this->translate('email_success'), self::STATUS_OK ); @@ -1102,18 +1096,12 @@ class AjaxController extends AbstractBase : $mailer->getDefaultLinkSubject(); $view = $this->createEmailViewModel(null, $defaultSubject); $mailer->setMaxRecipients($view->maxRecipients); + $cc = $this->params()->fromPost('ccself') && $view->from != $view->to + ? $view->from : null; $mailer->sendLink( $view->to, $view->from, $view->message, $url, - $this->getViewRenderer(), $view->subject + $this->getViewRenderer(), $view->subject, $cc ); - if ($this->params()->fromPost('ccself') - && $view->from != $view->to - ) { - $mailer->sendLink( - $view->from, $view->from, $view->message, $url, - $this->getViewRenderer(), $view->subject - ); - } return $this->output( $this->translate('email_success'), self::STATUS_OK ); diff --git a/module/VuFind/src/VuFind/Controller/CartController.php b/module/VuFind/src/VuFind/Controller/CartController.php index f5193f9c9a61d21e9329f2389d7c9f28a3b524a6..1194d8e2909f95710ea81aa17db943ff98bf485e 100644 --- a/module/VuFind/src/VuFind/Controller/CartController.php +++ b/module/VuFind/src/VuFind/Controller/CartController.php @@ -221,18 +221,12 @@ class CartController extends AbstractBase // If we got this far, we're ready to send the email: $mailer = $this->getServiceLocator()->get('VuFind\Mailer'); $mailer->setMaxRecipients($view->maxRecipients); + $cc = $this->params()->fromPost('ccself') && $view->from != $view->to + ? $view->from : null; $mailer->sendLink( $view->to, $view->from, $view->message, - $url, $this->getViewRenderer(), $view->subject + $url, $this->getViewRenderer(), $view->subject, $cc ); - if ($this->params()->fromPost('ccself') - && $view->from != $view->to - ) { - $mailer->sendLink( - $view->from, $view->from, $view->message, - $url, $this->getViewRenderer(), $view->subject - ); - } return $this->redirectToSource('info', 'email_success'); } catch (MailException $e) { $this->flashMessenger()->setNamespace('error') diff --git a/module/VuFind/src/VuFind/Controller/SearchController.php b/module/VuFind/src/VuFind/Controller/SearchController.php index 2ff0c060f8b4cc885785e026162bf3f2de02df0b..75ce048e748102822fe915077f2691702e22a08d 100644 --- a/module/VuFind/src/VuFind/Controller/SearchController.php +++ b/module/VuFind/src/VuFind/Controller/SearchController.php @@ -117,18 +117,12 @@ class SearchController extends AbstractSearch // Attempt to send the email and show an appropriate flash message: try { // If we got this far, we're ready to send the email: + $cc = $this->params()->fromPost('ccself') && $view->from != $view->to + ? $view->from : null; $mailer->sendLink( $view->to, $view->from, $view->message, - $view->url, $this->getViewRenderer(), $view->subject + $view->url, $this->getViewRenderer(), $view->subject, $cc ); - if ($this->params()->fromPost('ccself') - && $view->from != $view->to - ) { - $mailer->sendLink( - $view->from, $view->from, $view->message, - $view->url, $this->getViewRenderer(), $view->subject - ); - } $this->flashMessenger()->setNamespace('info') ->addMessage('email_success'); return $this->redirect()->toUrl($view->url); diff --git a/module/VuFind/src/VuFind/Mailer/Mailer.php b/module/VuFind/src/VuFind/Mailer/Mailer.php index 827e02e24eaf51c2e392080ea7d57e7ac9c39fa3..f9e1719575742f0404d7ff901e214ed32afbaec5 100644 --- a/module/VuFind/src/VuFind/Mailer/Mailer.php +++ b/module/VuFind/src/VuFind/Mailer/Mailer.php @@ -135,11 +135,12 @@ class Mailer implements \VuFind\I18n\Translator\TranslatorAwareInterface * @param string $from Sender email address * @param string $subject Subject line for message * @param string $body Message body + * @param string $cc CC recipient (null for none) * * @throws MailException * @return void */ - public function send($to, $from, $subject, $body) + public function send($to, $from, $subject, $body, $cc = null) { $recipients = $this->stringToAddressList($to); @@ -170,6 +171,9 @@ class Mailer implements \VuFind\I18n\Translator\TranslatorAwareInterface ->addTo($recipients) ->setBody($body) ->setSubject($subject); + if ($cc !== null) { + $message->addCc($cc); + } $this->getTransport()->send($message); } catch (\Exception $e) { throw new MailException($e->getMessage()); @@ -187,12 +191,14 @@ class Mailer implements \VuFind\I18n\Translator\TranslatorAwareInterface * @param \Zend\View\Renderer\PhpRenderer $view View object (used to render * email templates) * @param string $subject Subject for email (optional) + * @param string $cc CC recipient (null for none) * * @throws MailException * @return void */ - public function sendLink($to, $from, $msg, $url, $view, $subject = null) - { + public function sendLink($to, $from, $msg, $url, $view, $subject = null, + $cc = null + ) { if (null === $subject) { $subject = $this->getDefaultLinkSubject(); } @@ -202,7 +208,7 @@ class Mailer implements \VuFind\I18n\Translator\TranslatorAwareInterface 'msgUrl' => $url, 'to' => $to, 'from' => $from, 'message' => $msg ) ); - return $this->send($to, $from, $subject, $body); + return $this->send($to, $from, $subject, $body, $cc); } /** @@ -226,12 +232,14 @@ class Mailer implements \VuFind\I18n\Translator\TranslatorAwareInterface * @param \Zend\View\Renderer\PhpRenderer $view View object (used to render * email templates) * @param string $subject Subject for email (optional) + * @param string $cc CC recipient (null for none) * * @throws MailException * @return void */ - public function sendRecord($to, $from, $msg, $record, $view, $subject = null) - { + public function sendRecord($to, $from, $msg, $record, $view, $subject = null, + $cc = null + ) { if (null === $subject) { $subject = $this->getDefaultRecordSubject($record); } @@ -241,7 +249,7 @@ class Mailer implements \VuFind\I18n\Translator\TranslatorAwareInterface 'driver' => $record, 'to' => $to, 'from' => $from, 'message' => $msg ) ); - return $this->send($to, $from, $subject, $body); + return $this->send($to, $from, $subject, $body, $cc); } /**