diff --git a/src/Controller/DefaultController.php b/src/Controller/DefaultController.php index e3959b8..602e6be 100755 --- a/src/Controller/DefaultController.php +++ b/src/Controller/DefaultController.php @@ -20,7 +20,7 @@ class DefaultController extends AbstractController { */ private $mail_service; - public function __construct(MailService $mail_service) { + public function __construct( MailService $mail_service ) { $this->mail_service = $mail_service; } @@ -51,23 +51,21 @@ class DefaultController extends AbstractController { ]; // send email - $this->mail_service->sendOwnerPollsAction(); + if ( $this->mail_service->sendOwnerPollsAction( $founduser ) ) { + return $this->json( [ + 'message' => 'mail succefully sent to user ' . $email, + 'data' => '', + ], + 200 ); + } else { // user not found case + return $this->json( [ + 'message' => 'no user found for email ' . $email, + 'data' => '', + ], + 400 ); + } - - return $this->json( [ - 'message' => 'mail succefully sent to user ' . $email, - 'data' => '', - ], - 200 ); - - - } else { // user not found case - return $this->json( [ - 'message' => 'no user found for email ' . $email, - 'data' => '', - ], - 400 ); } diff --git a/src/Service/MailService.php b/src/Service/MailService.php index 1856633..c6629d7 100644 --- a/src/Service/MailService.php +++ b/src/Service/MailService.php @@ -98,14 +98,14 @@ class MailService { 'email_template' => 'emails/owner-polls.html.twig', ]; - $email = ( new TemplatedEmail( $titleEmail ) ) + $email = ( new TemplatedEmail( ) ) ->from( 'ne-pas-repondre@framadate-api.cipherbliss.com' ) ->to( new Address($admin_user->getEmail() ) ) + ->subject($titleEmail) ->htmlTemplate($templateVars[ 'email_template' ]) ->context( $templateVars); // send email return $this->mailer->send( $email ); - } }