<?php
namespace App\EventSubscriber;
use App\Event\AppointmentEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Mailer\MailerInterface;
use Symfony\Component\Mime\Email;
use Twig\Environment;
class EmailNotificationSubscriber implements EventSubscriberInterface
{
public function __construct(private MailerInterface $mailer, private Environment $twig)
{
}
public function onBookAppointment(AppointmentEvent $event)
{
$appointment = $event->getAppointment();
$htmlContent = $this->twig->render('emails/appointment.html.twig',[
'appointment'=>$appointment
]);
$email = (new Email())
->from('mailer@immihive.com')
->to('boabramah@gmail.com')
->subject('New Appointment Booking')
->html($htmlContent);
$this->mailer->send($email);
}
public static function getSubscribedEvents()
{
return [
AppointmentEvent::SUMMITED => 'onBookAppointment',
];
}
}