Webhook PHP Script Examples

October 22, 2021

If you’re already familiar with Jotform Webhook, here are example scripts that you may want to try.

Note: Make sure to update the field names on these scripts with the field names from your form.

Instant Email Notification – Get Instant Email Notification Using Your Email Sending Server

//convert json data to php
$obj=json_decode($result, true);
//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;
//get html code after the body tag
foreach ($body->childNodesas$child){
    $html->appendChild($html->importNode($child, true));
//make the table responsive so it appears nicely on email
foreach ($bodyas$width) {
    $width->setAttribute(‘width’, ‘100%’);
//Send email
@mail($emailto, $subject, $body, $headers);

SMS Notification – Send SMS After Form Submission Using Your SMS Provider’s API

//Catch form field values
$obj=json_decode($result, true);
//Replace your authentication key & credentials
//Replace your form field names
$mobileNumber=$obj['q1_mobileNo']; //mobile no. from form data
$message=urlencode($obj['q2_message']); //message from form data
//Prepare you post parameters
//Replace your API endpoint
// init the resource
curl_setopt_array($ch, array(
//Ignore SSL certificate verification
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
//get response
//Print error if any

Code: http://pastebin.com/embed_iframe/0A558v0y

Form To MySQL – Send Form Data To Your MySQL Database

//Replace with your DB Details
//Create connection
$mysqli=new mysqli($servername, $username, $password, $dbname);
//Check connection
if ($mysqli->connect_error) {
    die("Connection failed: ".$mysqli->connect_error);
//Get field values from the form
//Get unique submissionID - nothing to change here
//Get form field values and decode - nothing to change here
$obj=json_decode($fieldvalues, true);
//Replace the field names from your form here
$result=$mysqli->query("SELECT * FROM $dbtable WHERE sid = '$sid'");
//If submission ID exist, update record
if ($result->num_rows>0) {
    $result=$mysqli->query("UPDATE $dbtable SET firstname = '$fname', lastname = '$lname', email = '$email', message = '$message' WHERE sid = '$sid'");
    echo"Existing Record Updated!";
//If new submission, insert record
    $result=$mysqli->query("INSERT IGNORE INTO $dbtable (sid, firstname, lastname, email, message) VALUES ('$sid', '$fname', '$lname','$email','$message')");
    echo"New Record Added!";
    if ($result===false) {echo"SQL error:".$mysqli->error;}

Bounce Notifier – Get Notified When Submission Failed To Be Sent Into Your Recipient Email

The following script will utilize your default web host SMTP to send emails. So make sure your web host supports this, otherwise, the mail function won’t work.

$jotformAPI=new JotForm("YOUR_JOTFORM_API_KEY_HERE");    // Put your API Key here
$history=$jotformAPI->getHistory("emails", "lastWeek");
$submissionURL='https://www.jotform.com/submission/'.$subid; //Construct submission URL
$limit=1; //send the last failed notification - increase the number if you have multiple notifications
//Your emails here
$to="johndoe@example.com"; //Replace with your recipient email
$from="paulsmith@example.com"; //Replace with your FROM email
//change the subject title if you like
$subject="View submission failed to be sent";
//Don't edit
$headers="MIME-Version: 1.0"."rn";
$headers.='From: <'.$from.'>'."rn";
//Additional body message here (optional)
$msg1="This submission has failed to be sent into your email.";
//New method, get data from the submissions page
$html=new DOMDocument;
//get html code after the body tag
foreach ($body->childNodesas$child){
    $html->appendChild($html->importNode($child, true));
//make the table responsive so it appears nicely on email
foreach ($bodyas$width) {
    $width->setAttribute('width', '100%');
//don't edit anything from here unless you know what you're doing
foreach ($historyas$key=>$value) {        
    if ($value['status'] =="IN BOUNCE/BLOCK LIST"||$value['status'] =="FAILED"&&$value['submissionID'] ==$subid){
        if ($key==$limit-1) {
            $body=    $msg1."<br>";
            @mail($to, $subject, $body, $headers);

We will post more examples from time to time. If you have any suggestions or if you need help with Webhook, feel free to 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.