<?php
declare(strict_types = 1);
namespace App\Infra\Services;
use Symfony\Bridge\Twig\Mime\TemplatedEmail;
use Symfony\Component\Mailer\MailerInterface;
use Symfony\Component\Mime\Message;
use Twig\Environment;
class MailerService
{
private $twig;
private $mailer;
public function __construct(
Environment $twig,
MailerInterface $mailer
) {
$this->twig = $twig;
$this->mailer = $mailer;
}
public function sendMail(
string $from,
string $to,
string $subject,
string $template,
array $context
) {
$email = (new TemplatedEmail())
->from($from)
->to($to)
->subject($subject)
->htmlTemplate($template)
->context($context);
$this->mailer->send($email);
}
public function newAboNewsletter(string $email)
{
$email = (new TemplatedEmail())
->from($_ENV['ADMIN_MAIL'])
->to('contact@tracol.lu')
->subject('Tracol - Nouvel abonnement Newsletter !')
->html("<h1>Nouvel abonnement Newsletter Tracol</h1><p>Adresse mail du nouvel abonné : <strong>$email</strong></p>");
;
$this->mailer->send($email);
}
}