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.

Use pre-selected file as user notification attachment

  1. I'd like to use the new User Notification Attachment feature to automatically send a file to anyone who submits their email address through my form.

    The instructions for using this hook show how to attach a file when that file was uploaded through the original form. (http://www.gravityhelp.com/documentation/page/Gform_user_notification_attachments)

    In my case, I'd like to set up my form so that when they send me their email address (which is the only form field), the user notification gets sent out with a pre-defined file attached to it. That file would be located in my WordPress uploads folder.

    Unfortunately, I'm not a programmer so trying to customize the code is beyond my skillset.

    Can anyone show me how to customize the code shown in the link below so that it attaches a specific file (or even files) instead of requiring the files to be uploaded with the form?
    http://www.gravityhelp.com/documentation/page/Gform_user_notification_attachments

    Thanks so much!

    Posted 12 years ago on Monday March 12, 2012 | Permalink
  2. The following code snippet should point you in the right direction. Place it in your theme's function.php file.
    http://pastie.org/3580604

    Posted 12 years ago on Monday March 12, 2012 | Permalink
  3. Fantastic! Thanks so much for the quick reply. I'll try this out and report back if I have any trouble getting it to work.

    Posted 12 years ago on Monday March 12, 2012 | Permalink
  4. Hi,

    I tried using the code you sent but the form is not attaching my file to the user notification email. The user notification email goes out, but there's no file attached.

    Here's my demo page:
    http://archwebmarketing.com/nice-to-meet-you-2/

    Below is the code I added to my functions.php file (the form I'm using is ID 2). Any help would be greatly apprceiated!

    add_filter("gform_user_notification_attachments_2", "add_attachment", 10, 3);
    function add_attachment($attachments, $lead, $form){

    //getting wordpress upload folder
    $upload = wp_upload_dir();
    $upload_path = $upload["path"];

    $attachments = array();

    //add a file from the uploads folder
    $attachments[] = $upload_path . "/2012/JenniferFeurer.vcf";

    return $attachments;

    }

    Posted 12 years ago on Thursday March 22, 2012 | Permalink
  5. Hi

    I think I am in the same situation. If I paste that code (changing the file, of course), it gives me a syntax error and site is broken.

    I need to include a pdf file in the automatic response sent to users that fill in a given form on our site. So the response comes with some text blah blah and the pdf attached.

    That'd save us tons of time of manually replying to users with the pdf. We can't give a link, we need to collect the emails, and the link can be easily shared.

    Thanks a lot, as usual!

    Posted 12 years ago on Monday March 26, 2012 | Permalink
  6. jonny
    Member

    Hi - same as JenF:

    add_filter("gform_user_notification_attachments_6", "add_attachment", 10, 3);
    function add_attachment($attachments, $lead, $form){
    //getting wordpress upload folder
    $upload = wp_upload_dir();
    $upload_path = $upload["path"];
    $attachments = array();
    //add a file from the uploads folder
    $attachments[] = $upload_path . "/2012/03/Easy-Quote-16032012.xlsx";
    return $attachments;
    }

    The user notification mail is sent but no attachment:

    Posted 12 years ago on Tuesday March 27, 2012 | Permalink
  7. jonny
    Member

    bumping post - alex, have you had any further ideas as to why that code might not work?

    thanks,

    Jon.

    Posted 12 years ago on Thursday March 29, 2012 | Permalink
  8. Sorry. There was a small problem with the code I posted earlier. Here it is again (this time it should work)

    add_filter("gform_user_notification_attachments", "add_attachment", 10, 3);
    function add_attachment($attachments, $lead, $form){
    
        //getting wordpress upload folder
        $upload = wp_upload_dir();
        $upload_path = $upload["basedir"];
    
        $attachments = array();
    
        //add a file from the uploads folder
        $attachments[] = $upload_path . "/my_file.jpg";
    
        return $attachments;
    }
    Posted 12 years ago on Thursday March 29, 2012 | Permalink
  9. Alex: so beautifully working on our sites!!
    Thanks guys, you rock!

    E.

    Posted 12 years ago on Friday March 30, 2012 | Permalink
  10. jonny
    Member

    Great stuff, Alex, thank you - that works perfectly :o)

    Posted 12 years ago on Friday March 30, 2012 | Permalink

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