<?php
namespace App\Controller;
use App\Form\ContactType;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Mailer\Exception\TransportExceptionInterface;
use Symfony\Component\Mailer\MailerInterface;
use Symfony\Component\Mime\Email;
use Symfony\Component\Routing\Annotation\Route;
class QuoteController extends AbstractController
{
/**
* @Route("/demander-un-devis", name="quote")
*/
public function index(Request $request, MailerInterface $mailer): Response
{
$form = $this->createForm(ContactType::class);
$form->handleRequest($request);
if($form->isSubmitted() && $form->isValid()) {
//Construction du mail
try {
// dd($form->getData() );
$data = $form->getData();
$text = "Nom et prénom : " .$data['name'] ."<br>";
$text .= "Code postal : " .$data['postalcode'] ."<br>";
$text .= "Email : " .$data['email'] ."<br>";
$text .= "Téléphone : " .$data['phone'] ."<br>";
$text .= "Préstation désirée : " .$data["choice"] ."<br>";
$text .= "Message : " .$data['message'] ."<br>";
//Construction du mail de contact
$email = (new Email())
->from('noreply@renovathome.fr')
->to("contact@djabdigital.com")
//->cc('cc@example.com')
//->bcc('bcc@example.com')
//->replyTo('fabien@example.com')
//->priority(Email::PRIORITY_HIGH)
->subject('Formulaire Contact RenovAtHome')
// path of the Twig template to render
->html(
$text,
'UTF-8'
);
//Envoi du mail de contact
$mailer->send($email);
$this->addFlash('success', 'Votre demande a été transmise à l\'équipe Renov\'at Home');
unset($form);
$form = $this->createForm(ContactType::class);
} catch (TransportExceptionInterface $e) {
$this->addFlash('warning', 'Une erreur est survenue lors de l\'envoi de votre mail contacter nous directement à l\'adresse mail contact@renovathome.fr'.$e->getMessage());
}
}
return $this->render('quote/index.html.twig', [
'banner' => 'banniere.webp',
'form' => $form->createView(),
'titre' => 'Discutons de votre projet',
'sousTitre' => 'devis gratuit et sans engagement',
]);
}
}