<?php
namespace App\Controller;
use Symfony\Component\Mime\Email;
use Symfony\Component\Mailer\MailerInterface;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
class HomeController extends AbstractController
{
#[Route('/', name: 'app_home')]
public function index(): Response
{
$name = "chen";
return $this->render('home/index.html.twig', [
'name' => $name
]);
}
#[Route('/email', name: 'email')]
public function sendEmail(MailerInterface $mailer): Response
{
$name = "chen";
$email = (new Email())
->from('hello@example.com')
->to('chennuo0142@gmail.com')
//->cc('cc@example.com')
//->bcc('bcc@example.com')
//->replyTo('fabien@example.com')
//->priority(Email::PRIORITY_HIGH)
->subject('Time for Symfony Mailer!')
->text('Sending emails is fun again!')
->html('<p>See Twig integration for better HTML integration!</p>');
$mailer->send($email);
return $this->render('home/index.html.twig', [
'name' => $name
]);
}
}