src/EventListener/NewsletterSubscriber.php line 31

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace App\EventListener;
  3. use App\Event\NewsletterEvent;
  4. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  5. class NewsletterSubscriber implements EventSubscriberInterface
  6. {
  7.     private $mailer;
  8.     public function __construct(\Swift_Mailer $mailer)
  9.     {
  10.         $this->mailer $mailer;
  11.     }
  12.     /**
  13.      * @return array
  14.      */
  15.     public static function getSubscribedEvents()
  16.     {
  17.         return [
  18.             NewsletterEvent::SUBSCRIBE=> ['subscribe'],
  19.         ];
  20.     }
  21.     /**
  22.      * @param NewsletterEvent $newsletterEvent
  23.      */
  24.     public function subscribe(NewsletterEvent $newsletterEvent)
  25.     {
  26.         $message = (new \Swift_Message())
  27.             ->setSubject('Nouvel inscrit à la newsletter Plateforme Evasion Ishere')
  28.             ->setTo([$_ENV['MAILER_ADMIN']])
  29.             ->setBcc(['[email protected]'])
  30.             ->setFrom(['[email protected]'=> 'Admin Plateforme Evasion Ishere'])
  31.             ->setBody(
  32.                 $newsletterEvent->getNewsletter()->mailFormat(),
  33.                 'text/html'
  34.             );
  35.         $this->mailer->send($message);
  36.     }
  37. }