PHP tutorials,a way to getting some thing new in web

Followers

Powered by Blogger.

Wednesday 19 November 2014

How To send sms using API in PHP??

No comments :
Today we guys mostly use sms services available on internet like way2sms,160by2.but have we ever thought to take them in our webapplications.

In PHP,We can do this with simple code of thirdparty api..
Here i have created simple code which sends sms to given mobile number using clickatell API.




Here is code:

<?php
    $user = "xxxxxx";
    $password = "xxxxxx";
    $api_id = "xxxxxx";
    $baseurl ="http://api.clickatell.com";

    $text = urlencode("This is an example message");
    $to = "+919408046690";

    // auth call
    $url = "$baseurl/http/auth?user=$user&password=$password&api_id=$api_id";

    // do auth call
    $ret = file($url);

    // explode our response. return string is on first line of the data returned
    $sess = explode(":",$ret[0]);
    if ($sess[0] == "OK") {

        $sess_id = trim($sess[1]); // remove any whitespace
        $url = "$baseurl/http/sendmsg?session_id=$sess_id&to=$to&text=$text";

        // do sendmsg call
        $ret = file($url);
        $send = explode(":",$ret[0]);

        if ($send[0] == "ID") {
            echo "successnmessage ID: ". $send[1];
        } else {
            echo "send message failed";
        }
    } else {
        echo "Authentication failure: ". $ret[0];
    }
?>

In this code,user,password and api id are needed for code,which is available on www.clickatell.com/
site.

Happy Coding guys!!! 

No comments :

Post a Comment