Sending files with Incoming Webhook

Hi,

I have created an incoming webhook which creates a entry in GF, currently I am sending over user data which isn’t a problem but sometimes a file will need to be attached and sent then accessed from WP.

On my PHP script I have created the JSON which is sent over and added the attachment to this but I am not sure how this is going to send it, I hope that makes sense?

Below is my PHP variable encoding into JSON which is then sent to GF Incoming webhook via CURL.

$json_data = json_encode([
    // Message
    'emailSubject' => $emailSubject,
    'emailHtml' => $emailHtml,
    'emailMessageId' => $emailMessageId,
    'emailToAddress' => $emailToAddress,
    'emailFromAddress' => $emailFromAddress,
    'emailReplyToAddress' => $emailReplyToAddress,
    'emailSenderAddress' => $emailSenderAddress,
    'emailRecent' => $emailRecent,
    'emailUnseen' => $emailUnseen,
    'emailFlagged' => $emailFlagged,
    'emailMailDate' => $emailMailDate,
    'emailSize' => $emailSize,
    'attachment_1' => $attachments[0]['filename']
    

], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE );

Hi Tom. If your form uses a file upload field for single files (not multi-file) you can base64_encode the file and send it like this:

'attachment_1' => base64_encode( file_get_contents( $attachments[0]['filename'] ),

filename here needs to be the full path to the file on the server.

If you have any other questions, please let us know.

Hi Chris,

Fantastic thank you very much, I will give that a go.

Much appreciated.

Tom

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.