PHP Fax - Send a fax and check its status

This is a more advanced PHP code sample to show how to send a fax and then check the status of a fax that was submitted until the status indicates that the fax has been completed. This code sample is based on the PHP library for InterFAX available on Github.

This sample demonstrates how to send a fax with a PDF through InterFAX to a single recipient and then loop through checking the status of that fax until processing of the fax is completed in InterFAX - all you need to do in order to change it is to provide a different fax destination number and a path to a file.
A fax in InterFAX is completed when either the fax was sent successfully to the recipient (in which case, the fax status would be "0") or all of the call attempts for this fax have been completed and the fax was not sent fully (in which case the fax status would be > 0).

  
     $fax = $interfax->deliver([
  'faxNumber' => '+11111111112',
  'file' => 'path/to/fax.pdf'
]);

// wait for the fax to send
// successfully
while(true) {
  // reload the fax data
  $fax = $fax->refresh();
  // sleep if pending
  if ($fax->status < 0) {
    sleep(10);
  } else {
    if ($fax->status == 0) {
      print "Sent!";
    } else {
      print "Error: ".$fax->status;
    }
    break;
  }
}

  

The status of the fax is only one of several parameters that you can retrieve in regards to a fax. For a full list, please review our API documentation.

Contact us today

Talk to a member of our team about the benefits InterFAX can bring to your organization's communications processes.

Contact us today