sajad torkamani

In a nutshell

Symfony’s Mailer and Mime components give you a powerful way to create and send emails with support for:



composer require symfony/mailer

Setup transport (e.g., SMTP)

Your emails are delivered via a “transport”. Configure your transport at config/packages/mailer.yaml:

        dsn: '%env(MAILER_DSN)%'

Symfony’s Mailer also supports several 3rd party providers like SendGrid or Mailgun and provides Flex recipes to ease the installation and setup. View the docs for more info.

Create and send message

// src/Controller/MailerController.php
namespace App\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Mailer\MailerInterface;
use Symfony\Component\Mime\Email;
use Symfony\Component\Routing\Annotation\Route;

class MailerController extends AbstractController
    public function sendEmail(MailerInterface $mailer): Response
        $email = (new Email())
            ->subject('Time for Symfony Mailer!')
            ->text('Sending emails is fun again!')
            ->html('<p>See Twig integration for better HTML integration!</p>');


        // ...

This will send the message via the transport you configured. If you configured the transport to send emails asynchronously, the message won’t be sent until a worker consumes it.

Other notes