Thursday, March 21, 2013

SMS Gateway integration in PHP

The integration SMS API / Gateway with the PHP Code is very easy to implement

Following is the description of how to send SMS to a user who has registered on our web page. First of all, we have to add an HTML Element that will accept Mobile Number of the user. This mobile number value will be posted to the next PHP Page. Here, using CURL (Client URL) Library, we can post the mobile number field value to the SMS API

HTML Form
<form action=submit.php method=post>
Username <input type=text name=u>
<br>
Password <input type=password name=p>
<br>
Mobile Number <input type=text name=m>
<br>
<input type=submit value="Register">
</form>


PHP Page
<?php
$u=$_POST['u'];
$p=$_POST['p'];
$m=$_POST['m'];

$ch = curl_init();

$url="http://IPAddress/api/MessageCompose?admin=admin&user=SMSAPIUSERNAME:SMSAPIPASSWORD&senderID=TEST%20SMS&receipientno=$m&msgtxt=Welcome%20$u%20Your%20Password%20$p&state=4";

// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, "$url");
curl_setopt($ch, CURLOPT_HEADER, false);

// grab URL and pass it to the browser
curl_exec($ch);

// close cURL resource, and free up system resources
curl_close($ch);
echo "Successful Register ... Confirmation sent to your Mobile Number";

?>

No comments:

Post a Comment