This page may contain affiliate links. Please read my disclaimer for more information.

Attaching a File to Your Gravity Forms Notifications

  |  by Chris Eggleston

In this scenario, let’s say you’re using a Gravity Forms form on your website as an optin, collecting emails in exchange for an ebook. No need to fuss with an email marking system, get your users their ebook as soon as they click submit!

This is a very simple solution, that is easy to setup and easy to use. I’ll provide everything you need in this very detailed, step-by-step tutorial.

Rather use a plugin? Don’t want to mess with code? Checkout this solution: Notification Attachments for Gravity Forms Plugin Review (code free method)

These are a few benefits to this solution:

  1. The ebook file does not need to be stored in your media library
  2. You do not have to provide a download link
  3. You do not have to use an email marketing service (i.e Mailchimp)
  4. You only need one plugin

This is What You’ll Need

That’s it! Like I said, this is a simple solution.

If you do not have a Gravity Forms license, please head on over to gravityforms.com/pricing to get yours so that you can download the plugin, it is required for this to work ;-).

Alright, now this tutorial starts off with the assumption that you already have Gravity Forms installed and activated. If you are not sure how to do that, please refer to the video here.

Step 1: Creating your form

If you have already created your form, feel free to skip to the next step in this tutorial.

  1. Got to Forms => Add New
  2. Name Your Form “Free eBook Optin”
  3. Click ‘Create Form’
  4. Add Your Fields:
    • Name
    • Email
  5. Click Update
creating form

Step 2: Setting up your notifications

By default, when you create your form, Gravity Forms will automatically create an admin notification, which is set to send you an email every time the form is submitted.

In this scenario, we need to add a notification to send the ebook to the subscriber. This step walks you through setting up a new notification. You can edit the admin notification if you’d like, however I will not be covering that in this tutorial.

  1. Go to Settings => Notifications
  2. Click ‘Add New’
  1. Name your notification “User Notification”
  2. Send To use ‘Select a Field’
  3. From the ‘Send To Field’ dropdown select ‘Email’
  4. From Name: Put your name
  5. From Email: Use your domain email (i.e chris@wpmantis.com)
  6. Subject: “Your copy of Book Name is inside!”
  7. Message: Create a custom message, you can use merge tags to pull in the users name and any other information you collected through the form.
  8. Click ‘Update Notification’
  1. Make sure your new notification is Active

Step 3: Adding the form to a page

There are a couple ways to add your form to a page depending on which version of the WordPress page editor you use or if you use a third party page builder.

In this tutorial, I will only be showing you how to add the form to your page with the WordPress Block Editor. However, if you need to know how to add your form to a page with the Classic Editor click here.

If you are using a third party page builder like Elementor, I highly recommend using the Essential Addons plugin, you’ll be glad you did!

  1. Edit or Add your page
  2. Click the + icon
  3. Click the Gravity block
  4. Select your form
  5. Update or Publish your page

Step 4: Implementing the code

There are three different parts in this step. You will need to install the Code Snippets plugin, copy the code below, past it into the plugin, make a couple modifications and done!

Part 1: Install the Code Snippets plugin

  1. Go to Plugins => Add New
  2. Search for Code Snippets
  3. Click Install
  4. Click Activate

Part 2: Adding the code to your site

You will need to copy and past this code into the plugin you just installed.

  1. Copy the code above
  2. Go to Snippets => Add New
  3. Title you snippet “Ebook Attachment”
  4. Past the code in the ‘Code’ area
  5. Click ‘Save Changes’

Part 3: Modifying the code

  1. Replace 1 in the gform_notification_1 line, with your form ID
  2. Change ‘User Notification’ to the name of your notification (if you named your notification something different)
  3. Add the path to your file
  4. Click Save Changes and Activate

Step 5: Testing. Always Test!

This is an important step that so many people leave out, do NOT skip this step! You want to make sure it is working before you start driving traffic to your optin form.

To test this, go to the page you embedded your form on, fill out the form, and click submit.

If you get an email with the attachment you know it worked! Well done!

If you do NOT get an email, or if the email does not have an attachment, below are a few common causes.

  1. Your file path is invalid
  2. Didn’t change the ID number in the code
  3. Entered the wrong ID number
  4. Didn’t change the notification name
  5. Entered the wrong notification name
  6. You’re email was entered wrong
  7. You’re checking the wrong email address

If after checking the recommended items above, this is still not working, please use the chat or comments below for additional help.

Optional: Using a third party SMTP service

To improve the deliverability of you notifications, especially if you use a cheap hosting service like GoDaddy or Bluehost, you may want to consider using an SMTP service provider.

When you use one of these third party solution, you bypass your hosting services email servers and instead your emails are sent through one of these third party mail servers.

Gravity Forms integrates nicely with a couple of these services by providing add-ons available with any license.

While I recommend using one of these services above, there are several others to choose from and there are several WordPress plugins available for integrating with these and the other SMTP service providers.

Optional: Integration with an email marketing service

I already mentioned that you do not need to use an email marketing service, however, if you’d like to have these new subscribers added to a list in your email marketing account you can easily do that with Gravity Forms and several platforms.

This is a list of official integrations provided by Gravity Forms:

If you are interested in learning how to integrate Gravity Forms with an email service provider, you can watch this video tutorial, How to Create a Mailchimp Signup Form, to learn how it works.

The Wrap Up

By now I hope you see the power in this simple solution. With this you can do more to power your online business without the need for another plugin or another platform, all you need is Gravity Forms.

Subscribe to our blog for more articles like this and if you need additional help, please use the comments below.

Photo of author
About the Author
Chris Eggleston
Chris is not just a Gravity Forms enthusiast; he's a dedicated father and loving husband. As the proud owner of WP Mantis, he's on a mission to simplify the WordPress experience for site owners. He brings a unique perspective to the Gravity Forms community.

Advertisement

0 0 votes
Article Rating
Subscribe
Notify of
guest

7 Comments
Inline Feedbacks
View all comments
Paul
Paul
1 year ago

This is awesome. Is there a way to set the $path to the value of a hidden field on the form?

Andreas
Andreas
1 year ago

What if I the file to attach is located on a remote URL and not in the same server?
If I simply change
$path = ‘path/to/file.pdf’;
with
$path = ‘https://cdn.myexternalserver.com/the_attached_file.pdf’;
it doesn’t work.

Thanks a lot!

Spencer
Spencer
1 year ago

Very good tutorial and including all the reasons to check if it’s not working. Thanks!!

Garo
2 years ago

Hey mate, awesome! Worked first time.

Trying to add it to another form with the exact same attachment. Did everything the same but its giving me this error?

The snippet has been deactivated due to an error on line 8:

Cannot redeclare function add_notification_attachments.

No idea why?

Garo
Garo
Reply to  Chris Eggleston
2 years ago

ah ok, so you mean add it to the single instance of the working function. So just add that filter above and make the notification as the other GF 🙂 correct?

Guillaume
Guillaume
2 years ago

This is brillant. and works perfectly. Thank you so much Chris. Real life savier.

If someone is looking at this and have various attachments depending on the notification, just copy/paste the IF paragraph in the same snippet (and edit the name of the notification and the path to the file of course) Works perfectly as well.
Thanks again !