How do I attach a pdf file to a Gravity Forms Notification?

前提是你 提交于 2019-12-11 08:18:12

问题


Gravity forms offers a way to attach files from the file uploader (See code below), but how would I change this code to simply attach my own PDF file from either a hidden field value or simply paste the pdf file within this code? I tried a few things but it didn't work. Any help would be appreciated!

 add_filter( 'gform_notification', 'change_user_notification_attachments', 10, 3 );
 function change_user_notification_attachments( $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
if ( $notification['name'] == 'User Notification' ) {

    $fileupload_fields = GFCommon::get_fields_by_type( $form, array( 'fileupload' ) );

    if(!is_array($fileupload_fields))
        return $notification;

    $attachments = array();
    $upload_root = RGFormsModel::get_upload_root();
    foreach( $fileupload_fields as $field ) {
        $url = $entry[ $field['id'] ];
        $attachment = preg_replace( '|^(.*?)/gravity_forms/|', $upload_root, $url );
        if ( $attachment ) {
            $attachments[] = $attachment;
        }
    }

    $notification['attachments'] = $attachments;

}

return $notification;
  }

回答1:


Based on that code, something like this should work. Replace the $url value with the URL to your PDF.

add_filter( 'gform_notification', 'change_user_notification_attachments', 10, 3 );
function change_user_notification_attachments( $notification, $form, $entry ) {

    if ( $notification['name'] == 'User Notification' ) {
        $url = 'http://yoursite.com/path/to/file.pdf';
        $notification['attachments'] = array( $url );
    }

    return $notification;
}


来源:https://stackoverflow.com/questions/39260420/how-do-i-attach-a-pdf-file-to-a-gravity-forms-notification

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!