@@ -6,7 +6,7 @@ How to Work with Emails during Development
6
6
7
7
When developing an application which sends email, you will often
8
8
not want to actually send the email to the specified recipient during
9
- development. If you are using the SwiftmailerBundle with Symfony, you
9
+ development. If you are using the default Symfony mailer , you
10
10
can easily achieve this through configuration settings without having to
11
11
make any changes to your application's code at all. There are two main
12
12
choices when it comes to handling email during development: (a) disabling the
@@ -16,23 +16,21 @@ address (with optional exceptions).
16
16
Disabling Sending
17
17
-----------------
18
18
19
- You can disable sending email by setting the ``disable_delivery `` option
20
- to ``true ``. This is the default in the ``test `` environment in the Standard
21
- distribution. If you do this in the ``test `` specific config then email
22
- will not be sent when you run tests, but will continue to be sent in the
23
- ``prod `` and ``dev `` environments:
19
+ You can disable sending email by setting the ``disable_delivery `` option to
20
+ ``true ``, which is the default value used by Symfony in the ``test `` environment
21
+ (email messages will continue to be sent in the other environments):
24
22
25
23
.. configuration-block ::
26
24
27
25
.. code-block :: yaml
28
26
29
- # app/ config/config_test.yml
27
+ # config/packages/test/swiftmailer.yaml
30
28
swiftmailer :
31
29
disable_delivery : true
32
30
33
31
.. code-block :: xml
34
32
35
- <!-- app/ config/config_test .xml -->
33
+ <!-- config/packages/test/swiftmailer .xml -->
36
34
<?xml version =" 1.0" encoding =" UTF-8" ?>
37
35
<container xmlns =" http://symfony.com/schema/dic/services"
38
36
xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
@@ -46,14 +44,11 @@ will not be sent when you run tests, but will continue to be sent in the
46
44
47
45
.. code-block :: php
48
46
49
- // app/ config/config_test .php
47
+ // config/packages/test/swiftmailer .php
50
48
$container->loadFromExtension('swiftmailer', array(
51
49
'disable_delivery' => "true",
52
50
));
53
51
54
- If you'd also like to disable deliver in the ``dev `` environment, simply
55
- add this same configuration to the ``config_dev.yml `` file.
56
-
57
52
.. _sending-to-a-specified-address :
58
53
59
54
Sending to a Specified Address(es)
@@ -67,13 +62,13 @@ via the ``delivery_addresses`` option:
67
62
68
63
.. code-block :: yaml
69
64
70
- # app/ config/config_dev.yml
65
+ # config/packages/dev/swiftmailer.yaml
71
66
swiftmailer :
72
67
delivery_addresses : ['dev@example.com']
73
68
74
69
.. code-block :: xml
75
70
76
- <!-- app/ config/config_dev .xml -->
71
+ <!-- config/packages/dev/swiftmailer .xml -->
77
72
<?xml version =" 1.0" encoding =" UTF-8" ?>
78
73
<container xmlns =" http://symfony.com/schema/dic/services"
79
74
xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
@@ -90,16 +85,14 @@ via the ``delivery_addresses`` option:
90
85
91
86
.. code-block :: php
92
87
93
- // app/ config/config_dev .php
88
+ // config/packages/dev/swiftmailer .php
94
89
$container->loadFromExtension('swiftmailer', array(
95
90
'delivery_addresses' => array("dev@example.com"),
96
91
));
97
92
98
- Now, suppose you're sending an email to ``recipient@example.com ``.
99
-
100
- .. code-block :: php
93
+ Now, suppose you're sending an email to ``recipient@example.com `` in a controller::
101
94
102
- public function indexAction ($name, \Swift_Mailer $mailer)
95
+ public function index ($name, \Swift_Mailer $mailer)
103
96
{
104
97
$message = (new \Swift_Message('Hello Email'))
105
98
->setFrom('send@example.com')
@@ -143,7 +136,7 @@ by adding the ``delivery_whitelist`` option:
143
136
144
137
.. code-block :: yaml
145
138
146
- # app/ config/config_dev.yml
139
+ # config/packages/dev/swiftmailer.yaml
147
140
swiftmailer :
148
141
delivery_addresses : ['dev@example.com']
149
142
delivery_whitelist :
@@ -154,7 +147,7 @@ by adding the ``delivery_whitelist`` option:
154
147
155
148
.. code-block :: xml
156
149
157
- <!-- app/ config/config_dev .xml -->
150
+ <!-- config/packages/dev/swiftmailer .xml -->
158
151
<?xml version =" 1.0" encoding =" UTF-8" ?>
159
152
<container xmlns =" http://symfony.com/schema/dic/services"
160
153
xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
@@ -175,7 +168,7 @@ by adding the ``delivery_whitelist`` option:
175
168
176
169
.. code-block :: php
177
170
178
- // app/ config/config_dev .php
171
+ // config/packages/dev/swiftmailer .php
179
172
$container->loadFromExtension('swiftmailer', array(
180
173
'delivery_addresses' => array("dev@example.com"),
181
174
'delivery_whitelist' => array(
@@ -207,20 +200,20 @@ the web debug toolbar will not display an email icon or a report on the next
207
200
page.
208
201
209
202
Instead, you can set the ``intercept_redirects `` option to ``true `` in the
210
- ``config_dev.yml `` file , which will cause the redirect to stop and allow
211
- you to open the report with details of the sent emails.
203
+ ``dev `` environment , which will cause the redirect to stop and allow you to open
204
+ the report with details of the sent emails.
212
205
213
206
.. configuration-block ::
214
207
215
208
.. code-block :: yaml
216
209
217
- # app/ config/config_dev.yml
210
+ # config/packages/dev/swiftmailer.yaml
218
211
web_profiler :
219
212
intercept_redirects : true
220
213
221
214
.. code-block :: xml
222
215
223
- <!-- app/ config/config_dev .xml -->
216
+ <!-- config/packages/dev/swiftmailer .xml -->
224
217
<?xml version =" 1.0" encoding =" UTF-8" ?>
225
218
<container xmlns =" http://symfony.com/schema/dic/services"
226
219
xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
@@ -237,7 +230,7 @@ you to open the report with details of the sent emails.
237
230
238
231
.. code-block :: php
239
232
240
- // app/ config/config_dev .php
233
+ // config/packages/dev/swiftmailer .php
241
234
$container->loadFromExtension('web_profiler', array(
242
235
'intercept_redirects' => 'true',
243
236
));
0 commit comments