Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

59 lines
1.9KB

  1. <?php
  2. namespace App\Controller\Frontend;
  3. use App\Controller\AbstractController;
  4. use App\Form\ContactForm;
  5. use Symfony\Component\HttpFoundation\JsonResponse;
  6. use Symfony\Component\Mailer\MailerInterface;
  7. use Symfony\Component\Mime\Email;
  8. use Symfony\Component\HttpFoundation\Request;
  9. class ContactController extends AbstractController
  10. {
  11. public function contact()
  12. {
  13. $form = $this->createForm(ContactForm::class, null, array(
  14. 'action' => $this->generateUrl('app_contact_form')
  15. ));
  16. return $this->render('frontend/contact.html.twig', [
  17. 'form' => $form->createView()
  18. ]);
  19. }
  20. public function contactForm(Request $request, MailerInterface $mailer)
  21. {
  22. $form = $this->createForm(ContactForm::class);
  23. $form->handleRequest($request);
  24. if ($form->isSubmitted() && $form->isValid() && $form->get('lccap')->getData() == 'blop') {
  25. $message = '<p>De : ' . $form->get('firstname')->getData() . ' ' . $form->get('lastname')->getData() . '<br />Email : ' . $form->get('email')->getData(
  26. ) . '<br />Objet : ' . $form->get(
  27. 'object'
  28. )->getData() . '</p><p>' . $form->get('message')->getData() . '</p>';
  29. $email = (new Email())
  30. ->from('nepasrepondre@laclic.fr')
  31. ->replyTo($form->get('email')->getData())
  32. ->to('agir@lacooperativedescitoyens.fr')
  33. // ->to('charly@laclic.fr')
  34. ->subject('Message de contact sur Aux Actes Citoyens !')
  35. ->text(strip_tags($message))
  36. ->html($message);
  37. $mailer->send($email);
  38. return new JsonResponse(
  39. [
  40. 'status' => 'success'
  41. ]
  42. );
  43. }
  44. return new JsonResponse(
  45. [
  46. 'status' => 'error'
  47. ]
  48. );
  49. }
  50. }