<?php
namespace App\Controller\Front;
use App\Services\EmailManager;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class ContactController extends AbstractController
{
/**
* @Route("/contact", name="page_contact")
* Method ({"GET", "POST"})
*/
public function index(): Response
{
return $this->render('front/pages/contact.html.twig');
}
/**
* @Route("/contact/send-email", name="page_contact_send", options={"expose"=true})
* Method ({"GET", "POST"})
*/
public function sendEmail(EmailManager $emailManager, Request $request): Response
{
$token = $request->request->get('recaptcha_response');
$url = 'https://www.google.com/recaptcha/api/siteverify';
$data = [
'secret' => '6LdfcUQpAAAAAPGoilRZ0bIp392MNyDiiQajcdBc',
'response' => $token,
];
$options = [
'http' => [
'header' => 'Content-type: application/x-www-form-urlencoded',
'method' => 'POST',
'content' => http_build_query($data),
],
];
$context = stream_context_create($options);
$response = file_get_contents($url, false, $context);
$responseData = json_decode($response, true);
if ($responseData['success']) {
// $emailManager->sendEmailContact();
return new Response('DONE');
}
return new Response('NOT_OK');
}
}