src/Frontend/Modules/Mailmotor/EventListener/NewNotImplementedMailingListSubscription.php line 36

Open in your IDE?
  1. <?php
  2. namespace Frontend\Modules\Mailmotor\EventListener;
  3. use Common\Language;
  4. use Common\Mailer\Message;
  5. use Frontend\Modules\Mailmotor\Domain\Subscription\Event\NotImplementedSubscribedEvent;
  6. use Swift_Mailer;
  7. use Common\ModulesSettings;
  8. /**
  9.  * New mailing list subscription
  10.  *
  11.  * This will send a mail to the administrator
  12.  * to let them know that they have to manually subscribe a person.
  13.  * Because the mail engine is "not_implemented".
  14.  */
  15. final class NewNotImplementedMailingListSubscription
  16. {
  17.     /**
  18.      * @var ModulesSettings
  19.      */
  20.     private $modulesSettings;
  21.     /**
  22.      * @var Swift_Mailer
  23.      */
  24.     private $mailer;
  25.     public function __construct(Swift_Mailer $mailerModulesSettings $modulesSettings)
  26.     {
  27.         $this->mailer $mailer;
  28.         $this->modulesSettings $modulesSettings;
  29.     }
  30.     public function onNotImplementedSubscribedEvent(NotImplementedSubscribedEvent $event): void
  31.     {
  32.         $title sprintf(
  33.             Language::lbl('MailTitleSubscribeSubscriber'),
  34.             $event->getSubscription()->email,
  35.             strtoupper((string) $event->getSubscription()->locale)
  36.         );
  37.         $to $this->modulesSettings->get('Core''mailer_to');
  38.         $from $this->modulesSettings->get('Core''mailer_from');
  39.         $replyTo $this->modulesSettings->get('Core''mailer_reply_to');
  40.         $message Message::newInstance($title)
  41.             ->setFrom([$from['email'] => $from['name']])
  42.             ->setTo([$to['email'] => $to['name']])
  43.             ->setReplyTo([$replyTo['email'] => $replyTo['name']])
  44.             ->parseHtml(
  45.                 FRONTEND_CORE_PATH '/Layout/Templates/Mails/Notification.html.twig',
  46.                 [
  47.                     'message' => $title,
  48.                 ],
  49.                 true
  50.             )
  51.         ;
  52.         $this->mailer->send($message);
  53.     }
  54. }