Advertisement
jmdcoder

Email Status

Apr 8th, 2018
309
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.00 KB | None | 0 0
  1. <?php
  2. error_reporting(E_ALL & ~E_NOTICE);
  3.  
  4. //Needs JotForm API to be included
  5. include "jotform-api-php-master/JotForm.php";
  6.  
  7. //Put the API key here
  8. $jotformAPI = new JotForm("YOUR API HERE");
  9.  
  10. //Use getHistory of account, use parameter specific for emails
  11. $history = $jotformAPI->getHistory('emails','lastWeek','ASC');
  12.  
  13. //Get submission ID via POST
  14. $submissionID = $_POST['submission_id'];
  15. date_default_timezone_set('GMT');
  16.  
  17. //Download and require PHPMailer here
  18. require 'PHPMailer-master/PHPMailerAutoload.php';
  19.  
  20. //require 'PHPMailer-master/class.phpmailer.php';
  21. $mail = new PHPMailer();
  22. //$mail->SMTPDebug = 3;                               // Enable verbose debug output
  23. $mail->isSMTP();                                      // Set mailer to use SMTP
  24. //$mail->SMTPDebug = 1;
  25. $mail->Host = 'YOUR SMTP HOST';                       // Specify main and backup SMTP servers
  26. $mail->SMTPAuth = true;                               // Enable SMTP authentication
  27. $mail->Username = 'YOUR EMAIL';                       // SMTP username
  28. $mail->Password = 'YOUR PASSWORD';                    // SMTP password
  29. $mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
  30. $mail->Port = 587;                                    // TCP port to connect to
  31. $mail->SMTPOptions = array(
  32.     'ssl' => array(
  33.         'verify_peer' => false,
  34.         'verify_peer_name' => false,
  35.         'allow_self_signed' => true
  36.     )
  37. );
  38. $mail->setFrom('FROM EMAIL', 'Mailer');
  39. $mail->addAddress('RECIPIENT', '');                    // Add a recipient
  40. //$mail->addAddress('johnsmith@noemail.com');          // Name is optional
  41. //$mail->addReplyTo('info@noemail.com', 'Information');
  42. //$mail->addCC('cc@noemail.com');
  43. //$mail->addBCC('bcc@noemail.com');
  44. //$mail->addAttachment('/var/tmp/file.tar.gz');        // Add attachments
  45. //$mail->addAttachment('/tmp/image.jpg', 'new.jpg');   // Optional name
  46. $mail->isHTML(true);                                   // Set email format to HTML
  47. $mail->Subject = 'Email Status Check Notification';
  48. $mail->Body    = '<p>Email Notification Status: FAILED</p>';
  49. //$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
  50. ?>
  51.  
  52. <!DOCTYPE html>
  53. <html>
  54. <body>
  55.  
  56. <?php
  57. //PHP script for checking and outputting if the submission that was sent has failed email alert
  58. foreach($history as $result) {
  59.         $resultSubmissionID = $result['submissionID'];
  60.         if($submissionID == $resultSubmissionID) {
  61.             //Check if the status of the email alert failed, if it does, trigger PHPmail
  62.             if($result['status'] == "FAILED" || $result['status'] == "IN BOUNCE/BLOCK LIST") {
  63.  
  64.             //Can echo the output of the failed email alert here. Or create a thank you message here OR redirect a user to another link
  65.             echo "You can write the Thank You Message here.<br><br>";
  66.             echo 'Form ID: '.$result['formID'].'<br>';
  67.             echo 'Submission ID: '.$result['submissionID'].'<br>';
  68.             echo 'Provider: '.$result['provider'].'<br>';  
  69.             echo 'From: '.$result['from'].'<br>';
  70.             echo 'To: '.$result['to'].'<br>';
  71.             echo 'Status: '.$result['status'].'<br><br>';
  72.  
  73.             //Apend the details of the email alert that failed on this submission that will be sent to backup email
  74.             $mail->Body .= 'Form ID: '.$result['formID'].'<br>'
  75.                         .'Submission ID: '.$result['submissionID'].'<br>'
  76.                         .'Provider: '.$result['provider'].'<br>'
  77.                         .'From: '.$result['from'].'<br>'
  78.                         .'To: '.$result['to']
  79.                         .'<br>'.'Status: '.$result['status'].'<br><br>';
  80.        
  81.                 if(!$mail->send()) {
  82.                     echo 'Message could not be sent.<br>';
  83.                     echo 'Mailer Error: ' . $mail->ErrorInfo;
  84.                 } else {
  85.                     echo '<br>Email status checker has been sent.<br>';
  86.                 }
  87.         }
  88.     }
  89. }
  90. ?>
  91. </body>
  92. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement