getDoctrine()->getRepository( Owner::class ); // find user by email $owner = $repository->findOneByEmail($email); if ( $owner ) { $templateVars = [ 'owner' => $owner, 'polls' => $owner->getPolls(), 'title' => 'Mes sondages - ' . $owner->getEmail(), ]; // send email $mailSent = 0; try { $mailSent = $this->sendOwnerPollsAction( $owner ); } catch ( Exception $e ) { } catch ( TransportExceptionInterface $e ) { } if ( $mailSent ) { return $this->json( [ 'message' => 'mail succefully sent to user ' . $owner->getEmail(), 'data' => '', ], 200 ); } return $this->json( [ 'message' => 'no sucess sending email ' . $owner->getEmail(), 'data' => '', ], 400 ); } return $this->json( [ 'message' => 'no user found for email ' . $email, 'data' => '', ], 400 ); } }