src/Controller/Front/ContactController.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Front;
  3. use App\Services\EmailManager;
  4. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  5. use Symfony\Component\HttpFoundation\Request;
  6. use Symfony\Component\HttpFoundation\Response;
  7. use Symfony\Component\Routing\Annotation\Route;
  8. class ContactController extends AbstractController
  9. {
  10.     /**
  11.      * @Route("/contact", name="page_contact")
  12.      * Method ({"GET", "POST"})
  13.      */
  14.     public function index(): Response
  15.     {
  16.         return $this->render('front/pages/contact.html.twig');
  17.     }
  18.     /**
  19.      * @Route("/contact/send-email", name="page_contact_send", options={"expose"=true})
  20.      * Method ({"GET", "POST"})
  21.      */
  22.     public function sendEmail(EmailManager $emailManagerRequest $request): Response
  23.     {
  24.         $token $request->request->get('recaptcha_response');
  25.         $url 'https://www.google.com/recaptcha/api/siteverify';
  26.         $data = [
  27.         'secret' => '6LdfcUQpAAAAAPGoilRZ0bIp392MNyDiiQajcdBc',
  28.         'response' => $token,
  29.         ];
  30.         $options = [
  31.         'http' => [
  32.             'header' => 'Content-type: application/x-www-form-urlencoded',
  33.             'method' => 'POST',
  34.             'content' => http_build_query($data),
  35.         ],
  36.         ];
  37.         $context stream_context_create($options);
  38.         $response file_get_contents($urlfalse$context);
  39.         $responseData json_decode($responsetrue);
  40.         if ($responseData['success']) {
  41.             // $emailManager->sendEmailContact();
  42.             return new Response('DONE');
  43.         }
  44.         return new Response('NOT_OK');
  45.     }
  46. }