Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. <?php
  2. /******************************************************
  3.  
  4. Email Notification Script for Webhook using PHP's built-in Mail Function
  5. Elton - JotForm Support
  6. www.jotform.com
  7.  
  8. ******************************************************/
  9.  
  10. //convert json data to php
  11. $result = $_REQUEST['rawRequest'];
  12. $obj = json_decode($result, true);
  13.  
  14.  
  15. //Change with your emails
  16. $emailfrom = "[email protected]"; //Sender or From Email
  17. $emailto = "[email protected]"; //Recipient, you can predefine or use a field value e.g. $obj['q4_email']
  18. $subject = "You've got a new submission"; //Email Subject Title
  19.  
  20. //Do not edit
  21. $id = $_POST['submissionID']; //Get submission ID
  22. $submissionURL = 'https://www.jotform.com/submission/'.$id; //Construct submission URL
  23.  
  24. $headers = "From: " . $emailfrom . "\r\n";
  25. $headers .= "Reply-To: ". $emailfrom . "\r\n"; //Optional
  26. $headers .= "MIME-Version: 1.0\r\n";
  27. $headers .= "Content-Type: text/html; charset=utf-8\r\n";
  28.  
  29. //New method, get data from the submissions page
  30. $html = new DOMDocument;
  31. $html->loadHTML(file_get_contents($submissionURL));
  32. $body = $html->getElementsByTagName('body')->item(0);
  33. //get html code after the body tag
  34. foreach ($body->childNodes as $child){
  35.     $html->appendChild($html->importNode($child, true));
  36. }
  37. //make the table responsive so it appears nicely on email
  38. $body = $html->getElementsByTagName('table');
  39. foreach ($body as $width) {
  40.         $width->setAttribute('width', '100%');
  41. }
  42. $body = $html->saveHTML();
  43.  
  44. //Send email
  45. @mail($emailto, $subject, $body, $headers);
  46.  
  47. ?>