Send SMS Message Using Clickatell API - Part 5
This part of the tutorial is probably the most important part of the whole tutorial in sending an sms message using the clickatell api. You will create a page “send.php”, then you copy and paste the php code in this page. The send.php does the following;
- Authenticates with the Clickatell Gateway
- Sends the SMS Message
- Retrieve the apimsgid of the corresponding Text Message
- Save the SMS Message and its Apimsgid into the Mysql Database
I have put comments at every step of the code so you can identify what is happening at every stage of the code.
send.php
<?php
//*******************************************
//
// Send SMS Message Using Clickatell API - Part 5
// 23rd September 2007
// www.mboateng.com
// Michael Ofori Amanfo Boateng
//
//**********************************************require_once(’settings.php’);
//retrieve form details
$to = $_POST[’to’];
$from = $_POST[’from’];
$message = $_POST[’message’];function GetSQLValueString($theValue)
{
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;return $theValue;
}//get magic quotes
$message = GetSQLValueString($message);//url encode message
$message = urlencode($message);//authenticating user
$url = “$baseurl/http/auth?user=$user&password=$password&”;
$url = $url.”api_id=$api_id&from=$from&concat=2″;
$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 for sending message
$url = “$baseurl/http/sendmsg?session_id=$sess_id&”;
$url = $url.”to=$to&text=$message&from=$from&”;
$url = $url.”callback=3&deliv_ack=1&concat=2″;// send message
$ret = file($url);
$send = split(”:”,$ret[0]);
if ($send[0] == “ID”){// apimsgid
$apimsgid = trim($send[1]);// insert message with its corresponding apimsgid into the table
mysql_select_db($database_conn, $conn);
$sql = “insert into tbl_outbox (sender,recipient,message,dated,apimsgid ) values (’$from’,'$to’,'$message’,now(),’$apimsgid’) “;
$result = mysql_query($sql, $conn) or die(mysql_error());// redirect to sent.php when message is correctly sent
echo “<script language=\”JavaScript\”>”;
echo ” location.href = ’sent.php’; “;
echo “</script>”;
}
else{// this portion is for message sending failure
echo “<script language=\”JavaScript\”>”;
echo ” location.href = ‘failed.php’; “;
echo “</script>”;}
} else {// this portion checks for correct authentication
echo “<script language=\”JavaScript\”>”;
echo ” location.href = ‘badlogin.php’; “;
echo “</script>”;
}?>
Part 1 | Part 2 | Part 3 | Part 4 | Part 5 | Part 6 | Part 7















