Miscellaneous

  Home arrow Miscellaneous arrow Page 3 - Sending SMS Thru HTTP
MISCELLANEOUS

Sending SMS Thru HTTP
By: Codewalkers
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 64
    2005-05-11

    Table of Contents:
  • Sending SMS Thru HTTP
  • Understanding the Requirements of the Gateway
  • Prepare the Request
  • Sending the request with CURL
  • Sending the Request with Sockets
  • Conclusion

  •  
     

    SEARCH CODEWALKERS

    TOOLS YOU CAN USE

    advertisement

    Sending SMS Thru HTTP - Prepare the Request


    (Page 3 of 6 )

    Now the actual message-delivery process is handled by the gateway. All they want us to do is pass them the details of the message(s) in the form of an HTTP request, similar to this one:

    http://www.tm4b.com/client/api/send.php? username=abcdef&password=12345&msg=This+is+sample+message.& to=447768254545%7C447956219273%7C447771514662& from=MyCompany&route=frst&sim=yes

    You can test the above example (which uses GET) by pasting it into your browser's address bar. You should get a response saying that the username is invalid, which is normal because this is just to demonstrate.

    The first step is to save our data as variables and then convert them into a URL request. There are different ways of doing this, but this is a very innovative and useful way:

    <?php
    $request 
    ""//initialize the request variable
    $param["username"] = "abcdef"//this is the username of our TM4B account
    $param["password"] = "12345"//this is the password of our TM4B account
    $param["msg"] = "This is sample message."//this is the message that we want to send
    $param["to"] = "447768254545|447956219273|447771514662"//these are the recipients of the message
    $param["from"] = "MyCompany";//this is our sender 
    $param["route"] = "frst";//we want to send the message via first class
    $param["sim"] = "yes";//we are only simulating a broadcast

    foreach($param as $key=&gt;$val//traverse through each member of the param array

      
    $request.= $key."=".urlencode($val); //we have to urlencode the values
      
    $request.= "&amp;"//append the ampersand (&amp;) sign after each paramter/value pair
    }
    $request substr($request0strlen($request)-1); //remove the final ampersand sign from the request
    ?>

    We assign our credentials and routing information in the $param array. You'll notice that multiple recipients can be defined by separating them with the pipe-character. Each parameter value needs to be urlencoded and multiple key/value pairs are separated by ampersands. A final ampersand probably would not cause any problems but substr is still used to produce a tidy request.

    The script will produce the following request that can be sent to the SMS gateway: username=abcdef&password=12345&msg=This+is+sample+message.& to=447768254545%7C447956219273%7C447771514662& from=MyCompany&route=frst&sim=yes

    More Miscellaneous Articles
    More By Codewalkers

    blog comments powered by Disqus

    MISCELLANEOUS ARTICLES

    - Oracle Database XE: Indexes and Sequences
    - Modifying Tables in Oracle Database XE
    - Oracle Database XE: Tables and Constraints
    - More on Oracle Databases and Datatypes
    - Oracle Database XE Datatypes: Datetime and L...
    - Oracle Database XE Datatypes: Character and ...
    - From Databases to Datatypes
    - Firefox 3.6.6 Released with Improved Plug-in...
    - Attention Bloggers: WordPress 3.0 Now Releas...
    - Reflection in PHP 5
    - Inheritance and Other Advanced OOP Features
    - Advanced OOP Features
    - Linux from Scratch V.6.6 Review
    - Linux Gaining in Strength
    - Install Slackware on Your Old PC


    © 2003-2012 by Developer Shed. All rights reserved. DS Cluster 4 - Follow our Sitemap