Free SMS Gateway Programming in PHP

Free SMS Gateway Programming in PHP

Introduction:

Billions of SMS (Short Messaging Services in full) are sent daily, and it's a good
 option for sending promotion message, marketing coupon code distribution, 
notification, etc among many uses SMS Marketers adopted for using Text Messages. 
The amazing part is that in order for marketers to do what they do best, they often requires the service of a developer to help build a tool to augment their 
business. And importantly SMS senders wants more options of sending their message
 from any platform like desktop, mobile, even from an application (Where Software send SMS automatically to notify the involving parties) and this 
has require the need for most SMS gateway providers to have a public API that
 allows other developers to build a customize version of their software and give
 users of their system unlimited ways of using their solution.

About SMS2Profit:

SMS2Profit is a SMS marketing platform for small to mega businesses who are interested in promoting their businesses via SMS marketing. The platform varieties of SMS Marketing Solutions built into it. You can sign up for an account at https://www.portal.sms2profit.com/register/ to create an account or login at www.sms2profit.com/login/ I am supposed to give a full review of their products and services, but I will just dive straight into a feature of their Solution i.e. the SMS API (Application Programming Interface)
Their SMS API is: https://www.portal.sms2profit.com/sms-api/ and how to consume their API interface is presented below. Not only can you send SMS from the login of the system, but also outside the system without login in into the system. That means their API support both GET and POST requests.

Getting Started:

Here is a quick tutorial on how to program and build your own SMS Gateway using PHP
, mostly all SMS gateway provides third party developers with an API. It is with 
this API that other developers can  connect to their proprietary solutions without
 knowing the internal operation of the called solution and perhaps extends it
 beyond what is expected. This Tutorial is for you if:
  • You are planning to build a free/paid system 
  • You are a System Integrator 
  • You are a System Developer
  • Mobile App developer
  • etc

SMS Gateway API

Most SMS Gateway API exist in this format:
https://www.portal.sms2profit.com/sms-api/?email=email@email.com&password=password&message=Testing+this+gateway+&sender=Testing&recipients=0803123456789?appid=b7ca6aef60a667c185cf73a1b3ba0b50&email=email@email.com&password=password&message=Testing+this+gateway+&sender=Testing&recipients=0803123456789 
This chunk of text above, technically can be divided into two parts. 
The two necessary part is https://www.portal.sms2profit.com/sms-api/ and the second 
part is referred to as the  parameters (variables/instructions to be sent to 
the server). In order to send message to any SMS Gateway you must be equipped 
with those information. And here is a utility function that can does the magic 
of sending it to the gateway, the function doesn't actually communicate with Network provider, 
but hands over the message to the SMS Gateway based on their specified rules, 
and of course wait for their response. The function below does 
the magic:

function sendMessageCurl($apiUrl, $postValue) {
$browserType = "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax)";
$ci = curl_init();
curl_setopt($ci, CURLOPT_URL, $apiUrl);
curl_setopt($ci, CURLOPT_USERAGENT, $browserType);
curl_setopt($ci, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($ci, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ci, CURLOPT_POST, 1);
curl_setopt($ci, CURLOPT_POSTFIELDS, $postValue);
$gatewayResult = curl_exec($ci); curl_close($ci);
return $gatewayResult;
}
This function is expecting tow arguments to performs its role, so therefore two 
parameters must be passed to it. The first parameter $apiUrl is the SMS Gateway 
API (https://www.portal.sms2profit.com/sms-api/ in the case of SMS2Profit) while the
second parameter 
(appid=b7ca6aef60a667c185cf73a1b3ba0b50&email=email@email.com&password=password&message=Testing+this+gateway+&sender=Testing&recipients=0803123456789
is the expected parameter in order to send message) is the SMS Gateway expected parameters to be sent along to the gateway.

Implementation

Finally, here is how to implement the magic function in your code, to make it serve you the way you wanted, our gateway api address is http://www.sms2profit.com/sms-api/ and the required parameter are 
appid (AppID the application sending the message not compolsory),
email (Email the users uses in login into the application),
password (Login Password to the application), 
message (Message to be sent, space has been replaced with plus + sign url encoded), 
sender (Sender name that will appears as the sender of the message), 
recipients (Message recipients or Message Destination note multiple number
should be separated with comma in the case of sms2profit.com) all concatenated to 
get the string below:
appid=b7ca6aef60a667c185cf73a1b3ba0b50&email=email@email.com&password=password&message=Testing+this+gateway+&sender=Testing&recipients=0803123456789

Final Code:

So here is the final code, you can modify it to your need, but please don't lay claim on it.
<?php
$apiUrl = "https://portal.sms2profit.com/sms-api/";
$postValue="appid=b7ca6aef60a667c185cf73a1b3ba0b50&email=email@email.com&password=password&message=Testing+this+gateway+&sender=Testing&recipients=0803123456789";
sendMessageCurl($apiUrl, $postValue);
?>
This is everything in all

<?php
function sendMessageCurl($apiUrl, $postValue) {
$browserType = "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax)";
$ci = curl_init();
curl_setopt($ci, CURLOPT_URL, $apiUrl);
curl_setopt($ci, CURLOPT_USERAGENT, $browserType);
curl_setopt($ci, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($ci, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ci, CURLOPT_POST, 1);
curl_setopt($ci, CURLOPT_POSTFIELDS, $postValue);
$gatewayResult = curl_exec($ci); curl_close($ci);
return $gatewayResult;
}
$apiUrl = "http://www.sms2profit.com/sms-api/";
$postValue = "appid=b7ca6aef60a667c185cf73a1b3ba0b50&username=email@email.com&password=password&message=Testing+this+gateway+&senderid=Testing&recipients=0803123456789";
sendMessageCurl($apiUrl, $postValue);
?>

Final Note:

Please note SMS2Profit provide you with the privilege of sending message 
through GET request as aforementioned all you have to do is copy the URL in
quote below and paste it into your web browser 
https://www.portal.sms2profit.com/sms-api/appid=b7ca6aef60a667c185cf73a1b3ba0b50&username=email@email.com&password=@password&message=Testing+this+gateway+&senderid=Testing&recipients=0803123456789” 
that is all to the tutorial and review.
You may want download the code on my github page 
https://github.com/habeeb-salami/free-sms2profit-sms-gateway-php
Now your turn, what will you say about this code/tutorial? Kindly post 
your comment below:

Comments

Popular posts from this blog

Birth and Death of Bulk SMS Business in Nigeria

WHAT YOU NEED TO KNOW BEFORE LEARNING A PHP FRAMEWORK

Free Open Source Software That Could Make You Rich