src/Controller/ContactController.php line 65

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Form\ContactFormType;
  4. use App\Entity\Contact;
  5. use Doctrine\ORM\EntityManagerInterface;
  6. use Symfony\Component\HttpFoundation\Request;
  7. use Symfony\Component\HttpFoundation\Response;
  8. use Symfony\Component\Routing\Annotation\Route;
  9. use Symfony\Component\BrowserKit\Request as BrowserKitRequest;
  10. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  11. use Symfony\Component\DependencyInjection\Loader\Configurator\mailer;
  12. use Symfony\Component\HttpFoundation\Request as HttpFoundationRequest;
  13. use Symfony\Component\Mailer\MailerInterface;
  14. use Symfony\Component\Mime\Email;
  15. use Symfony\Bridge\Twig\Mime\TemplatedEmail;
  16. use Symfony\Component\Mailer\Transport;
  17.  
  18.  
  19. class ContactController extends AbstractController
  20. {
  21.     
  22.         private $mailer;
  23.     // #[Route('/contact', name: 'contact')]
  24.     // public function sendEmail(Request $request,MailerInterface $mailer): Response
  25.     // {
  26.     //      $form = $this->createForm(ContactFormType::class);
  27.     //     $form->handleRequest($request);
  28.         
  29.     //     $email = (new Email())
  30.     //         ->from('contact@ksdental.ma')
  31.     //         ->to('ayoubelkalali@gmail.com')
  32.     //         //->cc('cc@example.com')
  33.     //         //->bcc('bcc@example.com')
  34.     //         //->replyTo('fabien@example.com')
  35.     //         //->priority(Email::PRIORITY_HIGH)
  36.     //         ->subject('Time for Symfony Mailer!')
  37.     //         ->text('Sending emails is fun again!')
  38.     //         ->html('<p>See Twig integration for better HTML integration!</p>');
  39.     //     $mailer->send($email);
  40.     //     // ...
  41.         
  42.     //      return $this->render('home/contact.html.twig', [
  43.     //         'controller_name' => 'ContactController',
  44.     //     ]);
  45.     // }
  46.     
  47.     
  48.     
  49.     
  50.     
  51.     
  52.     
  53.     
  54.     
  55.     #[Route('/contact'name'contact')]
  56.     public function contact(Request $requestMailerInterface $mailer): Response
  57.     {    
  58.          
  59.         $form $this->createForm(ContactFormType::class);
  60.         $form->handleRequest($request);
  61.         if ($form->isSubmitted() && $form->isValid()) {
  62.             $formData $form->getData();
  63.             
  64.             // dd($formData);
  65.             
  66.             
  67.         }
  68.          
  69.         return $this->render('home/contact.html.twig', [
  70.             'form' => $form->createView(),
  71.              
  72.         ]);
  73.     }
  74.     #[Route('/sendEmail'name'sendEmail')]
  75.     public function sendEmail(Request $request,MailerInterface $mailer): Response
  76.     {
  77.         
  78.                  
  79.         $email = (new Email())
  80.             ->from('contact@gebanalysis.cloud')
  81.             ->to('ayoubelkalali@gmail.com')
  82.             //->cc('cc@example.com')
  83.             //->bcc('bcc@example.com')
  84.             //->replyTo('fabien@example.com')
  85.             //->priority(Email::PRIORITY_HIGH)
  86.             ->subject('Time for Symfony Mailer!')
  87.             ->text('Sending emails is fun again!')
  88.             ->html('<p>See Twig integration for better HTML integration!</p>');
  89.                 $mailer->send($email);
  90.                   
  91.                     dd('ff');
  92.                  return $this->redirectToRoute('contact');
  93.         
  94.         return $this->render('home/contact.html.twig', [
  95.             'controller_name' => 'ContactController',
  96.         ]);
  97.     }
  98. }