src/Infra/Services/MailerService.php line 42

Open in your IDE?
  1. <?php
  2. declare(strict_types 1);
  3. namespace App\Infra\Services;
  4. use Symfony\Bridge\Twig\Mime\TemplatedEmail;
  5. use Symfony\Component\Mailer\MailerInterface;
  6. use Symfony\Component\Mime\Message;
  7. use Twig\Environment;
  8. class MailerService
  9. {
  10.     private $twig;
  11.     private $mailer;
  12.   public function __construct(
  13.      Environment $twig,
  14.      MailerInterface $mailer
  15.   ) {
  16.        $this->twig $twig;
  17.        $this->mailer $mailer;
  18.   }
  19.     public function sendMail(
  20.         string $from,
  21.         string $to,
  22.         string $subject,
  23.         string $template,
  24.         array $context
  25.     ) {
  26.         $email = (new TemplatedEmail())
  27.             ->from($from)
  28.             ->to($to)
  29.             ->subject($subject)
  30.             ->htmlTemplate($template)
  31.             ->context($context);
  32.         $this->mailer->send($email);
  33.     }
  34.     public function newAboNewsletter(string $email)
  35.     {
  36.         $email = (new TemplatedEmail())
  37.             ->from($_ENV['ADMIN_MAIL'])
  38.             ->to('contact@tracol.lu')
  39.             ->subject('Tracol - Nouvel abonnement Newsletter !')
  40.             ->html("<h1>Nouvel abonnement Newsletter Tracol</h1><p>Adresse mail du nouvel abonnĂ© : <strong>$email</strong></p>");
  41.         ;
  42.         $this->mailer->send($email);
  43.     }
  44. }