PHP4: How to fax a binary file
25 Nov 2016 This code sample is deprecated and in process of being removed. Check out our new code libraries and usage documentation on InterFAX @ Github.
Faxing a binary file with PHP4
With thanks to Justin Horn from Justechnology, LLC
<?
/**
* Send a Fax using PHP/PEAR::SOAP Example:
* - Using SendfaxEx() Method from InterFax Web Services
*/
/**
* Your variables go here - assign a value to each one
*/
$username = "";
$password = "";
$faxnumber = ""; // formatted like +13055551234, i.e. +(country code)(area code)(phone number)
$file = ""; // binary file to fax
$filetype = ""; //e.g. HTML, DOC, PDF, etc.; see documentation for complete list
$postponetime = ""; //e.g. 2001-04-25T20:31:00-04:00, use a past date/time to fax immediately
$resolution = ""; // 0 for standard, 1 for fine
$csid = ""; // your fax identifier, visible on the receiving machine's little screen
$subject = ""; // for your reference, visible in the outbound queue
$replyemail = ""; //optional address at which to receive an emailed confirmation
/**
* PEAR::SOAP class [https://pear.php.net/package/SOAP]
*/
require_once 'SOAP/Client.php';
// Open File
if( !($fp = fopen($file, "r")))
{
// Error opening file
// Handle error how it is appropriate for your script
exit;
}
// Read data from the file into $data
$data = "";
while (!feof($fp)) $data .= fread($fp,1024);
// URL path to InterFax Web Services
$wsdl_url = 'https://ws.interfax.net/dfs.asmx?wsdl';
// Create an instance of the SOAP_WSDL class
$WSDL = new SOAP_WSDL($wsdl_url);
/**
* This function creates a proxy to the SOAP services
* so that you can access the InterFax methods directly
* as if you were calling a local function
*/
$client = $WSDL->getProxy();
/**
* Invoke the InterFax SendfaxEx Method
* NOTE: 'base64_encode' is a native method in PHP [https://www.php.net/manual/en/function.base64-encode.php]
*/
$result = $client->SendfaxEx($username, $password, $faxnumber, base64_encode($data), $filetype, strlen($data), $postponetime, $resolution, $csid, $subject, $replyemail);
// Echo Result
if($result > 0) echo "Fax submitted. Transaction ID: $result";
else echo "Error sending fax. Return code: $result";
?>