src/EventListener/EmailMessengerListener.php line 23

Open in your IDE?
  1. <?php 
  2. namespace App\EventListener;
  3. use App\Entity\Applicant;
  4. use App\Entity\Participant;
  5. use App\Event\ParticipantRegisteredEvent;
  6. use App\Event\ParticipantSendPinEvent;
  7. use Symfony\Bridge\Twig\Mime\TemplatedEmail;
  8. use Symfony\Component\Mailer\MailerInterface;
  9. use Symfony\Component\Mime\Address;
  10. use Symfony\Component\Mime\Email;
  11. class EmailMessengerListener
  12. {
  13.     private $mailer;
  14.     public function __construct(MailerInterface $mailer, private string $toEmail, private string $fromEmail)
  15.     {
  16.         $this->mailer $mailer;
  17.     }
  18.     public function onParticipantRegistered(Applicant $applicant):void
  19.     {
  20.         dump('EMAIL HIT');
  21.         //$participant = $event->getParticipant();
  22.         $email = (new TemplatedEmail())
  23.             ->from(new Address($this->fromEmail'NEIP Acceleration Programme'))
  24.             ->to($applicant->getEmailAddress())
  25.             ->subject('Thank you for registring')
  26.             ->htmlTemplate('registration/email.html.twig')
  27.             ->context([
  28.                 //'expiration_date' => new \DateTime('+7 days'),
  29.                 'applicant' => $applicant,
  30.             ]);
  31.         
  32.         $this->mailer->send($email); 
  33.     }
  34. }