Skip to content

Commit d5a3240

Browse files
committed
Updated README for the Mailer component
1 parent fd16ff2 commit d5a3240

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

README.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,66 @@ Mailer Component
33

44
The Mailer component helps sending emails.
55

6+
Getting Started
7+
---------------
8+
9+
```
10+
$ composer require symfony/mailer
11+
```
12+
13+
```php
14+
use Symfony\Component\Mailer\Transport;
15+
use Symfony\Component\Mailer\Mailer;
16+
17+
$transport = Transport::fromDsn('sendgrid://KEY@default');
18+
$mailer = new Mailer($transport);
19+
20+
$email = (new Email())
21+
22+
23+
24+
//->bcc('[email protected]')
25+
//->replyTo('[email protected]')
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+
34+
To enable the Twig integration of the Mailer, require `symfony/twig-bridge` and
35+
set up the `BodyRenderer`:
36+
37+
```php
38+
use Symfony\Bridge\Twig\Mime\BodyRenderer;
39+
use Symfony\Component\EventDispatcher\EventDispatcher;
40+
use Symfony\Component\Mailer\EventListener\MessageListener;
41+
use Twig\Environment as TwigEnvironment;
42+
43+
$twig = new TwigEnvironment(...);
44+
$messageListener = new MessageListener(new BodyRenderer($twig));
45+
46+
$eventDispatcher = new EventDispatcher();
47+
$eventDispatcher->addSubscriber($messageListener);
48+
49+
$mailer = new Mailer($transport, null, $eventDispatcher);
50+
51+
$email = (new TemplatedEmail())
52+
// ...
53+
->htmlTemplate('emails/signup.html.twig')
54+
->context([
55+
'expiration_date' => new \DateTime('+7 days'),
56+
'username' => 'foo',
57+
])
58+
;
59+
$mailer->mail($email);
60+
```
61+
662
Resources
763
---------
864

65+
* [Documentation](https://symfony.com/doc/current/mailer.html)
966
* [Contributing](https://symfony.com/doc/current/contributing/index.html)
1067
* [Report issues](https://github.com/symfony/symfony/issues) and
1168
[send Pull Requests](https://github.com/symfony/symfony/pulls)

0 commit comments

Comments
 (0)