src/Controller/EntryPointController.php

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  4. use Symfony\Component\HttpFoundation\JsonResponse;
  5. use Symfony\Component\HttpFoundation\Response;
  6. use Symfony\Component\Mailer\MailerInterface;
  7. use Symfony\Component\Mime\Email;
  8. use Symfony\Component\Routing\Annotation\Route;
  9. class EntryPointController extends AbstractController
  10. {
  11.     /**
  12.      * @Route("/entry/point", name="entry_point")
  13.      */
  14.     public function index(MailerInterface $mailer): Response
  15.     {
  16.         return $this->render('entry_point/index.html.twig', [
  17.             'controller_name' => 'EntryPointController',
  18.         ]);
  19.     }
  20.     /**
  21.      * @Route("/test/email/config", name="test_email_config")
  22.      */
  23.     public function emailConfig(MailerInterface $mailer): Response
  24.     {
  25.         $email = (new Email())
  26.             ->from('gitlab@sogec-marketing.net')
  27.             ->to('nsagouis@sogec-marketing.com')
  28.             ->subject('Time for Symfony Mailer!')
  29.             ->text('Sending emails is fun again!')
  30.             ->html('<p>See Twig integration for better HTML integration!</p>');
  31.         $mailer->send($email);
  32.         return new JsonResponse(["status" => "email sent"]);
  33.     }
  34. }