How to Setup a Webhook with Jotform

September 15, 2021

What is a Webhook?

A webhook is a technique used to send HTTP POST notifications to a URL. They can be used to connect apps together or just send data – read more.

  1. Open your form in the form builder and click on the settings tab, go to the integrations section and search WebHooks or filler the result in the dropdown with “Other”.
    WebHooks Integration

    WebHooks Integration

  2. Add your WebHook URL.
    WebHook URL

To inspect or debug a webhook request, you can use RequestBin. Simply create a Request Bin and set the endpoint URL in your form’s webhook (as seen in the screenshot on step 2). Make an actual submission to your form and then check the collected data on Request Bin.

782×481 jpeg
33.9 kB

Request Bin Endpoint

Example:

Request Bin Sample Output

Request Bin Sample Output

Here’s an example PHP script that you may want to try on Webhook. This is a simple mailer script that will send the form submissions data to your email through Webhook.


//convert json data to php
$result = $_REQUEST[‘rawRequest’];
$obj = json_decode($resulttrue);

//Change with your emails
$emailfrom = “john@example.com”//Sender or From Email
$emailto = “paul@example.com”//Recipient, you can predefine or use a field value e.g. $obj[‘q4_email’]
$subject = “You’ve got a new submission”//Email Subject Title

//Do not edit
$id = $_POST[‘submissionID’]; //Get submission ID
$submissionURL = ‘https://www.jotform.com/submission/’.$id//Construct submission URL

$headers = “From: “ . $emailfrom . rn;
$headers .= “Reply-To: “. $emailfrom . rn//Optional
$headers .= “MIME-Version: 1.0rn;
$headers .= “Content-Type: text/html; charset=utf-8rn;

//New method, get data from the submissions page
$html = new DOMDocument;
$html->loadHTML(file_get_contents($submissionURL));
$body = $html->getElementsByTagName(‘body’)->item(0);

//get html code after the body tag
foreach ($body->childNodes as $child){
    $html->appendChild($html->importNode($childtrue));
}

//make the table responsive so it appears nicely on email
$body = $html->getElementsByTagName(‘table’);
foreach ($body as $width) {
    $width->setAttribute(‘width’‘100%’);
}
$body = $html->saveHTML();

//Send email
@mail($emailto$subject$body$headers);
?>

Code: https://pastebin.com/raw/AmG72bve.

Make sure to replace the field names and emails with the ones from your form, you can also add fields if you prefer.

You can find more useful scripts here: Webhook PHP Script Examples.

If you have questions, post it below.

Was this guide helpful?
Contact Support:

Our customer support team is available 24/7 and our average response time is between one to two hours.
Our team can be contacted via:

Support Forum: https://www.jotform.com/answers/

Contact Jotform Support: https://www.jotform.com/contact/

Send Comment:

Jotform Avatar
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Comments: