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

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