# Attachments to mail in function \[RESOLVED\]

**URL:** <https://community.gravityforms.com/t/attachments-to-mail-in-function-resolved/5885>\
**Category:** Get Help\
**Tags:** gform\_notification\
**Created:** [August 25, 2020, 3:49pm UTC](https://community.gravityforms.com/t/attachments-to-mail-in-function-resolved/5885 "2020-08-25T15:49:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![AgenceKN](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/agencekn/32/1950_2.png) [@AgenceKN](https://community.gravityforms.com/u/AgenceKN)\
**Post date:** [August 25, 2020, 3:49pm UTC](https://community.gravityforms.com/t/attachments-to-mail-in-function-resolved/5885/1 "2020-08-25T15:49:40Z")

</div>

Hello Everybody !

I’ve been struggeling for a while with a form and need your help !  
I try to add attachments in function.php.

Here is my code :

```auto
    add_filter( 'gform_notification_5', 'rw_notification_attachments', 10, 3 );
function rw_notification_attachments( $notification, $form, $entry ) {
    $log = 'rw_notification_attachments() - ';

 
    if ( $notification['name'] == 'AKN' ) {

        $url = rgar( $entry, '7' );
        
       
                $uploaded_files = json_decode( stripslashes( $url ), true );
                 $attachment = array();
                foreach ( $uploaded_files as $uploaded_file ) {
                    
                    $attachment[] = $uploaded_file ;
                    $notification['message'] .= $uploaded_file;
                    $notification['message'] .= '<br>';
                    
                }
                $notification['attachments'] = $attachment;
         $notification['enableAttachments'] = 1;        
    }

    return $notification;}

```

As you can see, I’ve also added the files links into the message. They are correctly displayed in the email recieved.  
The filed 7 value is json :  
[“[https://www.serpinet-conseil.com/wp-content/uploads/gravity\_forms/Plan\_Paris\_Mutiburo\_Tour\_Horloge.pdf",“https://www.serpinet-conseil.com/wp-content/uploads/gravity\_forms/BDA.zip”,"https://www.serpinet-conseil.com/wp-content/uploads/gravity\_forms/CD.zip](https://www.serpinet-conseil.com/wp-content/uploads/gravity_forms/Plan_Paris_Mutiburo_Tour_Horloge.pdf%22,%22https://www.serpinet-conseil.com/wp-content/uploads/gravity_forms/BDA.zip%22,%22https://www.serpinet-conseil.com/wp-content/uploads/gravity_forms/CD.zip)”]

Thanks !

---

<div class="post-metadata">

**Author:** ![AgenceKN](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/agencekn/32/1950_2.png) [@AgenceKN](https://community.gravityforms.com/u/AgenceKN)\
**Post date:** [August 25, 2020, 4:00pm UTC](https://community.gravityforms.com/t/attachments-to-mail-in-function-resolved/5885/2 "2020-08-25T16:00:06Z")

</div>

Ok found the error 🙂

```
if ( $notification['name'] == 'AKN' ) {

        $url = rgar( $entry, '7' );
    
   
            $uploaded_files = json_decode( stripslashes( $url ), true );
             $attachment = array();
             $upload_root = RGFormsModel::get_upload_root();
             
            foreach ( $uploaded_files as $uploaded_file ) {
                $attachment = preg_replace( '|^(.*?)/gravity_forms/|', $upload_root, $uploaded_file );
                $notification['attachments'][] = $attachment;

                
            }
          
     $notification['enableAttachments'] = 1;        
}
```

---

<div class="post-metadata">

**Author:** ![chrishajer](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/chrishajer/32/88_2.png) [@chrishajer](https://community.gravityforms.com/u/chrishajer)\
**Post date:** [August 25, 2020, 5:38pm UTC](https://community.gravityforms.com/t/attachments-to-mail-in-function-resolved/5885/3 "2020-08-25T17:38:50Z")

</div>


