You are here: Home > Developer API > Fax Web Service > Code Samples > PHP Samples > Fax one or more files to one or more recipients with SendfaxEx_2
PHP Faxing Samples
- Tutorial: Fax from PHP
- Send a simple ASCII-text fax using SendCharFax
- Send one file attachment (e.g., PDF, DOC, HTML) to one recipient with Sendfax
- Fax one or more files to one or more recipients with SendfaxEx_2
- Get information about one or more submitted faxes with FaxStatusEx
- Get information about one or more submitted faxes with FaxQuery
- Get information about one or more submitted faxes with FaxQuery2
- Retrieve the image of a submitted fax with GetFaxImageResult
- Cancel a pending fax with CancelFax
- Inbound: get list of inbound faxes using GetList
- Inbound: retrieve a received fax using GetImageChunk
- Deprecated Samples
Fax one or more files to one or more recipients with SendfaxEx_2
This sample demonstrates how to send one or more attached files with 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("http://ws.interfax.net/dfs.asmx?wsdl"); // Use this version of SoapClient instantiation if tracing the SOAP call: // $client = new SoapClient("http://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"; ?>