Customising the emails sent by webform
There are 2 ways of customizing the emails that you can get webform to send when a user submits a form:
- use the built-in email templating interface
- use a webform email template in your theme directory
Using the built-in email templating interface
This is the easiest way of customising the emails that webform sends.
- Go to the Webform --> E-mails screen for the webform in question.
- Either use the Edit link for an existing email recipient or Add a new recipient. This should get you to the Edit e-mail settings screen.
- Scroll down to the E-mail template settings. Change the Default template to a Custom template. Modify the composition of the email, editing the text as desired. Use any of the Tokens listed under "Token values" to add in the variable data you might need. %email_values is the simplest way of getting all the values entered by the user into the email. You can easily include or exclude the value of a specific component by checking or unchecking the relevant component under "Included e-mail values".
- Click Save e-mail settings at the bottom of the page and that's basically it.
Using a webform email template
For greater control over the content of the email, you can use a template in your site's theme directory.
- Copy the default webform-mail.tpl.php template (usually found in sites/all/modules/webform/templates/) to your site's theme directory. If you prefer to test the modified webform template from the admin interface, be sure to add it to your site's admin theme directory as well.
- Clear the theme registry (e.g. by clearing caches on the Settings/Performance screen, or using devel module) so that the new template is picked up (you need to do this every time you add or remove a template, but not when you modify an existing template).
- Edit the template to suit your needs. There are instructions and suggestions in THEMING.txt and in the supplied webform-mail.tpl.php. Note that that putting
print_r($submission);in the template file is a very handy way of finding out some of the available variables. Note: if you copied the template to your admin theme as well, then be sure to include the changes in that template file as well. - Note that the output from webform-mail.tpl.php is subject to %-token substitution. If your template produces output from user-submitted data in $submission, it may be possible for users to inject %-token strings into form fields that might reveal data you would rather keep hidden (e.g. %value[some_form_field]). To avoid this, include the %email_values token in your template, and put your email message theme code in webform-submission.tpl.php instead like this:
if (isset($email)) { // Code to generate email message ... } else { // behave like default webform-submission.tpl.php print drupal_render($renderable); } - You can have a global template for all webforms, and/or have different templates for particular webforms, as described in the instructions.
- In order to use the template you have created, you must set the webform's E-mail template setting to Default on the Edit e-mail settings screen.
Technical note about using email template files: when you select the Default template on the Edit e-mail settings screen, the text area underneath shows the currently active webform mail template (either the default supplied with webform, or one from your theme folder, or the relevant webform-mail-[nid].tpl.php from your theme folder) after PHP processing but before token substitution. Any changes you make to the template file will show up immediately when you refresh the Edit e-mail settings screen, assuming that your changes modify the result of running your template through PHP. (This isn't always the case - for example, you won't be able to see the result of code that only runs for Anonymous users.)
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