mail_service = $mail_service; } /** * Send a mail with all the data to one user * @Get( * path = "/send-polls-to-user/{email}", * name = "send_user_polls" * ) * * @param $email * @param \Swift_Mailer $mailer * * @return JsonResponse */ public function sendPollsToUser( $email, \Swift_Mailer $mailer ) { $repository = $this->getDoctrine()->getRepository( Owner::class ); // find user by email $founduser = $repository->findOneBy( [ 'email' => $email ] ); if ( $founduser ) { $polls = $founduser->getPolls(); $templateVars = [ 'owner' => $founduser, 'polls' => $polls, 'title' => 'Mes sondages - ' . $email, ]; // send email 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 ); } } } }