I was wondering if it's possible for Gravity Forms to include a file (submitted via the form) as an attachment in an email rather than embedding a link to the item in the body of the email. I would like to avoid keeping these files on our servers.
I was wondering if it's possible for Gravity Forms to include a file (submitted via the form) as an attachment in an email rather than embedding a link to the item in the body of the email. I would like to avoid keeping these files on our servers.
Hi,
I think what you are looking for are the following hooks:
http://www.gravityhelp.com/documentation/page/Gform_user_notification_attachments
http://www.gravityhelp.com/documentation/page/Gform_admin_notification_attachments
These will let you include attachments.
Thanks!
I tried the usage of this in my functions.php file and its giving me a 500 error on save.. Using the latest version of GF and WP 3.2.1
Any ideas?
I would have to see the exact 500 error to understand why you are getting this, and not that it should matter to the functions.php file, but is there any reason you aren't upgraded to WordPress 3.4.1?
It's a white screen error.
HTTP Error 500 (Internal Server Error): An unexpected condition was encountered while the server was attempting to fulfill the request.
Error log shows:
[Thu Aug 02 10:37:14 2012] [error] [client 108.12.138.144] client denied by server configuration: /home2/dbrock/public_html/wp-content/uploads/gravity_forms/2-116e88a54c96a3cac96a00f10c181e70/2012/07
We haven't upgraded because the sites been working fine, no security issues and a lot of customization. The database is enormous; and they get about 1000 inquiries a month, so didn't want to touch anything, "don't fix what's not broken" with my luck it usually causes problems =)
You will want to send that error to your web host. After doing a quick search, I got the following:
http://www.cyberciti.biz/faq/httpd-client-denied-by-server-configuration/
Basically, Gravity Forms puts files there to be able to then grab then for e-mails and whatnot. So if your server won't let the file be grabbed, then it fails.
I had the webhost edit the file and change the settings as per the site you sent.
I'm still getting a 500 error/white screen, this time error log says..
[Thu Aug 02 13:39:02 2012] [error] [client 96.57.25.218] PHP Parse error: syntax error, unexpected '<' in /home2/dbrock/public_html/wp-content/themes/DBIStaffing/functions.php on line 28
Looks like your theme's function file might have an issue in it on line 28. Can you post it on pastebin or something similar so we can take a look?
I fixed the issue, not paying attention and left the <php in..
but now i have the code in and im getting this error when forms are submitted. Attachment arent attached.
[Thu Aug 02 16:42:53 2012] [error] [client 69.115.20.95] PHP Warning: call_user_func_array() [function.call-user-func-array]: First argument is expected to be a valid callback, 'add_attachment' was given in /home2/dbrock/public_html/wp-includes/plugin.php on line 170, referer: http://www.dbistaffing.com/submit-form/?job_title=Technical%20Writer&job_id=1859&job_email=Sheron@DBIStaffing.com
Can we get some clarity on this post? I can't seem to make this work either and it's very frustrating. This should be a checkbox in the module config, not a manual code entry in functions.php.
My situation: I have a form for people to submit resume for careers page. Notification goes to HR, but link isn't downloadable for them (permissions) so I just want to attach to the notification email. I copy and pasted exactly from:
http://www.gravityhelp.com/documentation/page/Gform_user_notification_attachments
add_filter("gform_user_notification_attachments", "add_attachment", 10, 3);
function add_attachment($attachments, $lead, $form){
$fileupload_fields = GFCommon::get_fields_by_type($form, array("fileupload"));
if(!is_array($fileupload_fields))
return $attachments;
$attachments = array();
$upload_root = RGFormsModel::get_upload_root();
foreach($fileupload_fields as $field){
$url = $lead[$field["id"]];
$attachment = preg_replace('|^(.*?)/gravity_forms/|', $upload_root, $url);
if($attachment){
$attachments[] = $attachment;
}
}
return $attachments;
}
What part of this do I need to customize? The common.php file was little help.
In your notifications, the email that goes to hr, is it the admin notification or the user notification? Because you might just have the hook wrong. We have one for admin notifications and one for user notifications.
985 - can you please post your functions.php file so I can take a look?
Relevant screenshot: http://www.actsoft.com/wp-content/uploads/2012/08/gravity-forms.jpg
/* ---------------------------------------------------------------- */
/* Include Form Attachments in Notification Emails */
/* ---------------------------------------------------------------- */
add_filter("gform_user_notification_attachments", "add_attachment", 10, 3);
function add_attachment($attachments, $lead, $form){
$fileupload_fields = GFCommon::get_fields_by_type($form, array("fileupload"));
if(!is_array($fileupload_fields))
return $attachments;
$attachments = array();
$upload_root = RGFormsModel::get_upload_root();
foreach($fileupload_fields as $field){
$url = $lead[$field["id"]];
$attachment = preg_replace('|^(.*?)/gravity_forms/|', $upload_root, $url);
if($attachment){
$attachments[] = $attachment;
}
}
return $attachments;
}
/* ---------------------------------------------------------------- */
Actsoft you want to use the admin attachments hook. Change user to admin in your code.
THANK YOU for this! Glad that worked ...
Thank you for the update.