PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Attach File to Email Notification (rather than including a url)

  1. bhagman88
    Member

    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.

    Posted 12 years ago on Saturday July 21, 2012 | Permalink
  2. David Peralty

    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.

    Posted 12 years ago on Saturday July 21, 2012 | Permalink
  3. bhagman88
    Member

    Thanks!

    Posted 12 years ago on Monday July 23, 2012 | Permalink
  4. 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?

    Posted 12 years ago on Thursday August 2, 2012 | Permalink
  5. David Peralty

    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?

    Posted 12 years ago on Thursday August 2, 2012 | Permalink
  6. 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 =)

    Posted 12 years ago on Thursday August 2, 2012 | Permalink
  7. David Peralty

    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.

    Posted 12 years ago on Thursday August 2, 2012 | Permalink
  8. 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

    Posted 12 years ago on Thursday August 2, 2012 | Permalink
  9. David Peralty

    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?

    Posted 12 years ago on Thursday August 2, 2012 | Permalink
  10. 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

    Posted 12 years ago on Thursday August 2, 2012 | Permalink
  11. 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.

    Posted 12 years ago on Friday August 31, 2012 | Permalink
  12. David Peralty

    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.

    Posted 12 years ago on Friday August 31, 2012 | Permalink
  13. David Peralty

    985 - can you please post your functions.php file so I can take a look?

    Posted 12 years ago on Friday August 31, 2012 | Permalink
  14. 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;
    }
    
    /* ---------------------------------------------------------------- */

    http://pastebin.com/EFGyPhxx

    Posted 12 years ago on Friday August 31, 2012 | Permalink
  15. David Peralty

    Actsoft you want to use the admin attachments hook. Change user to admin in your code.

    Posted 12 years ago on Friday August 31, 2012 | Permalink
  16. THANK YOU for this! Glad that worked ...

    Posted 12 years ago on Friday August 31, 2012 | Permalink
  17. Thank you for the update.

    Posted 12 years ago on Sunday September 2, 2012 | Permalink

This topic has been resolved and has been closed to new replies.