@@ -36,9 +36,9 @@ The ``$email`` object is created via the :doc:`Mime component </components/mime>
36
36
Transport
37
37
---------
38
38
39
- The only transport that comes pre-installed with mailer is Smtp .
39
+ The only transport that comes pre-installed is SMTP .
40
40
41
- Below is the list of other popular providers with built in support.
41
+ Below is the list of other popular providers with built- in support:
42
42
43
43
================== =============================================
44
44
Service Install with
@@ -51,12 +51,15 @@ Postmark ``composer require symfony/postmark-mailer``
51
51
SendGrid ``composer require symfony/sendgrid-mailer ``
52
52
================== =============================================
53
53
54
- For example, suppose you want to use Google's Gmail. First, install it:
54
+ For example, suppose you want to use Google's Gmail SMTP server. First, install
55
+ it:
55
56
56
57
.. code-block :: terminal
57
58
58
59
$ composer require symfony/google-mailer
59
60
61
+ Then, use the SMTP Gmail transport:
62
+
60
63
.. code-block :: php
61
64
62
65
use Symfony\Component\Mailer\Bridge\Google\Smtp\GmailTransport;
@@ -65,30 +68,36 @@ For example, suppose you want to use Google's Gmail. First, install it:
65
68
$mailer = new Mailer($transport);
66
69
$mailer->send($email);
67
70
68
- Use a DSN
69
- ---------
71
+ Each provider provides up to 3 transports: standard SMTP, HTTP (it uses the
72
+ provider's API but the body is created by the mailer component), API (it uses
73
+ the full API of the provider with no control over the body creation -- features
74
+ might be limited as well).
70
75
71
- The mailer component provides a convenient way to create transport object from
72
- DSN string::
76
+ .. _mailer_dsn :
77
+
78
+ The mailer component provides a convenient way to create a transport from a
79
+ DSN::
73
80
74
81
use Symfony\Component\Mailer\Transport;
75
82
76
83
$transport = Transport::fromDsn($dsn);
77
84
78
- Where ``$dsn `` as one of the form below.
79
-
80
- - ``smtp://user:pass@gmail ``
81
- - ``smtp://key@sendgrid ``
82
- - ``smtp://null ``
83
- - ``smtp://user:pass@mailgun ``
84
- - ``http://key:domain@mailgun ``
85
- - ``api://id@postmark ``
86
-
87
- This provides a unified behavior across all providers.
88
- Easily switch from SMTP in development to a "real" provider in production
89
- with same API.
90
-
91
- Failover transport
85
+ Where ``$dsn `` depends on the provider you want to use. For plain SMTP, use
86
+ ``smtp://user:pass@example.com `` or ``smtp://sendmail `` to use the ``sendmail ``
87
+ binary. For third-party providers, refers to the following table:
88
+
89
+ ==================== ================================== ================================== ================================
90
+ Provider SMTP HTTP API
91
+ ==================== ================================== ================================== ================================
92
+ Amazon SES smtp://ACCESS_KEY:SECRET_KEY@ses http://ACCESS_KEY:SECRET_KEY@ses api://ACCESS_KEY:SECRET_KEY@ses
93
+ Google Gmail smtp://USERNAME:PASSWORD@gmail n/a n/a
94
+ Mailchimp Mandrill smtp://USERNAME:PASSWORD@mandrill http://KEY@mandrill api://KEY@mandrill
95
+ Mailgun smtp://USERNAME:PASSWORD@mailgun http://KEY:DOMAIN@mailgun api://KEY:DOMAIN@mailgun
96
+ Postmark smtp://ID:ID@postmark n/a api://KEY@postmark
97
+ Sendgrid smtp://apikey:KEY@sendgrid n/a api://KEY@sendgrid
98
+ ==================== ================================== ================================== ================================
99
+
100
+ Failover Transport
92
101
------------------
93
102
94
103
You can create failover transport with the help of `|| ` operator::
@@ -106,11 +115,11 @@ you can use the ``&&`` operator between the transports::
106
115
107
116
$dsn = 'api://id@postmark && smtp://key@sendgrid'
108
117
109
- Async
110
- -----
118
+ Sending emails asynchronously
119
+ -----------------------------
111
120
112
- If you want to use the async functionality you need to install the
113
- :doc: ` Messenger component </components/messenger >`.
121
+ If you want to send emails asynchronously, install the :doc: ` Messenger component
122
+ </components/messenger>`.
114
123
115
124
.. code-block :: terminal
116
125
@@ -140,11 +149,13 @@ Then, instantiate and pass a ``MessageBus`` as a second argument to ``Mailer``::
140
149
]);
141
150
142
151
$mailer = new Mailer($transport, $bus);
152
+ $mailer->send($email);
143
153
154
+ // you can pass an optional Envelope
144
155
$mailer->send($email, new SmtpEnvelope(
145
156
new Address('sender@example.com'),
146
157
[
147
- new Address('recepient @example.com'),
158
+ new Address('recipient @example.com'),
148
159
]
149
160
));
150
161
0 commit comments