@@ -18,9 +18,9 @@ integration, CSS inlining, file attachments and a lot more. Get them installed w
18
18
Transport Setup
19
19
---------------
20
20
21
- Emails are delivered via a "transport". And without installing anything else , you
22
- can deliver emails over ``smtp `` by configuring your ``.env `` file (the
23
- ``user ``, `` pass `` and `` port `` parameters are optional):
21
+ Emails are delivered via a "transport". Out of the box , you can deliver emails
22
+ over ``SMTP `` by configuring your ``.env `` file (the `` user ``, `` pass `` and
23
+ ``port `` parameters are optional):
24
24
25
25
.. code-block :: bash
26
26
@@ -35,8 +35,8 @@ can deliver emails over ``smtp`` by configuring your ``.env`` file (the
35
35
Using a 3rd Party Transport
36
36
~~~~~~~~~~~~~~~~~~~~~~~~~~~
37
37
38
- But an easier option is to send emails via a 3rd party provider. Mailer supports
39
- several - install whichever you want:
38
+ Instead of using your own SMTP server, you can send emails via a 3rd party
39
+ provider. Mailer supports several - install whichever you want:
40
40
41
41
================== =============================================
42
42
Service Install with
@@ -50,7 +50,7 @@ SendGrid ``composer require symfony/sendgrid-mailer``
50
50
================== =============================================
51
51
52
52
Each library includes a :ref: `Symfony Flex recipe <symfony-flex >` that will add
53
- example configuration to your ``.env `` file. For example, suppose you want to
53
+ a configuration example to your ``.env `` file. For example, suppose you want to
54
54
use SendGrid. First, install it:
55
55
56
56
.. code-block :: terminal
@@ -64,13 +64,11 @@ You'll now have a new line in your ``.env`` file that you can uncomment:
64
64
# .env
65
65
MAILER_DSN=sendgrid://KEY@default
66
66
67
- The ``MAILER_DSN `` isn't a *real * address: it's a simple format that offloads
68
- most of the configuration work to mailer. The ``sendgrid `` scheme activates the
69
- SendGrid provider that you just installed, which knows all about how to deliver
70
- messages to SendGrid.
71
-
72
- The *only * part you need to change is to replace ``KEY `` in the ``MAILER_DSN `` (in
73
- ``.env `` or ``.env.local ``).
67
+ The ``MAILER_DSN `` isn't a *real * address: it's a convenient format that
68
+ offloads most of the configuration work to mailer. The ``sendgrid `` scheme
69
+ activates the SendGrid provider that you just installed, which knows all about
70
+ how to deliver messages via SendGrid. The *only * part you need to change is the
71
+ ``KEY `` placeholder.
74
72
75
73
Each provider has different environment variables that the Mailer uses to
76
74
configure the *actual * protocol, address and authentication for delivery. Some
@@ -93,8 +91,8 @@ Creating & Sending Messages
93
91
---------------------------
94
92
95
93
To send an email, autowire the mailer using
96
- :class: `Symfony\\ Component\\ Mailer\\ MailerInterface ` (service id `` mailer.mailer ``)
97
- and create an :class: `Symfony\\ Component\\ Mime\\ Email ` object::
94
+ :class: `Symfony\\ Component\\ Mailer\\ MailerInterface ` and create an
95
+ :class: `Symfony\\ Component\\ Mime\\ Email ` object::
98
96
99
97
// src/Controller/MailerController.php
100
98
namespace App\Controller;
@@ -127,7 +125,7 @@ and create an :class:`Symfony\\Component\\Mime\\Email` object::
127
125
}
128
126
}
129
127
130
- That's it! The message will be sent via whatever transport you configured.
128
+ That's it! The message will be sent via the transport you configured.
131
129
132
130
Email Addresses
133
131
~~~~~~~~~~~~~~~
@@ -811,20 +809,15 @@ Always Send to the same Address
811
809
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
812
810
813
811
Instead of disabling delivery entirely, you might want to *always * send emails to
814
- a specific address, instead of the *real * address. To do that, you can take
815
- advantage of the ``EnvelopeListener `` and register it *only * for the ``dev ``
816
- environment:
812
+ a specific address, instead of the *real * address:
817
813
818
814
.. code-block :: yaml
819
815
820
- # config/services_dev.yaml
821
- services :
822
- mailer.dev.set_recipients :
823
- class : Symfony\Component\Mailer\EventListener\EnvelopeListener
824
- tags : ['kernel.event_subscriber']
825
- arguments :
826
- $sender : null
827
- $recipients : ['youremail@example.com']
816
+ # config/packages/dev/mailer.yaml
817
+ framework :
818
+ mailer :
819
+ envelope :
820
+ recipients : ['youremail@example.com']
828
821
829
822
.. _`download the foundation-emails.css file` : https://github.com/foundation/foundation-emails/blob/develop/dist/foundation-emails.css
830
823
.. _`league/html-to-markdown` : https://github.com/thephpleague/html-to-markdown
0 commit comments