PHP script to send message

Following steps to send SMS using PHP.

Step 1:  Simply register for an account, and you will get username and password.

Step 2: When you login using these username and password, you will get an api_id to use.

These username , password and api_id details will be used in the code to send sms .

 

Here is the code to send sms : 

Code Sample:

<?php

    $user = “user”;
    $password = “password”;
    $api_id = “xxxxxxx”;
    $baseurl =”http://api.clickatell.com”;
 
    $text = urlencode(“This is an example message”);
    $to = “00123456789″;
 
    // 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];
    }
?>

 

 

Change the username and password and api_id with your username, password and api_id .

Enter the phone no in $to variable value.

You can change the $text  variable value that you want to send in sms.

 

941 total views, 1 views today

Share this OnShare on FacebookTweet about this on TwitterShare on LinkedInShare on Google+

Leave a Reply