<?php declare(strict_types=1);
namespace App\EventListener;
use App\Event\NewsletterEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class NewsletterSubscriber implements EventSubscriberInterface
{
private $mailer;
public function __construct(\Swift_Mailer $mailer)
{
$this->mailer = $mailer;
}
/**
* @return array
*/
public static function getSubscribedEvents()
{
return [
NewsletterEvent::SUBSCRIBE=> ['subscribe'],
];
}
/**
* @param NewsletterEvent $newsletterEvent
*/
public function subscribe(NewsletterEvent $newsletterEvent)
{
$message = (new \Swift_Message())
->setSubject('Nouvel inscrit à la newsletter Plateforme Evasion Ishere')
->setTo([$_ENV['MAILER_ADMIN']])
->setBcc(['[email protected]'])
->setFrom(['[email protected]'=> 'Admin Plateforme Evasion Ishere'])
->setBody(
$newsletterEvent->getNewsletter()->mailFormat(),
'text/html'
);
$this->mailer->send($message);
}
}