-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Quick proofread of the email cookbook #4918
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,43 +7,36 @@ How to Send an Email | |
Sending emails is a classic task for any web application and one that has | ||
special complications and potential pitfalls. Instead of recreating the wheel, | ||
one solution to send emails is to use the SwiftmailerBundle, which leverages | ||
the power of the `Swift Mailer`_ library. | ||
|
||
.. note:: | ||
|
||
Don't forget to enable the bundle in your kernel before using it:: | ||
|
||
public function registerBundles() | ||
{ | ||
$bundles = array( | ||
// ... | ||
|
||
new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(), | ||
); | ||
|
||
// ... | ||
} | ||
the power of the `Swift Mailer`_ library. This bundles comes with the Symfony | ||
Standard Edition. | ||
|
||
.. _swift-mailer-configuration: | ||
|
||
Configuration | ||
------------- | ||
|
||
Before using Swift Mailer, be sure to include its configuration. The only | ||
mandatory configuration parameter is ``transport``: | ||
To use Swift Mailer, you'll need to configure it for your mail server. | ||
|
||
.. tip:: | ||
|
||
Instead of setting up/using your own mail server, you may want to use | ||
a hosted mail provider such as `Mandrill`_, `SendGrid`_, `Amazon SES`_ | ||
or others. These give you an SMTP server, username and password (sometimes | ||
called keys) that can be used with the Swift Mailer configuration. | ||
|
||
In a standard Symfony installation, some ``swiftmailer`` configuration is | ||
already included: | ||
|
||
.. configuration-block:: | ||
|
||
.. code-block:: yaml | ||
|
||
# app/config/config.yml | ||
swiftmailer: | ||
transport: smtp | ||
encryption: ssl | ||
auth_mode: login | ||
host: smtp.gmail.com | ||
username: your_username | ||
password: your_password | ||
transport: "%mailer_transport%" | ||
host: "%mailer_host%" | ||
username: "%mailer_user%" | ||
password: "%mailer_password%" | ||
|
||
.. code-block:: xml | ||
|
||
|
@@ -55,27 +48,24 @@ mandatory configuration parameter is ``transport``: | |
--> | ||
|
||
<swiftmailer:config | ||
transport="smtp" | ||
encryption="ssl" | ||
auth-mode="login" | ||
host="smtp.gmail.com" | ||
username="your_username" | ||
password="your_password" /> | ||
transport="%mailer_transport%" | ||
host="%mailer_host%" | ||
username="%mailer_user%" | ||
password="%mailer_password%" /> | ||
|
||
.. code-block:: php | ||
|
||
// app/config/config.php | ||
$container->loadFromExtension('swiftmailer', array( | ||
'transport' => "smtp", | ||
'encryption' => "ssl", | ||
'auth_mode' => "login", | ||
'host' => "smtp.gmail.com", | ||
'username' => "your_username", | ||
'password' => "your_password", | ||
'transport' => "%mailer_transport%", | ||
'host' => "%mailer_host%", | ||
'username' => "%mailer_user%", | ||
'password' => "%mailer_password%", | ||
)); | ||
|
||
The majority of the Swift Mailer configuration deals with how the messages | ||
themselves should be delivered. | ||
These values (e.g. ``%mailer_transport%``), are reading from the parameters | ||
that are set in the :ref:`parameters.yml <config-parameters.yml>` file. You | ||
can modify the values in that file, or set the values directly here. | ||
|
||
The following configuration attributes are available: | ||
|
||
|
@@ -105,15 +95,27 @@ an email is pretty straightforward:: | |
{ | ||
$mailer = $this->get('mailer'); | ||
$message = $mailer->createMessage() | ||
->setSubject('Hello Email') | ||
->setSubject('You have Completed Registration!') | ||
->setFrom('[email protected]') | ||
->setTo('[email protected]') | ||
->setBody( | ||
$this->renderView( | ||
'HelloBundle:Hello:email.txt.twig', | ||
// app/Resources/views/Emails/registration.html.twig | ||
'Emails/registration.html.twig', | ||
array('name' => $name) | ||
), | ||
'text/html' | ||
) | ||
/* | ||
* If you also want to include a plaintext version of the message | ||
->addPart( | ||
$this->renderView( | ||
'Emails/registration.txt.twig', | ||
array('name' => $name) | ||
) | ||
), | ||
'text/plain' | ||
) | ||
*/ | ||
; | ||
$mailer->send($message); | ||
|
||
|
@@ -138,3 +140,6 @@ of `Creating Messages`_ in great detail in its documentation. | |
|
||
.. _`Swift Mailer`: http://swiftmailer.org/ | ||
.. _`Creating Messages`: http://swiftmailer.org/docs/messages.html | ||
.. _`Mandrill`: https://mandrill.com/ | ||
.. _`SendGrid`: https://sendgrid.com/ | ||
.. _`Amazon SES`: http://aws.amazon.com/ses/ |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bundle