From ac09cab3a0a72e3294a908772ab7226be8ec26c4 Mon Sep 17 00:00:00 2001 From: tykayn Date: Tue, 14 Apr 2020 18:39:29 +0200 Subject: [PATCH] more testing --- src/Service/MailService.php | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/Service/MailService.php b/src/Service/MailService.php index 9e4d238..efe0c20 100644 --- a/src/Service/MailService.php +++ b/src/Service/MailService.php @@ -7,9 +7,12 @@ namespace App\Service; use App\Entity\Owner; use App\Entity\Poll; use Doctrine\ORM\EntityManagerInterface; +use Exception; +use Swift_Mailer; use Swift_Message; use Symfony\Bridge\Twig\Mime\TemplatedEmail; use Symfony\Component\Mime\Address; +use Symfony\Component\Mime\Email; class MailService { @@ -19,16 +22,16 @@ class MailService { */ private $em; /** - * @var \Swift_Mailer + * @var Swift_Mailer */ private $mailer; - public function __construct( EntityManagerInterface $entityManager, \Swift_Mailer $mailer ) { + public function __construct( EntityManagerInterface $entityManager, Swift_Mailer $mailer ) { $this->em = $entityManager; $this->mailer = $mailer; } - public function sendCreationMailAction( Owner $foundOwner, Poll $newpoll, \Swift_Mailer $mailer ) { + public function sendCreationMailAction( Owner $foundOwner, Poll $newpoll, Swift_Mailer $mailer ) { $em = $this->em->getRepository( Owner::class ); $admin_user = $foundOwner; $poll = $newpoll; @@ -43,16 +46,17 @@ class MailService { 'email_template' => 'emails/creation-mail.html.twig', ]; - $message = ( new Swift_Message( 'Framadate - mes sondages' ) ) + $email = ( new Email( ) ) ->setFrom( 'ne-pas-repondre@framadate-api.cipherbliss.com' ) ->setContentType( 'text/html' ) ->setCharset( 'UTF-8' ) + ->subject('Framadate - mes sondages') ->setTo( $admin_user->getEmail() ) ->htmlTemplate( $templateVars[ 'email_template' ] ) ->context( $templateVars ); // send email - return $mailer->send( $message ); + return $mailer->send( $email ); } @@ -62,7 +66,7 @@ class MailService { * @param Owner $foundOwner * * @return int - * @throws \Exception + * @throws Exception */ public function sendOwnerPollsAction( Owner $foundOwner ) { $em = $this->em->getRepository( Owner::class ); @@ -85,7 +89,7 @@ class MailService { $templateVars = [ 'owner' => $admin_user, 'title' => $titleEmail, - 'email_template' => 'emails/owner-polls.html.twig', + 'email_template' => 'emails/owner-list.html.twig', ]; $email = ( new TemplatedEmail() )