Tutorial: Fax from PHP

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 step-by-step guide will enable you to get started sending faxes from PHP using the InterFAX internet fax XML web service.

Requirements

  • A web server running PHP 5 or higher.
  • FTP or direct access to the server for uploading scripts.

Steps

1. Determine your version of PHP.

  • Create a file called info.php an enter the following contents:
<?php
echo phpinfo();
?>
  • Upload the file to your server, then access the script from a browser. For example, if your server's web root is /htdocs/ and your faxing scripts reside in /htdocs/fax/, you would access the script by entering the following into your address bar: http://www.yoursite.com/fax/info.php.

The result page will look something like the following image and will show your server's version of PHP:

2. Install/verify your SOAP library

In PHP version 5 and higher SOAP should be installed by default. To verify that your installed version of PHP has SOAP enabled, run the above info.php script again and search for a section that looks like this:

If this section exists, you do not need to do anything further. If it doesn't exist, you will need to recompile PHP with the SOAP library activated.

3. Register for an InterFAX developer account

Register as a developer. When registering you will need to provide a designated fax number, at which you will receive test faxes that you send through InterFAX. With a developer account you can ONLY fax to this one number.

4. Create your faxing script

  • Create a new file which will be your main faxing script, let's call it faxsample1.php.

  • Copy the following code into your file:


<?php

/**************** Settings begin **************/

$username = ''; // Enter your Interfax username here
$password = ''; // Enter your Interfax password here
$faxnumber = ''; // Enter your designated fax number here in the format +[country code][area code][fax number], for example: +12125554874
$texttofax = 'My text goes here'; // Enter your fax contents here
$filetype = 'TXT'; // If $texttofax is regular text, enter TXT here. If $texttofax is HTML enter HTML here

/**************** Settings end ****************/

$client = new SoapClient("http://ws.interfax.net/dfs.asmx?wsdl");

$params->Username  = $username;
$params->Password  = $password;
$params->FaxNumber = $faxnumber;
$params->Data      = $texttofax;
$params->FileType  = $filetype;

$faxResult = $client->SendCharFax($params);

print_r($faxResult);
?>
  • Replace the variables in the "Settings" section. Note that the $faxnumber variable MUST be the same number that you designated when you registered as a developer.

Upload this script to your server's faxing script directory, e.g. /htdocs/fax/.

5. Test your faxing script

Point your browser to the location of your script, e.g. http://www.yoursite.com/fax/faxsample1.php.

After a few seconds, you should receive a reply that includes text like [SendCharFaxResult] => 32266956, possibly surrounded by other stuff. The number returned is your fax's transaction ID on the InterFAX system. This reply indicates that your web service call has been successfully received on the InterFAX system and that InterFAX will now start processing your fax. It does NOT indicate that your fax has been sent. Any result other than a positive number indicates an error, see the following link for possible error codes.

6. View the status of your fax

Login to your InterFAX account at https://secure.interfax.net/Default.aspx. Once you've logged in, click the "Outbound Queues" subnavigation link. Your fax should be visible as an entry in the table.

The status of your fax goes through several states, chronologically: Preprocessing, Ready, Sending, OK/Error. These are visible as icons in the outbound fax queue. Hover over the icon to view a toolbar tip of the status.

If all goes well, your fax should be received at your designated fax number within a minute or two. CONGRATULATIONS!

7. Learn more

InterFAX offers a variety of options for sending your faxes and retrieving status. To learn more about these capabilities, see the Outbound Web Service Reference, PHP Faxing Samples, and the Developer FAQ. If you have any questions, feel free to ask them here or to contact developer support.

8. Go live

Once you have finished development and wish to be able to fax to any number, simply follow the instructions under question number 7 in the Interfax Developer FAQ.


Questions or comments on this tutorial? Post them in the developer forum.

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