Skip to content

Instantly share code, notes, and snippets.

@isaumya
Created September 9, 2016 20:43
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save isaumya/70440b954389de08a2c5138ab3861ab0 to your computer and use it in GitHub Desktop.
Save isaumya/70440b954389de08a2c5138ab3861ab0 to your computer and use it in GitHub Desktop.
Attach files with Gravity Forms Notification Emails - Gravity Forms
<?php
//* Attaching file to the form notification user email
//* in gform_notification_7, the number 7 is the FORM ID
//* This snippet works with the newer version of Gravity Forms too
add_filter('gform_notification_7', 'add_attachment_pdf', 10, 3); //target form id 7, change to your form id
function add_attachment_pdf( $notification, $form, $entry ) {
//There is no concept of user notifications anymore, so we will need to target notifications based on other criteria,
//such as name or subject
if($notification["name"] == "User Notification - Life Lesson"){
//get upload root for WordPress
$upload = wp_upload_dir();
$upload_path = $upload["basedir"];
//add file, use full path , example -- $attachment = "C:\\xampp\\htdocs\\wpdev\\wp-content\\uploads\\test.txt"
$attachment = $upload_path . "/2016/08/some-file-name.pdf";
$notification["attachments"] = $attachment;
}
//return altered notification object
return $notification;
}
@jasimp
Copy link

jasimp commented Aug 29, 2021

how to give dynamic values as file names as different user need to get different files

@mrwweb
Copy link

mrwweb commented Sep 29, 2023

Thanks for sharing this, @isaumya. This is still working as of September 29, 2023.

Since site admins can change things like the notification name and subject, I'd recommend targeting the specific notification ID:

if( $notification['id'] === '7915ec2kj23d3' ) {
    // …attach the file…
}

For referenced, here's the current Gravity Forms documentations on this method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment