Dmitriy Gnatenko 2c154caeca Vendors updated 3 years ago
..
DataCollector da31d8a6df Revert "Vendors updated" 4 years ago
Event da31d8a6df Revert "Vendors updated" 4 years ago
EventListener e5f3fbd37b Vendors updated 3 years ago
Exception 2e430a556d Vendors updated 3 years ago
Header da31d8a6df Revert "Vendors updated" 4 years ago
Messenger da31d8a6df Revert "Vendors updated" 4 years ago
Test e5f3fbd37b Vendors updated 3 years ago
Transport e5f3fbd37b Vendors updated 3 years ago
CHANGELOG.md 9329362bd0 Symfony updated to 5.2 3 years ago
DelayedEnvelope.php 9329362bd0 Symfony updated to 5.2 3 years ago
Envelope.php 9329362bd0 Symfony updated to 5.2 3 years ago
LICENSE e5f3fbd37b Vendors updated 3 years ago
Mailer.php da31d8a6df Revert "Vendors updated" 4 years ago
MailerInterface.php da31d8a6df Revert "Vendors updated" 4 years ago
README.md 3106988397 Vendors updated 4 years ago
SentMessage.php da31d8a6df Revert "Vendors updated" 4 years ago
Transport.php 9329362bd0 Symfony updated to 5.2 3 years ago
composer.json 2c154caeca Vendors updated 3 years ago

README.md

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('hello@example.com')
    ->to('you@example.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);

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