@@ -29,6 +29,8 @@ Introduction
29
29
Usage
30
30
-----
31
31
32
+ The Mailer component has two main classes: a ``Transport `` and the ``Mailer `` itself::
33
+
32
34
use Symfony\Component\Mailer\Mailer;
33
35
use Symfony\Component\Mailer\Transport\Smtp\SmtpTransport;
34
36
@@ -38,12 +40,13 @@ Usage
38
40
39
41
Refer :doc: `Mime component </components/mime >` how to create `$email ` object.
40
42
41
-
42
43
Transport
43
44
---------
44
45
45
46
By default, the only transport available in the mailer component is Smtp.
47
+
46
48
Below is the list of other popular providers with built in support.
49
+
47
50
- Amazon SES : symfony/amazon-mailer
48
51
- Google Gmail : symfony/google-mailer
49
52
- Mandrill : symfony/mailchimp-mailer
@@ -57,24 +60,24 @@ For example to use google's gmail as a transport you need to install symfony/goo
57
60
58
61
$ composer require symfony/google-mailer
59
62
60
- .. include :: /components/require_autoload.rst.inc
61
-
62
-
63
+ .. code-block :: php
63
64
use Symfony\Component\Mailer\Bridge\Google\Smtp\GmailTransport;
64
65
65
66
$transport = new GmailTransport('user', 'pass');
66
- $transport->send($email);
67
+ $mailer = new Mailer($transport);
68
+ $mailer->send($email);
67
69
68
70
Use a Dsn
69
71
---------
70
72
71
- The mailer component provides a convenient way to create transport object from dsn string.
73
+ The mailer component provides a convenient way to create transport object from dsn string::
72
74
73
75
use Symfony\Component\Mailer\Transport;
74
76
75
77
$transport = Transport::fromDsn($dsn);
76
78
77
- Where `$dns ` as one of the form below.
79
+ Where ``$dns `` as one of the form below.
80
+
78
81
- smtp://user:pass@gmail
79
82
- smtp://key@sendgrid
80
83
- smtp://null
@@ -88,37 +91,32 @@ Easily switch from SMTP in dev to a "real" provider in production with same API.
88
91
Failover transport
89
92
------------------
90
93
91
- You can create failover transport with the help of `|| ` operator.
92
-
93
- Eg :
94
+ You can create failover transport with the help of `|| ` operator::
94
95
95
96
$dsn = 'api://id@postmark || smtp://key@sendgrid';
96
97
97
- So if it fails at one transport, the mailer will attempt to send through the other transport.
98
+ So if the first transport fails , the mailer will attempt to send through the second transport.
98
99
99
- RoundRobin
100
- ----------
100
+ Round Robin
101
+ -----------
101
102
102
- If you want to send mails via multiple transports, you can use the `&& ` operator between the transports.
103
+ If you want to send emails by using multiple transports in a round-robin fashion, you can use the
104
+ ``&& `` operator between the transports::
103
105
104
- Eg :
105
-
106
106
$dsn = 'api://id@postmark && smtp://key@sendgrid'
107
107
108
-
109
108
Async
110
109
-----
111
110
112
- If you want to use the async functionality you need to install `messenger ` component.
113
- By default, `$bus ` is null and if it is not configured, mailer is always using sync functionality.
114
- And async when `$bus ` is configured for EnvelopedMessage.
111
+ If you want to use the async functionality you need to install the ``messenger `` component.
115
112
116
113
.. code-block :: terminal
117
114
118
115
$ composer require symfony/messenger
119
116
120
- .. include :: /components/require_autoload.rst.inc
117
+ Then, instantiate and pass a `` MessageBus `` as a second argument to `` Mailer ``::
121
118
119
+ .. code-block :: php
122
120
use Symfony\Component\Mailer\Mailer;
123
121
use Symfony\Component\Mailer\Messenger\MessageHandler;
124
122
use Symfony\Component\Mailer\Messenger\SendEmailMessage;
@@ -135,7 +133,7 @@ And async when `$bus` is configured for EnvelopedMessage.
135
133
136
134
$bus = new MessageBus([
137
135
new HandleMessageMiddleware(new HandlersLocator([
138
- SendEmailMessage::class => ['message_hander' => $handler],
136
+ SendEmailMessage::class => [$handler],
139
137
])),
140
138
]);
141
139
0 commit comments