Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Implement SMS Gateway just in 5 Minutes using php

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 1.18k
    Comment on it

    If you want to implement SMS gateway using php.It's now very easy. Use clickatell SMS Gateway.

    To implement clickatell SMS Gateway you have to follow below simple steps.

    Step 1: Just go to the clickatell website.The url of clickatell site is as follow

    https://www.clickatell.com/developers/sms-gateway/

    Here at the right hand side there is a option to create free account. After using that just enter your basic detail then your account will be created.

    Step 2: Then You will get a url which I have written below:

    http://api.clickatell.com/http/sendmsg?user=USERNAME&password=PASSWORD&api_id=3600734&to=917060328868&text=Message

    Here in this url fill your user name and password and in to field write the number which you want to send the message.

    Step 3:

    class ClickatellComponent extends Component {
      /**
      * The username for the Clickatell API
      * @access public
      * @var string
      */
               
    //  var $api_user = '';
      var $api_user = '';
    
      /**
      * The password for the Clickatell API
      * @access public
      * @var string
      */
    //  var $api_pass = '';
    //  var $api_pass = '!';
      var $api_pass = '';
    
      /**
      * Who will be shown as the sender of the text at the receivers handset.
      * @access public
      * @var string
      */
    //  var $api_from = '';
      var $api_from = '';
    
      /**
      * The API id for this product.
      * @access public
      * @var string
      */
    //  var $api_id = ApiId;
      var $api_id = ApiId;
    
    
      /**
      * The Clickatell XML API url
      */
      const API_XML_URL = 'http://api.clickatell.com/xml/xml';
    
      /**
      * The Clickatell HTTP API url for sending GET or POST requests too.
      */
      const API_HTTP_URL = 'http://api.clickatell.com/http/';
    
    //user=WhoznextProd&password=PASSWORD&api_id=3492985&MO=1&from=17752374396&to=18183882818&text=Message
      /**
      * Post a message to the Clickatell servers for the number provided
      * @param string $tel The telephone number in international format.  Not inclduing a leading "+" or "00".
      * @param string $message The text message to send to the handset.
      * @return string
      * @see SmsComponent::api_id
      * @see SmsComponent::api_user
      * @see SmsComponent::api_pass
      * @see SmsComponent::api_from
      */
      function postSms($tel, $message) {
        $message = trim(str_replace(array("\n", "\r"), ' ', $message));
        $postdata = http_build_query(
          array(
            'user' => $this->api_user,
            'password' => $this->api_pass,
            'api_id' => $this->api_id,
            'MO'=>1,
            'from' => $this->api_from,
            'to' => $tel,
            'concat' => '3',
            'text' => $message
          )
        );
    
        $opts = array('http' =>
          array(
            'method'  => 'POST',
            'header'  => 'Content-type: application/x-www-form-urlencoded',
            'content' => $postdata
          )
        );
        $context  = stream_context_create($opts);
        $response = file_get_contents(self::API_HTTP_URL.'sendmsg', false, $context);
        return $response;
      }
    
      /**
      * Get the balance of your Clickatell account.
      * @return float
      * @see SmsComponent::api_id
      * @see SmsComponent::api_user
      * @see SmsComponent::api_pass
      * @see SmsComponent::api_from
      */
      function queryBalance() {
        $postdata = http_build_query(
          array(
            'api_id' => $this->api_id,
            'user' => $this->api_user,
            'password' => $this->api_pass
          )
        );
    
        $opts = array('http' =>
          array(
            'method'  => 'POST',
            'header'  => 'Content-type: application/x-www-form-urlencoded',
            'content' => $postdata
          )
        );
    
        $context  = stream_context_create($opts);
        $response = file_get_contents(self::API_HTTP_URL.'getbalance', false, $context);
        return $response;
      }
    }

    Here is the component where we put your credential and use it where you want. This component can check the available balance we have in our clickatell account and if we have balance in our clickatell account then send the message.

    By this way you can implement clickatell sms gateway in your project.

    NOTE: By using clickatell we can also maintain a record that how much message we have send at which phone number and their status. Many more records can be maintained by using clickatell.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: