PHP eFax
|
Welcome to the PHP eFax documentation.
What is eFax? eFax is a company that let's you send and receive faxes via the Internet (see http://www.efax.com). The faxes can be sent to a standard paper fax or to a virtual fax machine (i.e. to your eFax account.) There are two interfaces:
(1) an email interface used to send and receive documents from a set of standard email addresses.
(2) a secure HTTPS API called eFax Developer or business eFax. It can be used in a totally automated way to send and receive faxes via a web interface using the standard HTTPS protocol for communication.
At Made to Order Software, we use eFax for Order Made! Our easy to use ordering system for restaurants. https://secure.m2osw.com/resto/system/list.php
To use the eFax class, create an eFax object and either set the parameter to send a fax, or parse the disposition message. That's it! The rest of the work is handled internally by the class.
The source code for this class is available for sale on our http://www.m2osw.com website.
Click on Products at the top, search for PHP eFax, and add it to your cart. Then simply go through our checkout process. A few seconds after we receive your payment, you will gain access to the download area where you will be able to download the PHP eFax package.
If you already purchased a license then you have an account with us and you can simply go back to your account and download a new copy of the library. If you forgot your password, then use the request new password form to be sent a link to your email address. That link will let you enter a new password for your account. The license is permanent so you do not have to re-purchase a new license to re-download a copy of the library.
Up to version 1.5, the class requires the availability of HttpRequest. Below are information on how to install HttpRequest on your server.
Since version 1.6, HttpRequest is optional. You may instead use the accompanying http_request class. To do so, create the eFax object passing false as the optional parameter.
new eFax(false)
when creating an eFax object instead of using the HttpRequest class from PEAR.For a Microsoft Windows system, you can find pre-compiled versions of the HttpRequest module, called php_http.dll at the following URL:
http://pecl4win.php.net/list.php
Please, make sure that the version is correct for your system. The home page for the PECL code for Windows is at PECL4WIN.
A good tutorial for IIS and even Unix users on how to install HttpRequest can be found on IIS Aid.
new eFax(false)
when creating an eFax object instead of using the HttpRequest class from PEAR.If it is not already installed on your Debian system (this also works under Ubuntu) use the following commands to retrieve and recompile a version on your system:
Then edit your /etc/php/apache2/php.ini file and add the following line at the end:
new eFax(false)
when creating an eFax object instead of using the HttpRequest class from PEAR.For Fedora, RedHat and other RPM based systems, use yum
instead of apt-get
. The pecl command is the same.
The php-xml is to get the DOMDocument support.
Once the HTTP Request module installed, add the following at the end of your /etc/php.ini file:
The following code shows how you create an eFax object, initializes it to send a fax and finally eFax::send()
the fax.
The parameters are only examples. You will need to set the parameters to what you need for your specific needs.
Whenever you receive the fax disposition message from eFax, call the eFax::parse_disposition()
function with the XML data included in the message. Then you can use different get functions to retrieve the resulting information.
The disposition is sent by eFax once the fax was successfully sent or a failure was discovered. It is sent to your server using the disposition URL you specified when sending the fax to the eFax server. In our example it is set using the eFax::set_disposition_url() function as follow:
The following is an example of fax-disposition.php code:
Whenever you receive a fax from a sender, eFax Developer posts a notification to a URL you specify in your eFax Developer account. This HTTP POST message includes an XML file that PHP eFax can parse for you. See the eFax::parse_inbound_message()
function for additional information.
After the call to the parse function you can use different get functions to retrieve the inbound fax information.
Inbound requests are sent to the URL you define in your eFax Developer account. At that URL, you must have a PHP file that includes what follows:
In eFax, there are several built in security features.
The main feature is that it only works with an SSL connection. This clearly means secure! The only drawback is that you need a valid certificate in order to send and receive faxes with your system.
The second feature is the login and password. These are passed in the XML data. The one drawback with these is that they are written in clear in the XML data. In other words, anyone can read them if they somehow intercept your message (but remember, on the Internet the message is encrypted and thus no one can read the login and password.)
Similarly, whenever you create an XML file to be sent to eFax Developer, you need to incorporate the login and password in clear in that XML document. So watch out and consider saving that information in a protected place on your hard disk. A place only accessible to the part of your application dealing with the sending and receiving of faxes.
Another less obvious security feature is the use of the XML format. That ensures a strong structure preventing many invalid requests. For instance, for inbound messages, we check a certain number of entries that need to be valid for the request to be accepted as an eFax Developer request. This part is handled by the eFax class so you do not have to worry about it.
Whenever you receive an eFax failure such as "Your request failed due to invalid data" you need to check out your eFax object setup and the data that you are sending. I suggest you try sending documents that you trust are correct (was created with genuine tools.) If those fail too, then there is another problem. Note that at first you probably want to try sending a text file. These are the easiest to test with. Only make sure your lines are about 80 characters wide because eFax does not reformat your documents.
The debugging is somewhat difficult because eFax Developer does not give you much info about what goes right and what goes wrong. Note, however, that they keep a copy of the outbound response on their server. So if somehow you do not get that response, you can at least see what they were going to tell you.
The main reason why you would not receive the response is because you did not specify a URL with the HTTPS scheme (secure). Or because your certificate cannot be verified by eFax Developer. In most cases, if you can verify your certificate with your browser and it does not give you an error, then eFax Developer will have no problem with it.
Note that some eFax errors will not happen. For instance, the "Account identifier argument was not passed" error is prevented by the eFax class, which checks that you specified the identifier before it forwards the XML packet to the eFax Developer server.
Other failures are possible. For instance, the fax number may not be valid.
Internally, the eFax class automatically retries sending your document up to 5 times when an error occurs. In most cases, this is used when the connection to the eFax server fails (times out.) If after 5 times it cannot connect and send the fax to the eFax Developer server, then it returns with false
. In this case, you will NOT get any other error from eFax Developer since they do not even know you wanted to contact them. Failure to connect happen often at times when they receive a large number of faxes simultaneously. It is frequent that you have to try to connect a second or third time. It never happened to us that the communication would not happen with 5 attempts. For this reason, the count is hard coded in the send()
function. Feel free to increase it if you get that problem once in a while.
new eFax(false)
the http_request detects errors that it reports with a different exception. This allows the system to avoid waiting a long time when a fatal error happens. You may want to catch errors of type http_request_exception to make sure that your software does not just fail on those errors. In most cases those will happen at time of development and if something goes wrong.Most functions throw an eFaxException when an error occurs.
Exceptions are raised if some parameter was not yet defined and you try to create the message to send a fax and when calling the eFax::send()
function.
Also, exceptions are raised if the user name or password were not defined before calling the eFax::parse_disposition()
or eFax::parse_inbound_message()
.
Similarly, exceptions are raised if calling one of the get functions before eFax::parse_disposition()
or eFax::parse_inbound_message()
were called.
Notice that calling eFax::set_fax_id()
does NOT set the fax identifier of the disposition. In other words, calling eFax::get_result_fax_id()
after eFax::set_fax_id()
without calling eFax::parse_disposition()
or eFax::parse_inbound_message()
still generates an exception.
Although it should not be necessary, since no exceptions should ever occur when the eFax class is properly used, it is possible to catch the eFaxException in this way:
Note that the new http_request class may throw the http_request_exception. If raised, these exceptions will reach your software. Some are like the eFaxException: they only happen when a parameter is invalid and fixing your code will fix the problem. Others would happen in the event an invalid reply was sent by the eFax server. So neither should be raised, although to strengthen your code you probably want to catch these exceptions, just in case. These will only happen when you call the eFax::send() function so you may just protect that one call:
Note that the HttpRequest also throws some exceptions. Please read the HttpRequest reference manual for more information.
http://www.php.net/manual/en/class.httprequest.php
According to the documentation of the send() function the following exceptions may be raised by the library:
Note that the eFax::send() function already catches the HttpInvalidParamException so you will never get that one from the outside of the eFax class.
The following shows what changes between versions. In general, what is listed is what will affect you in some way.
$user_name
instead of $user_password
.eFax::parse_inbound_message()
function and some eFax::get_result...() functions. Updated the documentation accordingly.eFax::set_account_id()
function so invalid characters are automatically removed. Added eFax::set_raw_account_id()
just in case you need to setup an account identifier with what is supposed to be viewed as otherwise invalid characters.eFax::get_result_recipient_csid()
was renamed eFax::get_result_csid()
since it is now used for the notifications of sent faxes and the received faxes. In the later case we are the recipient and thus calling the CSID the recipient was not correct.eFax::get_result_pages_sent()
was renamed eFax::get_result_pages()
since it is now used for the notifications of sent faxes and the received faxes. In the later case, it would need to be "pages received" otherwise.All Rights Reserved. This software and its associated documentation contains proprietary, confidential and trade secret information of Made to Order Software Corp. and except as provided by written agreement with Made to Order Software Corp. a) no part may be disclosed, distributed, reproduced, transmitted, transcribed, stored in a retrieval system, adapted or translated in any form or by any means electronic, mechanical, magnetic, optical, chemical, manual or otherwise, and b) the recipient is not entitled to discover through reverse engineering or reverse compiling or other such techniques or processes the trade secrets contained therein or in the documentation.