Created
September 9, 2016 20:43
-
-
Save isaumya/70440b954389de08a2c5138ab3861ab0 to your computer and use it in GitHub Desktop.
Attach files with Gravity Forms Notification Emails - Gravity Forms
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
} |
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
how to give dynamic values as file names as different user need to get different files