• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

DataCollector/H03-May-2022-6131

Event/H03-May-2022-13682

EventListener/H03-May-2022-262171

Exception/H03-May-2022-275124

Header/H03-May-2022-6126

Messenger/H03-May-2022-7538

Test/H03-May-2022-239131

Transport/H03-May-2022-2,1841,293

CHANGELOG.mdH A D03-Dec-20212.2 KiB5743

DelayedEnvelope.phpH A D03-Dec-20212.4 KiB9965

Envelope.phpH A D03-Dec-20212.6 KiB8951

LICENSEH A D03-Dec-20211 KiB2016

Mailer.phpH A D03-Dec-20211.8 KiB5736

MailerInterface.phpH A D03-Dec-2021763 318

README.mdH A D03-Dec-20212 KiB7458

SentMessage.phpH A D03-Dec-20212 KiB9665

Transport.phpH A D03-Dec-20216.4 KiB174130

composer.jsonH A D03-Dec-20211.1 KiB4342

README.md

1Mailer Component
2================
3
4The Mailer component helps sending emails.
5
6Getting Started
7---------------
8
9```
10$ composer require symfony/mailer
11```
12
13```php
14use Symfony\Component\Mailer\Transport;
15use Symfony\Component\Mailer\Mailer;
16
17$transport = Transport::fromDsn('smtp://localhost');
18$mailer = new Mailer($transport);
19
20$email = (new Email())
21    ->from('hello@example.com')
22    ->to('you@example.com')
23    //->cc('cc@example.com')
24    //->bcc('bcc@example.com')
25    //->replyTo('fabien@example.com')
26    //->priority(Email::PRIORITY_HIGH)
27    ->subject('Time for Symfony Mailer!')
28    ->text('Sending emails is fun again!')
29    ->html('<p>See Twig integration for better HTML integration!</p>');
30
31$mailer->send($email);
32```
33
34To enable the Twig integration of the Mailer, require `symfony/twig-bridge` and
35set up the `BodyRenderer`:
36
37```php
38use Symfony\Bridge\Twig\Mime\BodyRenderer;
39use Symfony\Bridge\Twig\Mime\TemplatedEmail;
40use Symfony\Component\EventDispatcher\EventDispatcher;
41use Symfony\Component\Mailer\EventListener\MessageListener;
42use Symfony\Component\Mailer\Mailer;
43use Symfony\Component\Mailer\Transport;
44use Twig\Environment as TwigEnvironment;
45
46$twig = new TwigEnvironment(...);
47$messageListener = new MessageListener(null, new BodyRenderer($twig));
48
49$eventDispatcher = new EventDispatcher();
50$eventDispatcher->addSubscriber($messageListener);
51
52$transport = Transport::fromDsn('smtp://localhost', $eventDispatcher);
53$mailer = new Mailer($transport, null, $eventDispatcher);
54
55$email = (new TemplatedEmail())
56    // ...
57    ->htmlTemplate('emails/signup.html.twig')
58    ->context([
59        'expiration_date' => new \DateTime('+7 days'),
60        'username' => 'foo',
61    ])
62;
63$mailer->send($email);
64```
65
66Resources
67---------
68
69 * [Documentation](https://symfony.com/doc/current/mailer.html)
70 * [Contributing](https://symfony.com/doc/current/contributing/index.html)
71 * [Report issues](https://github.com/symfony/symfony/issues) and
72   [send Pull Requests](https://github.com/symfony/symfony/pulls)
73   in the [main Symfony repository](https://github.com/symfony/symfony)
74