src/Controller/web/WebController.php line 20

  1. <?php
  2. namespace App\Controller\web;
  3. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  4. use Symfony\Component\HttpFoundation\Request;
  5. use Symfony\Component\HttpFoundation\Response;
  6. use Symfony\Component\Mailer\MailerInterface;
  7. use Symfony\Bridge\Twig\Mime\TemplatedEmail;
  8. use Symfony\Component\Form\Extension\Core\Type\SubmitType;
  9. use Symfony\Component\Form\Extension\Core\Type\TextareaType;
  10. use Symfony\Component\Form\Extension\Core\Type\TextType;
  11. use Symfony\Component\Routing\Attribute\Route;
  12. class WebController extends AbstractController
  13. {
  14.     #[Route('/'name'index')]
  15.     public function index(): Response
  16.     {
  17.         return $this->render('web/index.html.twig', []);
  18.     }
  19.     #[Route('/php'name'php')]
  20.     public function php(): Response
  21.     {
  22.         return phpinfo();
  23.     }
  24.     #[Route('/about'name'about')]
  25.     public function about(): Response
  26.     {
  27.         return $this->render('web/about.html.twig', []);
  28.     }
  29.     #[Route('/contact'name'contact')]
  30.     public function contact(MailerInterface $mailerRequest $request): Response
  31.     {
  32.         $contactForm $this->createFormBuilder()
  33.             ->add('name'TextType::class,  [
  34.                 'label' => false,
  35.                 'attr' => [
  36.                     'placeholder' => 'Name',
  37.                     'class' => 'mb-3 rounded-0 py-2'
  38.                 ]
  39.             ])
  40.             ->add('email'TextType::class, [
  41.                 'label' => false,
  42.                 'attr' => [
  43.                     'rows' => 5,
  44.                     'placeholder' => 'Email',
  45.                     'class' => 'mb-3 rounded-0 py-2'
  46.                 ]
  47.             ])
  48.             ->add('subject'TextType::class,  [
  49.                 'label' => false,
  50.                 'attr' => [
  51.                     'rows' => 5,
  52.                     'placeholder' => 'Subject',
  53.                     'class' => 'mb-3 rounded-0 py-2'
  54.                 ]
  55.             ])
  56.             ->add('message'TextareaType::class, [
  57.                 'label' => false,
  58.                 'attr' => [
  59.                     'rows' => 5,
  60.                     'placeholder' => 'Message',
  61.                     'class' => 'mb-3 rounded-0 py-2'
  62.                 ]
  63.             ])
  64.             ->add('Send'SubmitType::class, [
  65.                 'attr' => [
  66.                     'class' => 'btn-primary px-4 fw-bold text-white w-100 rounded-0 py-2'
  67.                 ]
  68.             ])
  69.             ->getForm();
  70.         $contactForm->handleRequest($request);
  71.         if ($contactForm->isSubmitted()) {
  72.             $input $contactForm->getData();
  73.             $name = ($input['name']);
  74.             $userEmail = ($input['email']);
  75.             $subject = ($input['subject']);
  76.             $message = ($input['message']);
  77.             $mainEmail = (new TemplatedEmail())
  78.                 ->from("niraloyinfo@gmail.com")
  79.                 ->to("niraloyinfo@gmail.com")
  80.                 ->subject($subject)
  81.                 ->htmlTemplate('mailer/index.html.twig')
  82.                 ->context([
  83.                     'name' => $name,
  84.                     'userEmail' => $userEmail,
  85.                     'subject' => $subject,
  86.                     'message' => $message,
  87.                 ]);
  88.             $mailer->send($mainEmail);
  89.             $this->addFlash('successMessage''Thank you for contacting us. We will get back to you soon');
  90.             return  $this->redirect($this->generateUrl('contact'));
  91.         };
  92.         return $this->render('web/contact.html.twig', [
  93.             'contactForm' =>  $contactForm->createView()
  94.         ]);
  95.     }
  96.     #[Route('/terms'name'terms')]
  97.     public function terms(): Response
  98.     {
  99.         return $this->render('web/terms.html.twig', []);
  100.     }
  101.     #[Route('/policy'name'policy')]
  102.     public function policy(): Response
  103.     {
  104.         return $this->render('web/policy.html.twig', []);
  105.     }
  106.     #[Route('/test'name'test')]
  107.     public function test(): Response
  108.     {
  109.         return $this->render('user/profile/_email_reference_verify.html.twig', []);
  110.     }
  111. }