1
1
How to Work with Emails During Development
2
2
==========================================
3
3
4
- When you are creating an application which sends emails you will often
5
- not want to actually send the emails to the specified recipient during
6
- development. If you are using the ``SwiftmailerBundle `` with Symfony2 you
4
+ When you are creating an application which sends emails, you will often
5
+ not want to actually send the emails to the specified recipient while
6
+ development. If you are using the ``SwiftmailerBundle `` with Symfony2, you
7
7
can easily achieve this through configuration settings without having to
8
8
make any changes to your application's code at all. There are two main
9
- choices to disable sending emails altogether and to send them all to a
10
- specified address.
9
+ choices when it comes to handling emails during development: (a) disabling the
10
+ sending of emails altogether or (b) sending all the emails to a specified
11
+ address.
11
12
12
13
Disabling Sending
13
14
-----------------
14
15
15
16
You can disable sending emails by setting the ``disable_delivery `` option
16
17
to ``true ``. This is the default in the ``test `` environment in the Standard
17
18
distribution. If you do this in the ``test `` specific config then emails
18
- will not be sent when you run tets and will continue to be sent in the
19
+ will not be sent when you run tests, but will continue to be sent in the
19
20
``prod `` and ``dev `` environments:
20
21
21
22
.. configuration-block ::
@@ -45,13 +46,15 @@ will not be sent when you run tets and will continue to be sent in the
45
46
'disable_delivery' => "true",
46
47
));
47
48
49
+ If you'd also like to disable deliver in the ``dev `` environment, simply
50
+ add this configuration to the ``config_dev.yml `` file.
48
51
49
- Sending to a Specifed Address
50
- -----------------------------
52
+ Sending to a Specified Address
53
+ ------------------------------
51
54
52
- You can also choose to have all emails sent to an address set in the config,
53
- instead of the address they are set to be sent to, with the `` delivery_address ``
54
- option:
55
+ You can also choose to have all emails sent to a specific address, instead
56
+ of the address actually specified when sending the message. This can be done
57
+ via the `` delivery_address `` option:
55
58
56
59
.. configuration-block ::
57
60
@@ -80,7 +83,7 @@ option:
80
83
'delivery_address' => "dev@example.com",
81
84
));
82
85
83
- So if an email is sent from your app:
86
+ Now, suppose you're sending an email to `` recipient@example.com ``.
84
87
85
88
.. code-block :: php
86
89
@@ -97,15 +100,15 @@ So if an email is sent from your app:
97
100
return $this->render(...);
98
101
}
99
102
100
- Then instead of being sent to ``recipient @example.com `` it will be sent
101
- to `` dev@example.com ``. Swiftmailer will add an extra header to the email,
102
- `` X-Swift-To `` containing the replaced address, so you will still be able
103
- to see who it would have been sent to.
103
+ In the `` dev `` environment, the email will instead be sent to ``dev @example.com ``.
104
+ Swiftmailer will add an extra header to the email, `` X-Swift-To `` containing
105
+ the replaced address, so you will still be able to see who it would have been
106
+ sent to.
104
107
105
108
.. note ::
106
109
107
- As well as ``to `` addresses, this will also stop the email being sent
108
- to any ``CC `` and ``BCC `` addresses set for it. Swiftmailer will add
110
+ In addition to the ``to `` addresses, this will also stop the email being
111
+ sent to any ``CC `` and ``BCC `` addresses set for it. Swiftmailer will add
109
112
additional headers to the email with the overridden addresses in them.
110
113
These are ``X-Swift-Cc `` and ``X-Swift-Bcc `` for the ``CC `` and ``BCC ``
111
114
addresses respectively.
@@ -115,5 +118,9 @@ Viewing from the Web Debug Toolbar
115
118
116
119
You can view any emails sent by a page when you are in the ``dev `` environment
117
120
using the Web Debug Toolbar. The email icon in the toolbar will show how
118
- many emails were sent. If you click it a report showing the details of the
121
+ many emails were sent. If you click, it a report showing the details of the
119
122
emails will open.
123
+
124
+ If you're sending an email and then redirecting immediately after, you'll
125
+ need to set the ``intercept_redirects `` option to ``true `` in the ``config_dev.yml ``
126
+ file so that you can see the email in the web debug toolbar before being redirected.
0 commit comments