src/Controller/ContactController.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  4. use Symfony\Component\HttpFoundation\Response;
  5. use Symfony\Component\Routing\Annotation\Route;
  6. class ContactController extends AbstractController
  7. {
  8.     /**
  9.      * @Route("/contact", name="app_contact")
  10.      */
  11.     public function index(): Response
  12.     {
  13.         return $this->render('contact/index.html.twig', [
  14.             'controller_name' => 'ContactController',
  15.         ]);
  16.     }
  17.     /**
  18.      * @Route("/contact/send", name="app_contact_send")
  19.      */
  20.     public function sendContact(): Response
  21.     {
  22.         if ($_POST['g-recaptcha-response'] == "" or !isset($_POST['g-recaptcha-response']))
  23.             return $this->redirect("/contact?error=recaptcha");
  24.         $message $_POST['message'];
  25.         $sujet $_POST['Subject'];
  26.         $nom $_POST['name'];
  27.         $email $_POST['email'];
  28.         $phone $_POST['phone'];
  29.         // Create the Transport
  30.         $transport = (new \Swift_SmtpTransport($_ENV['main_host'], 25))
  31.             ->setUsername($_ENV['SWIFTMAIL_USERNAME'])
  32.             ->setPassword($_ENV['SWIFTMAIL_PASSWORD']);
  33.         // Create the Mailer using your created Transport
  34.         $mailer = new \Swift_Mailer($transport);
  35.         // Create a message
  36.         $messageMail = (new \Swift_Message("Message du site TEVA: " $sujet))
  37.             ->setFrom([$email => $nom])
  38.             ->setTo([$_ENV['main_mail'], 'thierrydavynjifon01@gmail.com'])
  39.             ->setBody(
  40.                 "<b>Téléphone :</b>" $phone "\nMessage :\n" $message,
  41.                 'text/html');
  42.         // Send the message
  43.         $result $mailer->send($messageMail);
  44.         return $this->redirect('/?sent=ok');
  45.     }
  46. }