Now We have our own SMS gateway up and working.But the million dollar question is how to send sms
now from it?
So you can use following links on your browser or php codes to send SMS:
1:http://localhost:13013/cgi-bin/sendsms?from=8009657517&username=kannel&password=kannel&text=hi%20budddy!&to=8009657517
2:http://localhost:13013/cgi-bin/sendsms?username=kannel&password=kannel&to=8009657517&text=hi%20buddy!
3:http://localhost:13013/cgi-bin/sendsms?from=123&username=kannel&password=kannel&text=%(text)s&to=%(recipient)
4:header("Location:http://localhost:13013/cgi-bin/sendsms?username=kannel&password=kannel&to=$in_number&text=$in_msg")
Just put your own username and password and you are good to go.
Now we can also build own PHP/MYSQL applications to send sms.
How We are going to do it ??
- User send his/her name by sms
- The message is forwarded to our application by the SMS box
- Our application store the sender name and telephone number in the database and then reply back to the user
Setting up the SMS box to foward every received message to our application{we had already done this in my last post here}
We must make the get-url point to our script and passed the variables as querystring
%p – is the variable for the sender number
%b – represent the text message received
you can take a look at other available variables here
A Simple PHP Script:
<?php
define("DBHOST","localhost",true);
define("DBUSERNAME","myUsername",true);
define("DBPASSWORD","myPassword",true);
define("DBNAME","kannel_sms",true);
function smsinsert($sender,$text)
{
$con = 'mysql:dbname='.DBNAME.';host='.DBHOST;
try {
$cmd = new PDO($con,DBUSERNAME,DBPASSWORD);
$stmt = $cmd->prepare("INSERT INTO kannel_tuto (number,message) VALUES (:sender,:message)");
$stmt->bindParam(':sender',$sender);
$stmt->bindParam(':message',$text);
$stmt->execute();
$cmd = null;
if($stmt->rowCount()>0)
{
echo "Hello ".$text.". Thank you for your registration.";
}
else
{
echo "Sorry an error has occured";
}
}
catch (PDOException $e) {
echo 'Connection failed: ' . $e->getMessage();
}
}
smsinsert($_GET['sender'],$_GET['text']);
?>
The script is very simple.
1:Create your own database with phpmyadmin or mysql.
2:We define a function smsinsert which will save the person name and phone number in our database.
3:The query string values are passed to the function
4:The function reply back by a success or failure message
5:The message is automatically send to the sender.
No comments:
Post a Comment