Skip to content

Commit de51b77

Browse files
hariktweaverryan
authored andcommitted
Incorporate changes requested by @weaverryan
1 parent 704cc0c commit de51b77

File tree

1 file changed

+20
-22
lines changed

1 file changed

+20
-22
lines changed

components/mailer.rst

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ Introduction
2929
Usage
3030
-----
3131

32+
The Mailer component has two main classes: a ``Transport`` and the ``Mailer`` itself::
33+
3234
use Symfony\Component\Mailer\Mailer;
3335
use Symfony\Component\Mailer\Transport\Smtp\SmtpTransport;
3436

@@ -38,12 +40,13 @@ Usage
3840

3941
Refer :doc:`Mime component </components/mime>` how to create `$email` object.
4042

41-
4243
Transport
4344
---------
4445

4546
By default, the only transport available in the mailer component is Smtp.
47+
4648
Below is the list of other popular providers with built in support.
49+
4750
- Amazon SES : symfony/amazon-mailer
4851
- Google Gmail : symfony/google-mailer
4952
- Mandrill : symfony/mailchimp-mailer
@@ -57,24 +60,24 @@ For example to use google's gmail as a transport you need to install symfony/goo
5760
5861
$ composer require symfony/google-mailer
5962
60-
.. include:: /components/require_autoload.rst.inc
61-
62-
63+
.. code-block:: php
6364
use Symfony\Component\Mailer\Bridge\Google\Smtp\GmailTransport;
6465
6566
$transport = new GmailTransport('user', 'pass');
66-
$transport->send($email);
67+
$mailer = new Mailer($transport);
68+
$mailer->send($email);
6769
6870
Use a Dsn
6971
---------
7072

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::
7274

7375
use Symfony\Component\Mailer\Transport;
7476

7577
$transport = Transport::fromDsn($dsn);
7678

77-
Where `$dns` as one of the form below.
79+
Where ``$dns`` as one of the form below.
80+
7881
- smtp://user:pass@gmail
7982
- smtp://key@sendgrid
8083
- smtp://null
@@ -88,37 +91,32 @@ Easily switch from SMTP in dev to a "real" provider in production with same API.
8891
Failover transport
8992
------------------
9093

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::
9495

9596
$dsn = 'api://id@postmark || smtp://key@sendgrid';
9697

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.
9899

99-
RoundRobin
100-
----------
100+
Round Robin
101+
-----------
101102

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::
103105

104-
Eg :
105-
106106
$dsn = 'api://id@postmark && smtp://key@sendgrid'
107107

108-
109108
Async
110109
-----
111110

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.
115112

116113
.. code-block:: terminal
117114
118115
$ composer require symfony/messenger
119116
120-
.. include:: /components/require_autoload.rst.inc
117+
Then, instantiate and pass a ``MessageBus`` as a second argument to ``Mailer``::
121118

119+
.. code-block:: php
122120
use Symfony\Component\Mailer\Mailer;
123121
use Symfony\Component\Mailer\Messenger\MessageHandler;
124122
use Symfony\Component\Mailer\Messenger\SendEmailMessage;
@@ -135,7 +133,7 @@ And async when `$bus` is configured for EnvelopedMessage.
135133
136134
$bus = new MessageBus([
137135
new HandleMessageMiddleware(new HandlersLocator([
138-
SendEmailMessage::class => ['message_hander' => $handler],
136+
SendEmailMessage::class => [$handler],
139137
])),
140138
]);
141139

0 commit comments

Comments
 (0)