On this page
Theming
Drupal 7 will no longer be supported after January 5, 2025. Learn more and find resources for Drupal 7 sites
All e-mails sent by the SwiftMailer module can be themed. This is useful when e-mails should reflect the look and feel of the website it was sent from. The Swift Mailer modules delegates theming to the Drupal theming system. This means that you can theme e-mails the same way you theme other content. The theme hook you need to use when interacting with the theming system is 'swiftmailer'.
Tip! You can set the theme which is to be responsible for theming e-mails through the mailsystem module. Simply go to admin/config/system/mailsystem and select the theme which is to be responsible for rendering e-mails.
Theme File
The easiest way to theme e-mails is to create a file named 'swiftmailer.tpl.php' in your theme folder. Please see section 2.1.1 for an overview of the variables you can use in the 'swiftmailer.tpl.php' file. The theme file should hold markup which wraps the actual content of the message. The below block of code demonstrates what a 'swiftmailer.tpl.php' might look like.
<div>
<?php print $body; ?>
</div>
Theme File Variables
This section is an overview of the basic variables that are available within the theme file 'swiftmailer.tpl.php'. Additional variables might be added by Drupal or other modules.
Tip! You can make even more variables available in 'swiftmailer.tpl.php' if you implement your own preprocess function. If you would like to make more variables available from a module you control, then you simply just need to implement the following preprocess function:
[yourmodule]_preprocess_swiftmailer(&$variables).
Similarly, if you want to make more variables available from your theme, then all you need is to implement the following preprocess function:
[yourtheme]_preprocess_swiftmailer(&$variables).
You can read more about which preprocess and process functions that are available form the 'swiftmailer' hook in the Drupal 7 documentation for the function theme().
- $key
- The key which identifies the e-mail. This is the $key provided to drupal_mail() which identifies the e-mail.
- $to
- The recipient's e-mail address.
- $from
- The sender's e-mail address.
- $language
- The language used to compose the e-mail.
- $params
- An array of parameters. This is the $params optionally provided to drupal_mail().
- $subject
- The subject.
- $body
- The actual content.
Help improve this page
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion