<?php
namespace App\Controller;
use App\Form\ContactType;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Mailer\MailerInterface;
use Symfony\Component\Mime\Email;
class ContactController extends AbstractController
{
/**
* @Route("/contact", name="contact", methods={"GET","POST"})
*/
public function index(Request $request, MailerInterface $mailer): Response
{
$form = $this->createForm(ContactType::class);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$data = $form->getData();
#$to = 'contact@yourdomain.com'; // CHANGE THIS
$to = 'info@ctssys.com'; // CHANGE THIS
$email = (new Email())
->from($to) // keep from your domain
->replyTo($data['email']) // user email goes here
->to($to)
->subject('CogniEdu Contact Form')
->text(
"Name: {$data['name']}\n" .
"Email: {$data['email']}\n\n" .
$data['message']
);
$mailer->send($email);
$this->addFlash('success', 'Thanks — your message has been sent.');
return $this->redirectToRoute('contact');
}
return $this->render('contact/index.html.twig', [
'form' => $form->createView(),
]);
}
}