123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- <?php
- namespace App\Service;
- use Symfony\Component\Mailer\MailerInterface;
- use Symfony\Component\Mime\Address;
- use Symfony\Component\Mime\Email;
- use Twig\Environment;
- /**
- * Envoi de mails
- */
- class Mail
- {
- protected $mailer;
- protected $templating;
- protected $from;
- protected $reply;
- protected $name;
- /**
- * Mail Manager
- * @param $mailer
- * @param $templating
- * @param $from
- * @param $reply
- * @param $name
- */
- public function __construct(MailerInterface $mailer, Environment $templating, $from, $reply, $name)
- {
- $this->mailer = $mailer;
- $this->templating = $templating;
- $this->from = $from;
- $this->reply = $reply;
- $this->name = $name;
- }
- protected function sendMessage($subject, $to, $body)
- {
- $mail = (new Email())
- ->from(new Address($this->from, $this->name))
- ->to($to)
- ->subject($subject)
- ->text($body)
- ->replyTo(new Address($this->reply, $this->name));
- return $this->mailer->send($mail);
- }
- public function sendMailActivation(\App\Entity\User $user, $lien)
- {
- $subject = "Activation de votre compte";
- $template = 'security/mail_activate.html.twig';
- $to = $user->getMail();
- $body = $this->templating->render($template, array('user' => $user, 'lien' => $lien));
- $this->sendMessage($subject, $to, $body);
- }
- public function sendMailTokenMp(\App\Entity\User $user, $lien)
- {
- $subject = "Mot de passe perdu";
- $template = 'security/mail_tokenmdp.html.twig';
- $to = $user->getMail();
- $body = $this->templating->render($template, array('user' => $user, 'lien' => $lien));
- $this->sendMessage($subject, $to, $body);
- }
- }
|