Skip to content

Commit 299ead1

Browse files
committed
Quick proofread of the email cookbook
1 parent 9a6d7b9 commit 299ead1

File tree

1 file changed

+46
-41
lines changed

1 file changed

+46
-41
lines changed

cookbook/email/email.rst

Lines changed: 46 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -7,43 +7,36 @@ How to Send an Email
77
Sending emails is a classic task for any web application and one that has
88
special complications and potential pitfalls. Instead of recreating the wheel,
99
one solution to send emails is to use the SwiftmailerBundle, which leverages
10-
the power of the `Swift Mailer`_ library.
11-
12-
.. note::
13-
14-
Don't forget to enable the bundle in your kernel before using it::
15-
16-
public function registerBundles()
17-
{
18-
$bundles = array(
19-
// ...
20-
21-
new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
22-
);
23-
24-
// ...
25-
}
10+
the power of the `Swift Mailer`_ library. This bundles comes with the Symfony
11+
Standard Edition.
2612

2713
.. _swift-mailer-configuration:
2814

2915
Configuration
3016
-------------
3117

32-
Before using Swift Mailer, be sure to include its configuration. The only
33-
mandatory configuration parameter is ``transport``:
18+
To use Swift Mailer, you'll need to configure it for your mail server.
19+
20+
.. tip::
21+
22+
Instead of setting up/using your own mail server, you may want to use
23+
a hosted mail provider such as `Mandrill`_, `SendGrid`_, `Amazon SES`_
24+
or others. These give you an SMTP server, username and password (sometimes
25+
called keys) that can be used with the Swift Mailer configuration.
26+
27+
In a standard Symfony installation, some ``swiftmailer`` configuration is
28+
already included:
3429

3530
.. configuration-block::
3631

3732
.. code-block:: yaml
3833
3934
# app/config/config.yml
4035
swiftmailer:
41-
transport: smtp
42-
encryption: ssl
43-
auth_mode: login
44-
host: smtp.gmail.com
45-
username: your_username
46-
password: your_password
36+
transport: "%mailer_transport%"
37+
host: "%mailer_host%"
38+
username: "%mailer_user%"
39+
password: "%mailer_password%"
4740
4841
.. code-block:: xml
4942
@@ -55,27 +48,24 @@ mandatory configuration parameter is ``transport``:
5548
-->
5649
5750
<swiftmailer:config
58-
transport="smtp"
59-
encryption="ssl"
60-
auth-mode="login"
61-
host="smtp.gmail.com"
62-
username="your_username"
63-
password="your_password" />
51+
transport="%mailer_transport%"
52+
host="%mailer_host%"
53+
username="%mailer_user%"
54+
password="%mailer_password%" />
6455
6556
.. code-block:: php
6657
6758
// app/config/config.php
6859
$container->loadFromExtension('swiftmailer', array(
69-
'transport' => "smtp",
70-
'encryption' => "ssl",
71-
'auth_mode' => "login",
72-
'host' => "smtp.gmail.com",
73-
'username' => "your_username",
74-
'password' => "your_password",
60+
'transport' => "%mailer_transport%",
61+
'host' => "%mailer_host%",
62+
'username' => "%mailer_user%",
63+
'password' => "%mailer_password%",
7564
));
7665
77-
The majority of the Swift Mailer configuration deals with how the messages
78-
themselves should be delivered.
66+
These values (e.g. ``%mailer_transport%``), are reading from the parameters
67+
that are set in the :ref:`parameters.yml <config-parameters.yml>` file. You
68+
can modify the values in that file, or set the values directly here.
7969

8070
The following configuration attributes are available:
8171

@@ -105,15 +95,27 @@ an email is pretty straightforward::
10595
{
10696
$mailer = $this->get('mailer');
10797
$message = $mailer->createMessage()
108-
->setSubject('Hello Email')
98+
->setSubject('You have Completed Registration!')
10999
->setFrom('[email protected]')
110100
->setTo('[email protected]')
111101
->setBody(
112102
$this->renderView(
113-
'HelloBundle:Hello:email.txt.twig',
103+
// app/Resources/views/Emails/registration.html.twig
104+
'Emails/registration.html.twig',
105+
array('name' => $name)
106+
),
107+
'text/html'
108+
)
109+
/*
110+
* If you also want to include a plaintext version of the message
111+
->addPart(
112+
$this->renderView(
113+
'Emails/registration.txt.twig',
114114
array('name' => $name)
115-
)
115+
),
116+
'text/plain'
116117
)
118+
*/
117119
;
118120
$mailer->send($message);
119121

@@ -138,3 +140,6 @@ of `Creating Messages`_ in great detail in its documentation.
138140

139141
.. _`Swift Mailer`: http://swiftmailer.org/
140142
.. _`Creating Messages`: http://swiftmailer.org/docs/messages.html
143+
.. _`Mandrill`: https://mandrill.com/
144+
.. _`SendGrid`: https://sendgrid.com/
145+
.. _`Amazon SES`: http://aws.amazon.com/ses/

0 commit comments

Comments
 (0)