Sending Text Messages w/ PHP

Sending text messages from your web site can be great for security, It would be nice to beable to make a return on it aswell, so your not forking out hundreds of pounds on text messaging, but thats up to you to manage.

ClickATell offer an amazingly simple set of APIs for sending text messages via their network, along with very affordable text messaging bundles.

The thing I use text messaging for is again, server monitoring. Whenever a server of mine goes above a certain load level, a text message is fired off to me to alert me. This actually saved the day – on Christmas day – last year, when there was a hard drive failure on a clients server, I got a text at the breakfast table.

[php]
## DEFINE ACCOUNT USERNAME & PASSWORD
$user = ‘<-- username -->‘;
$password = ‘<-- password -->‘;

## DEFINE ACCOUNTS API ID
$api_id = ‘<-- api id -->‘;

## BASE URL
$baseurl =’http://api.clickatell.com’;

## MESSAGE TO BE SENT
$text = urlencode(‘<-- message to be sent by text -->‘);

## PHONE NUMBER TO SEND TO, STARTING WITH COUNTRY CODE (4477425235235)
$to = ‘<-- recipients phone number, starting with country code -->‘;

$url = $baseurl.’/http/auth?user=’.$user.’&password=’.$password.’&api_id=’.$api_id;
$ret = file($url);
$sess = split(‘:’,$ret[0]);

if($sess[0] == ‘OK’) {

$sess_id = trim($sess[1]);
$url = $baseurl.’/http/sendmsg?session_id=’.$sess_id.’&to=’.$to.’&text=’.$text;
$ret = file($url);
$send = split(‘:’, $ret[0]);

if($send[0] == ‘ID’) {
echo ‘Message Sent’;
} else {
echo ‘Message Failed To Send.’;
}

} else {
echo ‘Auth failure :/’;
exit();
}
[/php]