<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class ContactController extends AbstractController
{
/**
* @Route("/contact", name="app_contact")
*/
public function index(): Response
{
return $this->render('contact/index.html.twig', [
'controller_name' => 'ContactController',
]);
}
/**
* @Route("/contact/send", name="app_contact_send")
*/
public function sendContact(): Response
{
if ($_POST['g-recaptcha-response'] == "" or !isset($_POST['g-recaptcha-response']))
return $this->redirect("/contact?error=recaptcha");
$message = $_POST['message'];
$sujet = $_POST['Subject'];
$nom = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
// Create the Transport
$transport = (new \Swift_SmtpTransport($_ENV['main_host'], 25))
->setUsername($_ENV['SWIFTMAIL_USERNAME'])
->setPassword($_ENV['SWIFTMAIL_PASSWORD']);
// Create the Mailer using your created Transport
$mailer = new \Swift_Mailer($transport);
// Create a message
$messageMail = (new \Swift_Message("Message du site TEVA: " . $sujet))
->setFrom([$email => $nom])
->setTo([$_ENV['main_mail'], 'thierrydavynjifon01@gmail.com'])
->setBody(
"<b>Téléphone :</b>" . $phone . "\nMessage :\n" . $message,
'text/html');
// Send the message
$result = $mailer->send($messageMail);
return $this->redirect('/?sent=ok');
}
}