src/Controller/ContactController.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Form\ContactType;
  4. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  5. use Symfony\Component\HttpFoundation\Request;
  6. use Symfony\Component\Routing\Annotation\Route;
  7. use Symfony\Component\Mailer\MailerInterface;
  8. use Symfony\Component\Mime\Email;
  9. class ContactController extends AbstractController
  10. {
  11.     /**
  12.      * @Route("/contact", name="contact")
  13.      */
  14.     public function index(Request $request,MailerInterface $mailer)
  15.     {
  16.         $form $this->createForm(ContactType::class);
  17.         $form->handleRequest($request);
  18.         
  19.         if ($form->isSubmitted() && $form->isValid()) {
  20.             $contactFormData $form->getData();
  21.             $email = (new Email())
  22.             ->from($contactFormData['email'])
  23.             ->to('info@timechip.cz')
  24.             //->cc('cc@example.com')
  25.             //->bcc('bcc@example.com')
  26.             //->replyTo('fabien@example.com')
  27.             //->priority(Email::PRIORITY_HIGH)
  28.             ->subject('Zpráva z webového formuláře')
  29.             ->text($contactFormData['zprava']);
  30.             $mailer->send($email);
  31.             $this->addFlash('success''Váš email byl odeslán');
  32.             return $this->redirectToRoute('contact');
  33.         }
  34.         
  35.         
  36.         
  37.         
  38.         
  39.         return $this->render('contact/index.html.twig', [
  40.             'email_form' => $form->createView(),
  41.             'title' => "Kontakt"
  42.         ]);
  43.     }
  44. }