getDoctrine()->getRepository( Owner::class ); $founduser = $repository->findOneBy( [ 'email' => $email ] ); if ( $founduser ) { $polls = $founduser->getPolls(); $templateVars = [ 'owner' => $founduser, 'polls' => $polls, ]; $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 ) ); $mailer->send( $message ); return $this->render( 'emails/owner-list.html.twig', $templateVars ); } else { return $this->json( [ 'message' => 'no user found for email ' . $email, 'data' => '', ], 400 ); } // find user by email // send email // user not found case } }