The Mailer component helps sending emails

Last update: Aug 8, 2022

Mailer Component

The Mailer component helps sending emails.

Getting Started

$ composer require symfony/mailer
use Symfony\Component\Mailer\Transport;
use Symfony\Component\Mailer\Mailer;

$transport = Transport::fromDsn('smtp://localhost');
$mailer = new Mailer($transport);

$email = (new Email())
    ->from('[email protected]')
    ->to('[email protected]')
    //->cc('[email protected]')
    //->bcc('[email protected]')
    //->replyTo('[email protected]')
    //->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);

To enable the Twig integration of the Mailer, require symfony/twig-bridge and set up the BodyRenderer:

use Symfony\Bridge\Twig\Mime\BodyRenderer;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\Mailer\EventListener\MessageListener;
use Twig\Environment as TwigEnvironment;

$twig = new TwigEnvironment(...);
$messageListener = new MessageListener(new BodyRenderer($twig));

$eventDispatcher = new EventDispatcher();
$eventDispatcher->addSubscriber($messageListener);

$mailer = new Mailer($transport, null, $eventDispatcher);

$email = (new TemplatedEmail())
    // ...
    ->htmlTemplate('emails/signup.html.twig')
    ->context([
        'expiration_date' => new \DateTime('+7 days'),
        'username' => 'foo',
    ])
;
$mailer->mail($email);

Resources

GitHub

https://github.com/symfony/mailer
Comments
  • 1. Removing unneeded mode checking in SendmailTransport

    The mode checking and exception has been there since this class started in Swiftmailer: https://github.com/swiftmailer/swiftmailer/commit/de5f2f984e03441d3f7c2b10737e9d80ef3bae4f#diff-ab3f44d17819352e5340cebcc66a104a2c60ae6a389cbc012d6d13625cd2b870R87

    It's caused trouble in combination with environment specific scripts that capture or parse mail with overridden ini_get('sendmail_path') like mailhog in my case or we use a custom script that eats mail in our staging environments.

    Here's more context and details around the problem: https://www.drupal.org/project/symfony_mailer/issues/3277333#comment-14619079 https://www.drupal.org/project/swiftmailer/issues/3174215

    I'm creating this PR against 6.1 but we are using "symfony/mailer": "^5.3.0", in Drupal, not sure if this will get in 5.x, but maybe this will help future us 😅

    Reviewed by joelpittet at 2022-07-21 22:37
  • 2. Update AbstractTransport.php

    Removing ? from return type. According to line 66, a SentMessage is returned in any case, isn't it?

    If you agree, this change should be reflected in extending classes as well, e.g. https://github.com/symfony/mailer/blob/4.4/Transport/Smtp/SmtpTransport.php#L129

    Question: What's the recommended way to check if the mail has been sent successfully? I didn't find anything better than $sentMessage->getDebug() yet...

    Reviewed by ThomasLandauer at 2020-06-16 19:19
  • 3. [Mailer] Handle missed sender name

    • [x] bug fix

    Fix missed sender name in case with usage of the EnvelopeListener

    $eventDispatcher = new \Symfony\Component\EventDispatcher\EventDispatcher();
    $eventDispatcher->addSubscriber(
        new \Symfony\Component\Mailer\EventListener\EnvelopeListener(
            new \Symfony\Component\Mime\Address('[email protected]', 'TestName')
        )
    );
    
    Reviewed by bobahvas at 2022-05-16 20:05
  • 4. fixing send email when tls is disabled 6.0

    // WARNING: !$stream->isTLS() is right, 100% sure :) // if you think that the ! should be removed, read the code again // if doing so "fixes" your issue then it probably means your SMTP server behaves incorrectly or is wrongly configured

    in order to send mail when ssl disabled ,we shoud set the condition as :

    if ($stream->isTLS() && \defined('OPENSSL_VERSION_NUMBER') && \array_key_exists('STARTTLS', $capabilities))

    Reviewed by Soffi-Zahir at 2022-02-28 10:13
  • 5. [Mailer] Make `Transports` and `Mailer` private properties read-only.

    | Q | A | ------------- | --- | Branch? | 6.1 | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | | License | MIT | Doc PR |

    "In order to be able to read mailer transports configuration/details from the user space, allow the read of it."

    Basically, I'm working on a project where developers could easily set-up production SMTP on their development environments. Therefore I wanted to add a second protection, hard-coded in our PHP logic relative to the sending of mails which prevents sending an email to any non-local domain. But it seems like their is no way to retrieve the transports configuration from inside my services, other than a really heavy use of reflection.

    It occurred to me that making those properties read-only wouldn't hurt the initial intention of making them impossible to change at runtime by the user, but still making it possible to check their value.

    Reviewed by OlivierKessler01 at 2021-12-30 16:35
  • 6. Update EsmtpTransport.php for TLS error when in SMTP mode

    I thinks that this condition is false. We should not call startTLS if we are not in TLS. see symfony/symfony#36005

    That's my first PR on symfony, so please say me if it's not the right way to do.

    Reviewed by sebheitzmann at 2020-03-25 08:56
This application (class) does the sending of emails used in the phpmailer library

emailsender - PHP Notification library via email using phpMailer This library has the function of sending email using the phpmailer library. Doing thi

Feb 9, 2022
Provides Amazon SES integration for Symfony Mailer

Amazon Mailer Provides Amazon SES integration for Symfony Mailer. Resources Contributing Report issues and send Pull Requests in the main Symfony repo

May 23, 2022
Yii Framework Symfony Mailer Integration

Yii Mailer Library - Symfony Mailer Extension This package is an adapter for yiisoft/mailer relying on symfony/mailer. Requirements PHP 7.4 or higher.

Feb 14, 2022
Manage mailboxes, filter/get/delete emails in PHP (supports IMAP/POP3/NNTP)

PHP IMAP Initially released in December 2012, the PHP IMAP Mailbox is a powerful and open source library to connect to a mailbox by POP3, IMAP and NNT

Aug 8, 2022
Allows you to archive old emails from one Gmail mailbox to another Gmail mailbox

Gmail Archiver L'application Gmail archiver permet de déplacer automatiquement tous les vieux mails d'une boite Gmail vers une autre boite Gmail (ou é

Jan 27, 2022
Queue, preview and and send emails stored in the database.

Codeigniter4 email queue Queue, preview and and send emails stored in the database. This package provides an interface for creating emails on the fly

Apr 12, 2022
Offer an online version of your Laravel emails to users.
Offer an online version of your Laravel emails to users.

This is was a collaborative project with Ryan Chandler. Please consider supporting him for the hard work he put into this package! Help support the ma

Aug 6, 2022
An AngularJS / Laravel app - Keyword Based Email forwarder | read/write emails through IMAP
An AngularJS / Laravel app - Keyword Based Email forwarder | read/write emails through IMAP

@MailTree Simple mail forwarder. Based on the specific email body/subject keywords forward mails to the list of predefined users. Install Imap Install

Aug 21, 2018
Store outgoing emails in Laravel
Store outgoing emails in Laravel

Record and view all sent emails Watch a video walkthrough https://www.youtube.com/watch?v=Oj_OF5n4l4k&feature=youtu.be Documentation and install instr

Aug 7, 2022
Mail Web is a Laravel package which catches emails locally for debugging
 Mail Web is a Laravel package which catches emails locally for debugging

Mail Web is a Laravel package which catches emails locally for debugging Installation Use the package manager composer to install Mail Web. composer r

Jul 27, 2022
Send beautiful HTML emails with Laravel
Send beautiful HTML emails with Laravel

Beautymail for Laravel Beautymail makes it super easy to send beautiful responsive HTML emails. It's made for things like: Welcome emails Password rem

Aug 13, 2022
The classic email sending library for PHP
The classic email sending library for PHP

PHPMailer – A full-featured email creation and transfer class for PHP Features Probably the world's most popular code for sending email from PHP! Used

Aug 11, 2022
Mail sending module for Mezzio and Laminas MVC with support for file attachment and template email composition
Mail sending module for Mezzio and Laminas MVC with support for file attachment and template email composition

This module provides an easy and flexible way to send emails from Mezzio and Laminas MVC applications (formerly known as Zend Expressive and Zend MVC). It allows you to pre-configure emails and transports, and then send those emails at runtime.

Jan 16, 2022
Provides a clean and simple way to configure the WordPress-bundled PHPMailer library, allowing you to quickly get started sending mail through a local or cloud based service of your choice

WP PHPMailer provides a clean and simple way to configure the WordPress-bundled PHPMailer library, allowing you to quickly get started sending mail through a local or cloud based service of your choice.

Jul 21, 2022
Sending Email via Microsoft Exchange Web Services made Easy!

Send Mail via Exchange Web Services! Sending Email via Microsoft Exchange Web Services (EWS) made easy! Installation Install via Composer composer req

Jul 19, 2022
Simple mail sending by PHPMailer and Create your local system.

Simple mail sending by PHPMailer and Create your local system. Send mail zero of cost and also send Attachment like Photo, pdf and multiple files. You should be create a login and verify two steps authentication like OTP, verifications ?? link. PHPMailer make your dreams project eassy and simple also free of cost.

Dec 8, 2021
A simplified SMPP client lib for sending or receiving smses through SMPP v3.4.

PHP-based SMPP client lib This is a simplified SMPP client lib for sending or receiving smses through SMPP v3.4. In addition to the client, this lib a

Jul 26, 2022
Magento 2 SMTP Extension helps the owner of store simply install SMTP server
Magento 2 SMTP Extension helps the owner of store simply install SMTP server

Magento 2 SMTP Extension helps the owner of store simply install SMTP (Simple Mail Transfer Protocol) server which transmits the messages into codes or numbers.

Jul 29, 2022
CssToInlineStyles is a class that enables you to convert HTML-pages/files into HTML-pages/files with inline styles. This is very usefull when you're sending emails.

CssToInlineStyles class Installation CssToInlineStyles is a class that enables you to convert HTML-pages/files into HTML-pages/files with inline style

Aug 11, 2022
Microservice for sending emails with Lumen

Microservice for send email Microservice developed in Lumen for sending emails in real time or by queue. Current Features Send email in real time Send

Aug 1, 2022