src/Controller/HomeController.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Symfony\Component\Mime\Email;
  4. use Symfony\Component\Mailer\MailerInterface;
  5. use Symfony\Component\HttpFoundation\Response;
  6. use Symfony\Component\Routing\Annotation\Route;
  7. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  8. class HomeController extends AbstractController
  9. {
  10.     #[Route('/'name'app_home')]
  11.     public function index(): Response
  12.     {
  13.         $name "chen";
  14.         return $this->render('home/index.html.twig', [
  15.             'name' => $name
  16.         ]);
  17.     }
  18.     #[Route('/email'name'email')]
  19.     public function sendEmail(MailerInterface $mailer): Response
  20.     {
  21.         $name "chen";
  22.         $email = (new Email())
  23.             ->from('hello@example.com')
  24.             ->to('chennuo0142@gmail.com')
  25.             //->cc('cc@example.com')
  26.             //->bcc('bcc@example.com')
  27.             //->replyTo('fabien@example.com')
  28.             //->priority(Email::PRIORITY_HIGH)
  29.             ->subject('Time for Symfony Mailer!')
  30.             ->text('Sending emails is fun again!')
  31.             ->html('<p>See Twig integration for better HTML integration!</p>');
  32.         $mailer->send($email);
  33.         return $this->render('home/index.html.twig', [
  34.             'name' => $name
  35.         ]);
  36.     }
  37. }