The Mailer component helps sending emails

Overview

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

Comments
  • Removing unneeded mode checking in SendmailTransport

    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 😅

    opened by joelpittet 2
  • Update AbstractTransport.php

    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...

    opened by ThomasLandauer 2
  • [Mailer] Include all transports' debug messages in RoundRobin transport exception

    [Mailer] Include all transports' debug messages in RoundRobin transport exception

    The RoundRobin Mail transport does not include inner transports' debug messages in case of failure, which makes it very difficult to reason about the failures.

    This PR attempts to add that debug information to the thrown TransportException.

    In the process of fixing this issue, I discovered that one of the existing tests is incorrect. The last assertion is never executed and the test passes regardless of the assertion state. The test was also fixed.

    opened by mixdf 1
  • [Mailer] Handle missed sender name

    [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')
        )
    );
    
    opened by bobahvas 1
  • fixing send email when tls is disabled 6.0

    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))

    opened by Soffi-Zahir 1
  • [Mailer] Make `Transports` and `Mailer` private properties read-only.

    [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.

    opened by OlivierKessler01 1
  • Update EsmtpTransport.php for TLS error when in SMTP mode

    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.

    opened by sebheitzmann 1
Releases(v6.2.0-RC1)
  • v6.2.0-RC1(Nov 25, 2022)

  • v6.2.0-BETA3(Nov 19, 2022)

    Changelog (https://github.com/symfony/mailer/compare/v6.2.0-BETA2...v6.2.0-BETA3)

    • bug #48075 Stream timeout not detected fgets returns false (Sezil)
    Source code(tar.gz)
    Source code(zip)
  • v6.2.0-BETA2(Oct 28, 2022)

  • v6.1.7(Oct 28, 2022)

  • v6.0.15(Oct 28, 2022)

  • v5.4.15(Oct 28, 2022)

  • v4.4.48(Oct 28, 2022)

  • v6.2.0-BETA1(Oct 24, 2022)

    Changelog (https://github.com/symfony/mailer/compare/v6.1.6...v6.2.0-BETA1)

    • feature #47711 deprecate attach/embed methods in favor of Email::addPart() (fabpot)
    • feature #47730 Ban DateTime from the codebase (WebMamba)
    • feature #47462 Simplify adding Parts to an Email (fabpot)
    • feature #47190 Add a way to change the Bus transport dynamically (fabpot)
    • feature #47191 Add a way to inject Stamps when sending an email via Messenger (fabpot)
    • feature #47170 Use better error code when auth fails (fabpot)
    • feature #47080 Add new events (fabpot)
    • feature #47049 Throw a more specific exception when a BodyRendererInterface is needed but not configured (fabpot)
    • feature #47040 Add a mailer:test command (fabpot)
    • feature #46326 SMTP Transport to provide the (final) Message-ID if available (Raphaël Droz)
    • feature #45404 allow custom hosts for ses+smtp with amazon mailer (jrushlow)
    • feature #46211 Add Infobip bridge (B-Galati)
    • feature #46183 Hide sensitive information with SensitiveParameter attribute (GromNaN)
    • feature #46714 Deprecate OhMySmtp Transport, Create MailPace transport (Holicz)
    • feature #46315 max_per_second option configurable via DSN (gassan)
    Source code(tar.gz)
    Source code(zip)
  • v6.1.5(Sep 30, 2022)

    Changelog (https://github.com/symfony/mailer/compare/v6.1.4...v6.1.5)

    • bug #47703 Apply the default value of 512 for max depths (nurtext)
    • bug #47403 Fix edge cases in STMP transports (fabpot)
    Source code(tar.gz)
    Source code(zip)
  • v6.0.13(Sep 30, 2022)

  • v5.4.13(Sep 30, 2022)

  • v4.4.46(Sep 30, 2022)

  • v6.1.4(Aug 26, 2022)

    Changelog (https://github.com/symfony/mailer/compare/v6.1.3...v6.1.4)

    • bug #47162 Fix error message in case of an SMTP error (fabpot)
    • bug #47142 Fix error message in case of an STMP error (fabpot)
    Source code(tar.gz)
    Source code(zip)
  • v6.0.12(Aug 26, 2022)

    Changelog (https://github.com/symfony/mailer/compare/v6.0.11...v6.0.12)

    • bug #47161 Fix logic (fabpot)
    • bug #47142 Fix error message in case of an STMP error (fabpot)
    Source code(tar.gz)
    Source code(zip)
  • v5.4.12(Aug 26, 2022)

    Changelog (https://github.com/symfony/mailer/compare/v5.4.11...v5.4.12)

    • bug #47161 Fix logic (fabpot)
    • bug #47142 Fix error message in case of an STMP error (fabpot)
    Source code(tar.gz)
    Source code(zip)
  • v4.4.45(Aug 26, 2022)

    Changelog (https://github.com/symfony/mailer/compare/v4.4.44...v4.4.45)

    • bug #47161 Fix logic (fabpot)
    • bug #47142 Fix error message in case of an STMP error (fabpot)
    Source code(tar.gz)
    Source code(zip)
  • v6.1.3(Jul 29, 2022)

  • v6.0.11(Jul 29, 2022)

  • v5.4.11(Jul 29, 2022)

  • v4.4.44(Jul 29, 2022)

  • v6.1.2(Jun 26, 2022)

    Changelog (https://github.com/symfony/mailer/compare/v6.1.1...v6.1.2)

    • bug #46603 Fix Error Handling for OhMySMTP Bridge (paul-oms)
    • bug #46368 Fix for missing sender name in case with usage of the EnvelopeListener (bobahvas)
    Source code(tar.gz)
    Source code(zip)
  • v6.0.10(Jun 26, 2022)

    Changelog (https://github.com/symfony/mailer/compare/v6.0.9...v6.0.10)

    • bug #46603 Fix Error Handling for OhMySMTP Bridge (paul-oms)
    • bug #46368 Fix for missing sender name in case with usage of the EnvelopeListener (bobahvas)
    Source code(tar.gz)
    Source code(zip)
  • v5.4.10(Jun 26, 2022)

    Changelog (https://github.com/symfony/mailer/compare/v5.4.9...v5.4.10)

    • bug #46603 Fix Error Handling for OhMySMTP Bridge (paul-oms)
    • bug #46368 Fix for missing sender name in case with usage of the EnvelopeListener (bobahvas)
    Source code(tar.gz)
    Source code(zip)
  • v4.4.43(Jun 26, 2022)

    Changelog (https://github.com/symfony/mailer/compare/v4.4.42...v4.4.43)

    • bug #46368 Fix for missing sender name in case with usage of the EnvelopeListener (bobahvas)
    Source code(tar.gz)
    Source code(zip)
  • v6.1.1(Jun 9, 2022)

  • v6.1.0(May 27, 2022)

  • v6.1.0-RC1(May 14, 2022)

  • v6.1.0-BETA2(Apr 27, 2022)

    Changelog (https://github.com/symfony/mailer/compare/v6.1.0-BETA1...v6.1.0-BETA2)

    • bug #46154 Restore X-Transport after failure (zenas1210)
    Source code(tar.gz)
    Source code(zip)
  • v6.0.8(Apr 27, 2022)

    Changelog (https://github.com/symfony/mailer/compare/v6.0.7...v6.0.8)

    • bug #46154 Restore X-Transport after failure (zenas1210)
    • bug #45992 Return-Path has higher priority for envelope address than From address (tpetry)
    Source code(tar.gz)
    Source code(zip)
  • v5.4.8(Apr 27, 2022)

    Changelog (https://github.com/symfony/mailer/compare/v5.4.7...v5.4.8)

    • bug #46154 Restore X-Transport after failure (zenas1210)
    • bug #45992 Return-Path has higher priority for envelope address than From address (tpetry)
    Source code(tar.gz)
    Source code(zip)
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

Tijs Verkoyen 5.6k Dec 3, 2022
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

Lucas Alcantara Rodrigues Volpati 1 Feb 9, 2022
A ready-to-use PHP script for sending Emails with an HTML Template will use a Gmail account as the sender and you will not need any email server. Powered by PHPMailer.

Gmail Email Sender by PHP A ready-to-use PHP script for sending Emails with an HTML Template will use a Gmail account as the sender and you will not n

Max Base 4 Oct 29, 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

Symfony 49 Nov 7, 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.

Yii Software 9 Oct 26, 2022
Messenger mailer bundle

messenger-mailer-bundle About Install Usage Contributing About You might need to bundle if your project fulfills the following criteria: You are using

Fusonic GmbH 5 Nov 8, 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

Sergey 1.5k Dec 3, 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 é

Arnaud Lemercier 19 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

null 3 Apr 12, 2022
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

Sam Carré 249 Nov 2, 2022
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

Dren Kajmakchi 4 Aug 21, 2018
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

David Carr 201 Nov 16, 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 Installation Use the package manager composer to install Mail Web. composer r

Appoly 63 Nov 26, 2022
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

null 1.1k Nov 29, 2022
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

PHPMailer 18.9k Nov 28, 2022
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.

null 82 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.

Itineris Limited 60 Nov 14, 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

Raju Rayhan 19 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.

SUSHIL KUMBHAR 2 Dec 8, 2021