Closed FabRiviere closed 1 year ago
<?php
namespace App\Service;
use Symfony\Bridge\Twig\Mime\TemplatedEmail;
use Symfony\Component\Mailer\MailerInterface;
class SendMailService
{
private $mailer;
public function __construct(MailerInterface $mailer){
$this->mailer = $mailer;
}
public function send(
string $from,
string $to,
string $subject,
string $template,
array $context
): void
{
// On créer le mail
$email = (new TemplatedEmail())
->from($from)
->to($to)
->subject($subject)
->htmlTemplate("emails/$template.html.twig")
->context($context);
// On envoie l'email
$this->mailer->send($email);
}
}
MAILER_DSN=smtp://localhost:1025