Miscellaneous

  Home arrow Miscellaneous arrow Page 4 - 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 - Sending the request with CURL


    (Page 4 of 6 )

    Previously we saw that the request could be executed by pasting it into the browser window. But what we really want is for this to take place behind the scenes. The following code does exactly that using CURL.

    CURL is a very impressive library that allows you to connect and communicate to many different types of servers with many different types of protocols. You can find more info in the PHP Manual.

    This code opens up a connection with the gateway, sends the SMS message(s) and collects their message IDs which are presented within the response header.

    <?php
    $url 
    "http://www.tm4b.com/client/api/send.php"//this is the url of the gateway's interface
    $ch curl_init//initialize curl handle 
    curl_setopt($chCURLOPT_URL$url); //set the url
    curl_setopt($chCURLOPT_RETURNTRANSFER,1); //return as a variable 
    curl_setopt($chCURLOPT_POST1); //set POST method 
    curl_setopt($chCURLOPT_POSTFIELDS$request); //set the POST variables
    $response curl_exec($ch); //run the whole process and return the response
    curl_close($ch); //close the curl handle
    //print $response; //show the result onscreen for debugging
    ?>

    First, we initialize a new CURL session. Then we set our desired options; this includes setting CURLOPT_POST because TM4B's SMS API requires us to send multiple messages using POST. Finally we execute the call and then close the handle.

    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 10 - Follow our Sitemap