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, ]; $message = ( new Swift_Message( 'Framadate - mes sondages' ) ) ->setFrom( 'ne-pas-repondre@framadate-api.cipherbliss.com' ) ->setTo( $founduser->getEmail() ) ->setBody( $this->renderView( 'emails/owner-list.html.twig', $templateVars, 'text/html' ) ); // send email $mailer->send( $message ); 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 ); } } }