PHP Fax – send one or more files to one or more recipients with SendfaxEx_2
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.
This sample demonstrates how to send a fax using PHP, with one or more attached files, using the method SendfaxEx_2.
<?php
/**************** Settings begin **************/
$username = ''; // Insert your InterFAX username here
$password = ''; // Insert your InterFAX password here
$faxnumbers = '+12077301111;+492077301222;+442077301333'; // semicolon-
// delimited list of destination fax numbers
$contacts = 'Rachel Burns;Albie Eins;Max Planck'; // optional semicolon-
// delimited list of recipient names; one per fax number
$files = array('test.pdf', 'test.html'); // List of files to fax
// These files need to be resident on the file system
$postponetime = '2001-12-31T00:00:00-00:00';
$retries = '3';
$csid = 'AA CSID';
$pageheader = 'To: {To} From: {From} Pages: {TotalPages}';
$subject = 'Anything goes';
$replyemail = '';
$page_size = 'A4';
$page_orientation = 'Portrait';
$high_resolution = FALSE;
$fine_rendering = TRUE;
/**************** Settings end ****************/
$filetypes = '';
$data = '';
$filesizes = '';
// Open files and determine file types from extension
foreach ($files as $filename){
$filetype_exploded_array = explode('.', $filename);
$filetype = $filetype_exploded_array[count($filetype_exploded_array) - 1];
$filetypes .= $filetype . ';';
if(!($fp = fopen($filename, "r"))){
// Error opening file
// Handle error however appropriate for your script
echo "Error opening file";
exit;
}
// Read data from the file into $data
$filedata = "";
while (!feof($fp)) $filedata .= fread($fp,1024);
$filesizes .= strlen($filedata) . ';';
$data .= $filedata;
fclose($fp);
}
$filetypes = trim($filetypes, ';');
$filesizes = trim($filesizes, ';');
// Call WS method
$client = new SoapClient("https://ws.interfax.net/dfs.asmx?wsdl");
// Use this version of SoapClient instantiation if tracing the SOAP call:
// $client = new SoapClient("https://ws.interfax.net/dfs.asmx?wsdl", array('trace' => 1));
$params->Username = $username;
$params->Password = $password;
$params->FaxNumbers = $faxnumbers;
$params->Contacts = $contacts;
$params->FilesData = $data;
$params->FileTypes = $filetypes;
$params->FileSizes = $filesizes;
$params->Postpone = $postponetime;
$params->RetriesToPerform = $retries;
$params->CSID = $csid;
$params->PageHeader = $pageheader;
$params->JobID = '';
$params->Subject = $subject;
$params->ReplyAddress = $replyemail;
$params->PageSize = $page_size;
$params->PageOrientation = $page_orientation;
$params->IsHighResolution = $high_resolution;
$params->IsFineRendering = $fine_rendering;
$result = $client->SendfaxEx_2($params);
echo $result->SendfaxEx_2Result;
// Use the following line to trace the SOAP call
// Requires using the 'trace' version of SoapClient instantiation above
// echo "REQUEST:\n" . $client->__getLastRequest() . "\n";
?>