Closed (fixed)
Project:
Webform
Version:
6.x-3.11
Component:
Code
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
16 Jul 2007 at 09:40 UTC
Updated:
2 Oct 2012 at 18:38 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
quicksketchThis a feature enhancement, since webform can't currently do this and would require an amount of time to implement. I don't have any plans to implement such a feature, but patches would be gladly accepted.
Comment #2
Gentoo7 commentedI also would be interested in this feature. That uploaded files can be attached within the email.
I could maybe help out or trade for design work.
Comment #3
Gentoo7 commentedMaybe we can all add funds to pay someone to develop this feature. Im in with $25 USD. (to start)
Comment #4
yan commentedDefiniteley a feature I'd like to see!
Comment #5
ron collins commentedthis works for me in 2.2. watch that the file directory is writable. the directory location is set in the file component's configuration and defaults to something like sites/default/files/webform/
Comment #6
quicksketch@elraun, thanks for marking this fixed, but this feature request is not to include a link to the uploaded file, but actually to include the uploaded file itself in the e-mail as an attachment. As such, this feature is not yet implemented.
Comment #7
jrabeemer commentedSadly, I believe my client is going to ask me about this.. :-/
Comment #8
megabit81 commentedI would also be greatly interested an option to have uploaded files get attached to the email.
Comment #9
erifneerg commentedthis would be epic...
Comment #10
advseb commentedHas anyone found any workaround for that? Could I maybe do that with some custom scripting after submitting the form?
Comment #11
Anonymous (not verified) commentedHas anyone found a PHP command to place in the "webform-mail-[node id here].tpl.php" file? I have tried several commands to "get" the file but not sure how to workaround this...any ideas?
Comment #12
liren.zhu commentedFirst time posting on drupal.org, I wanted to share the solution I developed to overcome the same issue. Perhaps when I get some time, I'll create a patch to implement this solution better. I do believe that Webform module should simply have a check box for the File Upload field to easily enable this option.
This is a two part solution so follow closely:
Part 1: Modify the e-mail header
You want to modify the e-mail header so that the e-mail is interpreted to include attachments. To do this, copy the function theme_webform_mail_headers into your template.php file inside your theme. You'll need to rename the function name to override the default. Below is a bare bones version I've created for reference, feel free to modify for your needs. Note the version I am using attaches only one file for one upload field, but the codes below should allow you to have as many upload fields as you'd like.
Part 2: Editing the actual e-mail
The mail template file included with the Webform module is actually the e-mail being sent, so this is where you attach the file(s). Copy the webform-mail.tpl.php file from the Webform directory into your theme folder, and modify as needed.
Now remember to empty your cache once you complete these two steps. Hopefully I haven't made any typo and everything should work as planned. Let me know otherwise and I'll make adjustments.
P.S. You can also add to part 2 to include HTML e-mails, but that's another issue.
Comment #13
attiks commentedI created a patch that uses mimemail to send the attachments, but it look similar to the code above, be warned patch also includes code to resend a submission (see also #414294: Option to resend emails when submission is modified)
Comment #14
limeology commentedliren.zhu
This is an awesome piece of code, but I can't seem to get it to work correctly. I copied part 1 into my template file and renamed it from
function yourthemename_webform_mail_headers
to
function phptemplate_webform_mail_headers
Then I setup Part 2 by copying and pasting it in a duplicate of my webform-mail.tpl.php file. I want to style a particular webform with this ability, so I've given the filename webform-mail-195.tpl.php. It's in my theme folder.
What happens after I clear cache is that I get the form and can upload a file and fill out the form, but when I press submit, I just get a white screen like there's some type of error in the webform-mail file. Any advice? Thanks!
Comment #15
gregarios commentedSubscribing.
Comment #16
bomarmonk commentedI tried the patch in #13, and it seemed to apply cleanly (stripped some ending tags, or whatever, but no problems). The attachment, though, isn't sent with the e-mail. Do I have to do something else to get this to work? Thanks for any pointers!
Comment #17
quicksketchThis is still on my wish list for Webform, any patches adding this functionality to 3.x would be appreciated. No new features are being added to the 2.x version. From what I've seen of the patch in #13, I wouldn't really recommend it for production use (though if it works, that's great). @bomarmonk: Make sure you install the MIME Mail module, which is required for this functionality.
An additional not on this topic: now that we have HTML versions of our submissions it might be possible to use MIME mail to send HTML versions of the submissions too, which could be a nice bonus once we build integration with MIME mail.
Comment #18
bomarmonk commentedTrying mimemail with patch in #13: I get an error message on the confirmation page (after submitting the form) and the e-mail from the webform is not sent:
Maybe this is why the patch in #13 is not recommended? Still, if I can get it to work, I'll go with whatever is available and doesn't break anything.
Thanks again for your help!
Comment #19
attiks commented#18, my bad, I ran into the same problem and fixed it by changing line 244 in mimemail.inc to
Comment #20
attiks commented#16: do you get any errors, also look at my remark in #19
Comment #21
attiks commented#17: quicksketch, I wouldn't really recommend it for production use , can you elaborate, so i can make changes if necessary?
Comment #22
quicksketchThis is just a pretty bad hack:
Check if a value is serialized (or really starts with "a:") and then attach it as an e-mail? Just seems prone to error. Also won't work if File components are within fieldsets.
Comment #23
attiks commentedquicksketch, you're absolutely right, i did a quick copy and paste of the code in #12
i'll probably rewrite it for 3.x version, unless someone else is faster
Comment #24
bomarmonk commentedThank you for the help, but now I get this error (after replacing line 244 with your suggested code):
Again, I would like to get this working, even with a temporary hack, so any help is appreciated. Thank you!
Comment #25
attiks commented#24 can you double check to make sure you didn't make a typo, if not send me an email through my contact form and i'l send you a copy of my file
Comment #26
bomarmonk commentedI got rid of the error by adding another curly brace after 244, but the e-mail for the webform is not sent. So I'll take you up on your offer to send your file and I'll contact you by e-mail. Thanks!
Comment #27
bensey commentedHi, subscribing to this. Attachments would be a great feature to the webform module...
Has anyone got these solutions working yet? I've installed mimemail and played with the webform template etc. as above, and can get the attachments encoded and sent with the form, but there is something wrong with the header format and they're just a lot of mess at the end of the mail.
Cheers.
Comment #28
liren.zhu commented@limeology,
Sorry, I haven't checked back in a while.
It seems like an issue with the template.php file, I don't see anything with the mail formatting portion that would cause a wsod. Thought, without going into your code and debugging it, I can't really tell you for sure what it is, but I have a small suggestion that may work:
If your theme is called "thisIsMyTheme" rename the function yourthemename_webform_mail_headers to "thisIsMyTheme_webform_mail_headers" without the quotations.
I can't remember if there's any difference between phptemplate_ and themename_ inside template.php file but it's worth a try.
But do understand that this is, for the most part, a pretty poor hack, but it does get the job done short of going deep into Drupal and the Webform module. Maybe once I get more time, I'll revisit this issue. Let me know if this works out, otherwise feel free to contact me and I'll be glad to help you.
Comment #29
bensey commentedFinally sorted this! This can be made to work well using the two pieces of code from #12 and the patching from #13.
The problems that have had me tearing out my hair out for weeks turned out to be caused by attachment fields contained inside fieldsets.
They stuffed the whole process, there was no confirmation message after submit and empty emails arrived.
Move the attachments out of the fieldset and everything works nicely...
If someone has any suggestions how to fix this, that would be great, I'm a bit of a PHP nuffy but like things grouped on webforms...
Hope this helps some of you...
Comment #30
h l commentedThe suggestion from liren.zhu in comment #12 works for me well.
Very thanks!!
Comment #31
mbasfour commentedhi
i need this feature for the 3.0 version of web form module and i need the file to be send as an attachment
without being uploaded on the server .
Comment #32
liren.zhu commentedI got a question yesterday about how to send files as an attachment in 3.0, so here's the solution I came up with.
Note this is a quick solution, definitely not the most elegant one; I wouldn't try to patch this into the webform module itself. Regardless, I've tested this with webform 6.x-3.0-beta6 and it works without modifying the module itself.
Same as last time, this comes in two parts:
Part 1: Modify the e-mail header
You need to modify template.php to change the e-mail header when there are attachments. Copy the function theme_webform_mail_headers (from webform.module) into your template.php file and modify it. Don't forget to replace "theme_" in the function name with "yourthemename_" where yourthemename is the name of the theme you're using.
Part 2: Editing the actual e-mail
Again, the mail template file (webform-mail.tpl.php) is included with the module, so copy it into your theme folder and modify it to include the attachments.
Clear your cache, and it should work. Please forgive me if there are any typos.
Comment #33
liren.zhu commented#31:
Got your email, see my post above to send files as attachments with webform 6.x-3.0-beta6. Not sure it'll work when it gets updated out of beta6.
As for your other issue of having the file not uploaded to the server, that's a little tricky:
1) What happens to the rest of the webform submission?
a) If you keep that data, it's a bit problematic to not have anything in the file fields. I mean...why have the fields at all?
b) If you don't care about the data. You're probably better off looking into another module or just coding the whole thing yourself.
Comment #34
quicksketchWe're merging this with #698494: HTML Email Template Functionality (MIME mail support), which adds support for MIME Mail module, including attachments.
Comment #35
mattwhelan commented#32
In the line declaring Content-Type for the attachment in the email, $attachments is plural when I think it needs to be singular. I was having trouble with Yahoo! inboxes reading the attachment and changing that seemed to take care of the problem for me (worked in Gmail even when the Mime Type was omitted).
Comment #36
CraigCamm commentedAll of my headers are being output into the email body after implementing this. Any ideas why?
"
--b690c2d41e1100be61f1602cd42d4e16 Content-Type: text/plain;
charset=ISO-8859-1 1042 - Submitted on Thursday, October 21, 2010 - 10:55
normal body text
--b690c2d41e1100be61f1602cd42d4e16 Content-Type: application/msword;
name=errors.doc Content-Disposition: attachment; filename=errors.doc
Content-Transfer-Encoding: base64
Y2NhbW1hcmF0YUBtZXJyeW10Zy5jb20KCk9yaWdpbmFsIEVycm9yOgoKdXNlciB3YXJuaW5nOiBZ
b3UgaGF2ZSBhbiBlcnJvciBpbiB5b3VyIFNRTCBzeW50YXg7IGNoZWNrIHRoZSBtYW51YWwgdGhh
dCBjb3JyZXNwb25kcyB0byB5b3VyIE15U1FMIHNlcnZlciB2ZXJzaW9uIGZvciB0aGUgcmlnaHQg
c3ludGF4IHRvIHVzZSBuZWFyICdMSU1JVCAwLCAxJyBhdCBsaW5lIDEgcXVlcnk6IFNFTEVDVCBm
LmZpbGVuYW1lLCBmLmZpbGVwYXRoLCBmLmZpbGVtaW1lIEZST00gZmlsZXMgZiBXSEVSRSBmLmZp
ZCA9IExJTUlUIDAsIDEgaW4gL2hvbWUvY2MubXRzem9uZS5jb20vZG9tYWlucy9mcm9udGllcmFk
anVzdGVycy5jYy5tdHN6b25lLmNvbS9wdWJsaWNfaHRtbC9zaXRlcy9hbGwvdGhlbWVzL3RoZWlu
.......
"
Comment #37
liren.zhu commentedMost likely caused by changes from 6.x-3.0-beta6 to 6.x-3.4
Comment #38
Bencio commentedI had the same problem, solved changing the email format from text to html in Webform general settings
Comment #39
pfahlr commentedIf you happen to be on an older version of mimemail (< alpha3) and are using the patch in #13, you'll want to see http://drupal.org/node/358439
Comment #40
Dret commentedI tryed the code here: http://drupal.org/node/159678#comment-3279336
But an error appear related to this part of code in template.php
Error is:
I'm using webform 2.x
Thanks bye!
Comment #41
liren.zhu commentedSince you're using 2.x, try comment #12
Comment #42
mbasfour commentedi suggest you update to the latest version of this module it has a native support for attachments
it uses mime type module to support attachments in email
Comment #43
berliner commentedSorry to reopen this, but from looking at the code I get the impression, that attachments only work, if mimemail is used. Any reasons for this? What about cases, where I just want to send a plain text mail, but with attachments included? Technically there should be no need for mimemail.
Comment #44
quicksketchSending attachments, even with plain-text e-mails, still requires special encoding of the e-mail data. Since MIME Mail handles this, Webform utilizes it's existing code to handle attachments. When using MIME Mail and Webform together you have separation options for "Send this e-mail as HTML" and "Include uploaded files at attachments". You can use one or the other, or both.
I don't have any interest in rewriting the encoding provided by MIME Mail, since a lot of users want both HTML and attachments, it'd be rather silly of us not to use that module for both purposes. If you have further questions, please open a new issue.
Comment #45
laevensv@gmail.com commented"When using MIME Mail and Webform together you have separation options for "Send this e-mail as HTML" and "Include uploaded files at attachments". You can use one or the other, or both."
Where are those options ?
Thank you for your help
>> no further help needed, i've found it in the options, when adding an email. :)
Comment #46
sagar ramgade commentedHi All,
I am using webform-6.x-3.11 with mimemail-6.x-1.0-beta1, for me attachments were not working. So after searching found that there is a bug in the module and patch has been submitted. I used the patch given in this comment http://drupal.org/node/1162112#comment-4516628, worked like a charm. Hope this might help all who are struggling.
Regards
Sagar
Comment #47
yesct commentedThe status of this issue sounds like using webform with minemail (the newest versions) should work. But I couldn't get an attachment to the node to be emailed by checking the attachment checkbox. Please see #1262096: Attachments: Handbook page on using mimemail with webform to send emails with files as attachments. I'd like to write down instructions on how to get sending a file to work.
Comment #48
attiks commented@YesCT by attachment you mean file upload in the webform, if so than try the patch in #46
if you mean with attachment a file you added in edit mode, than this will not work
Please open a new issue if the problem persists and reference it here
Comment #49
lurkerX commentedThank you so much for this solution liren.zhu!
In #32 did find a typo that can be an issue for some email clients when there is no file field in the webform (such as where you have more than one webform on a site).
In part 1 you have:
if ($item['type'] = 'file') {Should be:
if ($item['type'] == 'file') {So that the condition is not always true. Otherwise, for forms without file fields, improperly formated emails will be generated that some email clients will not render.
Comment #50
santoshm29 commentedi m new todrupal CMS. I created contact us form using html script. this form has to send email to specific email id (used hidden fields to store email address). typical web site contact form. don't know where to paste above php code. please help