@@ -3,9 +3,66 @@ Mailer Component
3
3
4
4
The Mailer component helps sending emails.
5
5
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
+
25
+
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
+
6
62
Resources
7
63
---------
8
64
65
+ * [ Documentation] ( https://symfony.com/doc/current/mailer.html )
9
66
* [ Contributing] ( https://symfony.com/doc/current/contributing/index.html )
10
67
* [ Report issues] ( https://github.com/symfony/symfony/issues ) and
11
68
[ send Pull Requests] ( https://github.com/symfony/symfony/pulls )
0 commit comments