Introduction: This is very simple and workable example of sending sms using PHP fopen & Curl function. I m not completly a php coder but somehow i got the code by searching over the internet. But it was giving error so i modify the code and finaly after working on it for 5hrs i got the actual functional code.
The values used in the code like username, mobile, password, sender, message these are the input values i got it from my sms api company so you can modify those values if your sms sender api company provides diff. values to work on.
This code works on fopen and curl function so dont panic if your php.ini dosent supports curl function, this code will work. Try this code and get back to me if any help needed.
You can download the code from here
<?php
/**
*Do not remove the creditable note this code will help you to send sms using http request
*/
// Send the SMS function function openurl($url)
{
if(is_callable(”curl_exec”))
{
// Use CURL if it’s available
$ch = @curl_init($url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
}
else
{
// Use fopen instead
if($fp = @fopen($url, “rb”))
{
$result = “”;
while(!feof($fp))
{
$result .= fgets($fp, 4096);
}
@fclose($fp);
}
}
return $result;
}
$username=”enter username here”; //use your sms api username
$password=”enter password here”; //use your sms api password
$sender=”enter sender id here”; //use your sms api sender id
$mobile=”use delivery cell no. here”; //use delivery cell no.
$message=”Your Subject : $fullname on $cell.$line”;
$sms_url = sprintf(”http://www.yoursmsapigoeshere.comusername=%s&password=%s&sender=%s&mobile=%s&clientcharset=UTF-8&message=%s“, $username, $password, $sender, $mobile, urlencode($message));
// Let’s try to send the message
$result = openurl($sms_url);
// End if
// Redirect
echo “<script type=’text/javascript’>”;
echo “alert(SMS Sent Successfully’)”;
echo “</script>”;
echo “<script type=’text/javascript’>”;
echo “window.location=put redirect url here’”;
echo “</script>”;
?>
You can download sendsms.html, send_sms.php files

