Syed Jahanzaib Personal Blog to Share Knowledge !

September 7, 2016

Sample PHP page to insert data into kannel/sqlbox

Filed under: Linux Related — Tags: , — Syed Jahanzaib / Pinochio~:) @ 11:56 AM


Other kannel references:

Before Proceeding further, read the following links for Kannel Installation and configure SLQBOX.

Following is a sample PHP file which can be called by BASH/CURL or any remote system to send SMS via inserting the message into SND database which will send SMS to destination with the message. So it will act as a centralized SMS submission process that will keep record of every outgoing Sent SMS along with any detail that we requires, example sender (the requesting party), recipient, and the message (OR etc etc)

This is just for reference purposes of DOABLE things, and by no means it should be deployed in production environment. These are just short references, and must be modified according to the safety standards.



Currently we are using KANNEL as SMS gateway to send messages to users,admins about various events and information. This SMS Gateway is used by the Linux , Mikrotik Router, and windows base systems. But the problem is that using standard kannel HTTP submission method, we cannot track any message and its status. Its like blind system. And recently it was asked by few OP to track the Sent sms Numbers, status for a particular given time or over all month report.


Standard Examples of sending SMS via kannel HTTP submission:

Linux Example:

curl "$KURL/cgi-bin/sendsms?username=$KID&password=$KPASS&to=$mobile" -G --data-urlencode text@/tmp/$USR.sms

Windows Example:

C:\wget\wget.exe  " [TimeAndDate] UPS is working on KESC now"

Mikrotik Example:

/tool fetch url="$KURL\?username=$KID&password=$KPASS&to=$cell1+$cell2&text=$MSGUPSMS"


I wanted to have a simple PHP page that can be called by any system with only three fields

1- Sender (Example server1 or ExpiryDaemon)
2- To (mobile number of the recipient)
3- Message (which is usually large with multiple lines)

One Example for Linux base system as following:

The scheduled bash script runs on Linux base billing system which submits various messages to users like account expiry, password change info, etc via submitting messages with destination numbers using CURL.


For this purpose we made simple PHP page that can be called from any remote system and will act using the provided url parameters. thanks to mr tapan.kumar for providing sample php page for this purpose.

Example of CURL/BASH script which fetch data from mysql table for  logged in alert for manager/admin into panel.

You have successfully logged-in to billing admin panel.
ID = $ID
Thank You"

# Curl example that will call test.php with 3 parameters ...
curl -G "http://$KANNELURL/test.php?sender=php&to=$MOBILE" --data-urlencode "message=$MSG"



$host = 'localhost';
$user = 'root';
$password = 'SQLPASS';
$database = 'kannel_db';
$port = 3306;
$conn = mysql_connect($host, $user, $password);
mysql_select_db($database, $conn);
if (!$conn) {
die("Unable to connect with MySQL database.\n");
$sender = trim($_GET['sender']);
$to = trim($_GET['to']);
$message = trim($_GET['message']);
// I have already configured the SQLBOX so any entry made into SND DB, it will automatically move
// data into send_sms and will update the SND status as well on receiving DLR
$sqlQuery = "insert into snd (snd_sender,snd_to,snd_txt) values('$sender','$to','$message')";
echo 'OK';

When the curl will call test.php , it will simply enter the data into SND DB.



and from mikrotik it would be like



This way we can have a centralized SMS submission system , which will keep track of every SENT sms with the details we require according the local need. It can be modified as per the requirements. These are just my findings from Google and tips with some working sample code from few resources.


Syed Jahanzaib

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at

%d bloggers like this: