Thursday, January 19, 2006

SMS (Short Message Service)

You can use SMS to send and receive from the website to mobile phone. There are 2 issues you need to know and its costs as well.
1. Need to buy the SMS messages allowing you to send. Depending on where you are using to send SMS messages, there is another terms called SMS credits sometime 1 SMS message costs SMS credits and if the SMS has to travel to many hops/routers, it can cost more 1 SMS credits. There is a website has everything you need to know (http://www.clickatell.com)
2. If you want to receive a message from mobile phone then you need to have a number registration for example 123456789@clickatell.com so it will forward this SMS message to your website. They can convert SMS to email and vice versa. The cost to have a number like a telephone number is $20.00/month
Here is PHP code to implement to your website. You need to pay to get the
password and username. After you submit into their API, it returns with $ret where is valid or non valid, and tell you whether the message has been sent or not.

PHP
$user = "user";
$password = "password";
$api_id = "xxxx";
$baseurl ="http://api.clickatell.com";
$text = urlencode("This is an example message");
$to = "0123456789";
// auth call
$url = "$baseurl/http/auth?user=$user&password=$password&api_id=$api_id";
// do auth call
$ret = file($url);
// split our response. return string is on first line of the data returned
$sess = split(":",$ret[0]);
if ($sess[0] == "OK") {
$sess_id = trim($sess[1]); // remove any whitespace
$url = "$baseurl/http/sendmsg?session_id=$sess_id&to=$to&text=$text";
// do sendmsg call
$ret = file($url);
$send = split(":",$ret[0]);
if ($send[0] == "ID")
echo "success
message ID: ". $send[1];
else
echo "send message failed";
} else {
echo "Authentication failure: ". $ret[0];
exit();
}
?>



No comments: