src/Controller/web/WebController.php line 20
<?php
namespace App\Controller\web;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Mailer\MailerInterface;
use Symfony\Bridge\Twig\Mime\TemplatedEmail;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Routing\Attribute\Route;
class WebController extends AbstractController
{
#[Route('/', name: 'index')]
public function index(): Response
{
return $this->render('web/index.html.twig', []);
}
#[Route('/php', name: 'php')]
public function php(): Response
{
return phpinfo();
}
#[Route('/about', name: 'about')]
public function about(): Response
{
return $this->render('web/about.html.twig', []);
}
#[Route('/contact', name: 'contact')]
public function contact(MailerInterface $mailer, Request $request): Response
{
$contactForm = $this->createFormBuilder()
->add('name', TextType::class, [
'label' => false,
'attr' => [
'placeholder' => 'Name',
'class' => 'mb-3 rounded-0 py-2'
]
])
->add('email', TextType::class, [
'label' => false,
'attr' => [
'rows' => 5,
'placeholder' => 'Email',
'class' => 'mb-3 rounded-0 py-2'
]
])
->add('subject', TextType::class, [
'label' => false,
'attr' => [
'rows' => 5,
'placeholder' => 'Subject',
'class' => 'mb-3 rounded-0 py-2'
]
])
->add('message', TextareaType::class, [
'label' => false,
'attr' => [
'rows' => 5,
'placeholder' => 'Message',
'class' => 'mb-3 rounded-0 py-2'
]
])
->add('Send', SubmitType::class, [
'attr' => [
'class' => 'btn-primary px-4 fw-bold text-white w-100 rounded-0 py-2'
]
])
->getForm();
$contactForm->handleRequest($request);
if ($contactForm->isSubmitted()) {
$input = $contactForm->getData();
$name = ($input['name']);
$userEmail = ($input['email']);
$subject = ($input['subject']);
$message = ($input['message']);
$mainEmail = (new TemplatedEmail())
->from("niraloyinfo@gmail.com")
->to("niraloyinfo@gmail.com")
->subject($subject)
->htmlTemplate('mailer/index.html.twig')
->context([
'name' => $name,
'userEmail' => $userEmail,
'subject' => $subject,
'message' => $message,
]);
$mailer->send($mainEmail);
$this->addFlash('successMessage', 'Thank you for contacting us. We will get back to you soon');
return $this->redirect($this->generateUrl('contact'));
};
return $this->render('web/contact.html.twig', [
'contactForm' => $contactForm->createView()
]);
}
#[Route('/terms', name: 'terms')]
public function terms(): Response
{
return $this->render('web/terms.html.twig', []);
}
#[Route('/policy', name: 'policy')]
public function policy(): Response
{
return $this->render('web/policy.html.twig', []);
}
#[Route('/test', name: 'test')]
public function test(): Response
{
return $this->render('user/profile/_email_reference_verify.html.twig', []);
}
}