Hi,

I created a webform to collect subscriber name and email address. As soon as the user fills the form, I would like to send them a PDF attachment in the confirmation email. The PDF file is not something user is uploading. I tried adding the attachment in the mail.tpl file by modifying email['attachment'] variable but I believe I am not doing it right. Is this possible? Can someone please give me some hints on doing this? I am using webform 7.x-3.18.

Thanks!

Comments

quicksketch’s picture

quicksketch’s picture

Sorry I meant http://drupal.org/project/webform2pdf. http://drupal.org/project/fillpdf would probably also work.

It's possible to also do this through hook_mail_alter() in a custom module, but that's beyond the scope of the Webform issue queue.

abuzakaria’s picture

Status: Active » Closed (fixed)

Thanks for the hint for using hook_mail_alter in my custom module. That's really helpful for what I am trying to do. The other modules you listed actually generates PDF from the submission results. But I actually have to send an already existing PDF that resides in the Drupal files folder.

Once again ... Thanks!

jiakomo’s picture

@abuzakaria,
it would be nice to know how you solved this, as I am trying to achieve something similar.

jphelan’s picture

This can be done with rules. You just need the following modules:
http://drupal.org/project/mimemail (Be sure to also enable Mime Mail Action)
http://drupal.org/project/rules
http://drupal.org/project/webform_rules

Then create a new rule for "After a webform has been submitted"
Add the "Select a webform" as a condition and select your webform
Then select the mimemail "Send an HTML mail to an arbitrary mail address" action NOT the system "Send a mail to an arbitrary mail address"

You can then use tokens to send the email to an address the user submits in the form. Add your attachments in your attachments box and your all set to go.

I did it in D6 but it all of the modules have a 7.x version so it should be the same or similar in D7.

jphelan’s picture

Also if anonymous users are submitting the form they need the "send arbitrary files" permission or the attachment won't be sent.

abuzakaria’s picture

I used the mail_alter hook with to achieve this.
NOTE: you will have to modify some of the hard coded parameters if you use this code.

function fla_custom_mail_alter(&$message) {
	if ($message['id'] == 'webform_submission' && $message['params']['email']['eid'] == 2){
		$message['params']['attachments'][] = (array) file_load($message['params']['submission']->data[6]['value'][0]);
		$message['params']['attachments'][0]['filepath'] = $message['params']['attachments'][0]['uri'];
	} 
}
tostinni’s picture

Thank you abuzakaria for this snippet, also this should be used in conjunction with mimemail module as Drupal can't send attachment without it.

johhan’s picture

Issue summary: View changes

Regard #7:
Trying in D7, but non of the mentioned names matches, mainly in constructing the rule. Some unfathomable "The form id of the submitted form" is required. As well as "A key to identify the e-mail sent."

So, can anybody clear the steps for D7 & Webform 3 ?

Thank you very much

jphelan’s picture

I have a step by step article on it here
http://justinphelan.com/post/add-attachment-drupal-webform-confirmation-...

"A key to identify the e-mail sent." Can be anything you want, it's not important in this situation.