Add an attachment to a Drupal Webform confirmation email

This is not how to include user submit files on a webform as attachments on an email, although mimemail will allow you to do that too. But rather the ability to send a single attachment to everyone who submits a specific webform. For instance, perhaps people are signing up for an event and they need to print off and sign a release form to bring with them and you want to send them a pdf as an attachment to a webform confirmation email.

I've done this in both Drupal 6 and 7 and it's pretty similar. We'll be assuming your on Drupal 7 for this article but I'll try and note any differences for 6.

You'll need to install these modules. (Be sure to also enable the Mime Mail Action sub module) (Not necessary for D6)

First step is to create a new rule and set it to fire After a webform has been submitted

Add a new condition Webform has name (Select a webform in D6). Change the form id to data selection which should default to form_id. (You wont have to worry about form_id in D6). Then select the webform(s) you want send the confirmation email to.

Next add a Send HTML e-mail action (D6 is Send an HTML mail to an arbitrary mail address). You can then use the replacement patterns to send it to the users submitted email address. [data:FIELD-value] where FIELD is the webform component's Field Key which can be found by editing the component. 

Fill in all the other options and at the bottom you can include the path to one or more files to be included as attachments. In D6 you need to format it like this mimetype:path, so for our PDF it would look something like this application/pdf:sites/default/files/test.pdf

Once you are done your rule should look something like this.

Go submit your webform and you should receive your beautiful HTML email with an attachment!

Other Notes:

  1. In Drupal 6 you need to give anonymous users the send arbitrary files permission in order for the attachment to be sent to them when they submit a form.
  2. Be sure in your mimemail setting you have a text format is selected that allows HTML
Justin Phelan

Hi, I'm Justin Phelan. I'm a web developer at Blackwood Media Group and I've been working with Drupal since 2006. My goal here is simply to share some of the tips and tricks I've learned along the way. I'm by no means an expert but I hope I can help a few folks out. Feel free to contact me with questions or suggestions.

Drupal Association Member