PETS is a simple PHP script to read a mailbox and send the contents (or partial contents) to a mobile phone by SMS (short message service).
As provided, the script uses the API and SMS services provided by PennyTel. No doubt you can change that to use another provider.
Thus, you need a PennyTel account.
The script uses the NuSOAP SOAP classes.
You will need a mailbox reserved to receive the e-mails that are destined to be sent as SMS.
A Web server able to run PHP scripts.
I have installed and tested this (NuSoap ver. 0.7.2) on a commercial shared server. I imagine it could be installed on any server that runs PHP.
Download and unzip the PHP file to your local computer.
Rename the file name from pets.php to a name of your choice, if you wish.
Edit the configuration file pets-cfg.php to customise the variables to set your PennyTel account details:
$Account_ID = "61xxxxxxxxx"; | PennyTel account ID. |
$Account_PW = "xxxx"; | PennyTel account password. |
$SMS_Type = 0; | Integer; 0 = free; 1 = Premium. |
$Default_Dest = "614xxxxxxxx"; | Default destination for SMS; 614xxxxxxxx; |
$Send_Time = "2000-01-01T00:00:00"; | An early time for immediate sending. |
$timezonediff = 15; | Difference in time on the server on which this script is hosted. |
$Mailbox = "{example.com:110/pop3/notls}"; | For PHP's imap_open. {localhost:110/pop3} may also work. |
$Mailbox_User = "some_name_for_sms_mailbox"; | Login for the mailbox that receives your SMS e-mail. Use a non-obvious address to reduce spam. Some accounts may need full e-mail address. |
$Mailbox_PW = "xxxxxxxx"; | Mailbox password. |
$Write_Log = true; | Whether to write a log file. |
$Allow_Any_Sender = false; | Set to true if you are prepared to accept e-mail from any sender,
regardless of the form of the subject. WARNING: this may subject you to more
spam. If set to true, the $Allowed_Addr list is ignored. See "Usage" below. |
For security, leave the configuration file with the .php extension.
Upload the script file and configuration file to a directory of your choice. For example, example.com/pets
For better security, depending on your host,
you can put the configuration file outside the public html area. Just change the path to the include file. Eg., something like:
include '/home/username/pets/pets-cfg.php';
Download the NuSOAP PHP class and upload it to your server. PETS assumes
that it is installed at the same level as PETS itself, in a separate directory. That is, if PETS is in:
example.com/pets, then NuSOAP will be in:
example.com/nusoap.
You can modify the path if required, at the require_once('../nusoap/lib/nusoap.php'); statement.
Current code now works with NuSOAP version 0.7.3 and with PHP 5.2.5 and 5.2.6.
If you wish, PETS can create a log file of activity. This is a simple text file, formatted as CSV to simplify loading into a spreadsheet. You will have to manually delete the log file at some stage as there is no process to stop it growing.
The zip file contains a file called master_smslog.csv, which is just one line of descriptive headers, which you can rename (to the default smslog.csv) and upload to the same directory as the PETS script.
You will probably have to use your FTP program to change the permissions of the file so that can be written to (try 666).
The log file records the following:
Of course, the mailbox needs to be checked on regular intervals. The easiest way to do this is configure a cron job on the server.
How that is done will depend on the control panel used there (if you are not using crontab directly). If you are using cPanel (cron Jobs, Unix style), then do something like:
| Minute | Hour | Day | Month | Weekday |
| */5 | * | * | * | * |
and use a command like (may depend on your host):
/usr/bin/php /home/username/public_html/pt-sms/sms.php
That will run the script every 5 minutes. Change as required. In the field for an e-mail address for the cron results,
enter either a valid e-mail address to receive the results, or enter /dev/nul to send the results nowhere. In some cases,
(e.g., some versions of cPanel) the e-mail field should be left empty if you do not want e-mails of the cron results.
The behaviour of PETS can be controlled by some extent with commands in the e-mail subject line. The codes can be changed in the script. They commands are case sensitive and must appear at the beginning of the subject. The surrounding symbols ([[ and ]] for example, as the default) must also appear. The commands are not sent as part of the SMS message.
NOTE: Do not try to use angle brackets (<, >). PennyTel will not send SMSs with them in the text. PETS converts them to underscores. Messages sent from Outlook Express as HTML e-mails are sent with a text part and an HTML part. PETS retrieves only the text part, without HTML coding. Any remaining angle brackets are converted to underscores.
| [[SMS]]... | Goes to the default mobile number set in the script. Will be sent no matter what e-mail address originates the e-mail. |
| [[SMS_04xxxxxxxx]]... | To the specified number. Australian only at this point. Will be sent no matter what e-mail address originates the e-mail. |
| [[SMSG_group]]... | To the group name in PennyTel address book. Will be sent no matter what e-mail address originates the e-mail. |
| any subject... | To the default number; will be sent only if the sender is in the allowed list. |
$Allowed_Addr = "address@example.com"; | Space separated list of allowed senders; lower case. (In the pets.cfg file) |
$Allow_Any_Sender = false; | Set to true if you are prepared to accept e-mail from any sender,
regardless of the form of the subject. WARNING: this may subject you to more
spam. If set to true, the $Allowed_Addr list is ignored. |
The group name is the name as per the group name in the PennyTel account address book. It it not case sensitive, but the name must match exactly otherwise. That is, spaces, etc, are significant. WARNING: No checks are made as to the number of entries in your particular PennyTel group, so if you are not careful you may end up sending to a lot of phones.
Because you may want to send e-mails from some automated process, or forward some e-mails that arrive, but
are thus unable to modify the subject line, PETS allows the sending of messages without the subject line commands. However, the sender of the e-mail must
be in the list allowed in the $Allowed_Addr variable, otherwise the mail will be classified as spam, and not sent.
Because the Short Message Service does not guarantee delivery, it may be worth considering configuring the e-mail address for the SMS mailbox so that it also forwards the e-mail to another e-mail address. That way, you will obtain the (full) contents of the message by e-mail, as well. You should be able to do that on the host server.
Messages are sent in the following format, with the items separated with dashes:
<Subject>-<From (name)>-<From (email address)>-<Body of e-mail>
PennyTel allows messages of up to 255 characters and will automatically send up to two SMSs. PETS uses this feature; messages longer than the limit (default of 255) are truncated, and the indicator of "-more." is appended to the end of the message.
End-of-lines, excess whitespace, and HTML tags are stripped.
Previous version: 1.3 June 2007 (for NuSOAP 0.7.2)
pets.zip (8k)
Current version: 1.4 June 2008 (for NuSOAP 0.7.3)
pets-1-4.zip (10k)
Here is an "offshoot" of the project... a script that will make a VoIP call-back, initiated by e-mail.
Subject line is:
<First leg><space><second leg>
Eg:
617xxxxxxxx 612xxxxxxxx
will have the originating call (first leg) go to a Queensland number, and the destination to NSW.
NOTE: THIS IS ONLY DEMONSTRATION, PROOF-OF-CONCEPT CODE!! (E.g., PennyTel account details are hard coded.)
For use with NuSOAP 0.7.3 you'll need to change line 22 to:
$client = new nusoap_client("http://pennytel.com/pennytelapi/services/PennyTelAPI");
php-cb-demo.zip (2k)
If you are getting an error message something like:
Fatal error: Cannot redeclare class soapclient in <your host path>/nusoap/lib/nusoap.php on line 7240
then it could be some conflict with PHP5 builtin soapclient.
Do this to fix it (this should not be necessary if you are using NuSOAP 0.7.3):
Edit all the occurrences of "soapclient" in the files in nusoap/lib, changing to, say, "soapclientNU". Not all files have it. Take care to not modify names of which "soapclient"
is a subset. Rename the file class.soapclient.php to class.soapclientNU.php (if you also changed references to it).
Change (line 50 approx.), in pets.php, the line:
$client = new soapclient("http://pennytel.com/pennytelapi/services/PennyTelAPI");
to
$client = new soapclientNU("http://pennytel.com/pennytelapi/services/PennyTelAPI");
[Here are the edited files for version 0.7.2 (they go in the nusoap/lib directory): nusoap-0-7-2-nu.zip.
You'll still have to edit line 50 of pets.php if you use those modified lib files.]
If you get an error such as the following, then double check your PennyTel login usrename and password.
Array
(
[faultcode] => soapenv:Server.userException
[faultstring] => java.lang.NullPointerException
[detail] => Array
(
[hostname] => penny1
)
)
This program is provided as is, with no warranty of any kind. Use of the program for any legal purpose is permitted, so long as accreditation is not removed from the code.