Skip to content

SMS API to send SMS from WAY2SMS

January 9, 2011

It will helps you to integrate the free SMS functionlity with in your application using your user credentials in Way2SMS. This program using very simple technique like http client connection to establish a connection with the way2sms website. If you get the thinks better means you can write your own API for many of your favourite application which helps you to integrate that with in your system. This is just like a small type of hacking.

First of all you have to submit username and password to the url and submit your message and send to mobile number.

PHP Source Code:

<?php
ini_set(‘display_errors’, ‘On’);
error_reporting(E_ALL);

//Your way2SMS account details configure here….
$post_data = “username=9984631238&password=xxxxxxx”;
$timeout = 30;
//$header_array[]=”User-Agent:
$url = “http://wwwa.way2sms.com/auth.cl&#8221;;
$cookie = tempnam (“/tmp”, “CURLCOOKIE”);
$ch = curl_init();
curl_setopt( $ch, CURLOPT_USERAGENT,”Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.5) Gecko/2008120122 Firefox/3.0.5″ );
curl_setopt( $ch, CURLOPT_URL, $url );
curl_setopt ($ch, CURLOPT_HTTPHEADER, Array(“Content-Type: application/x-www-form-urlencoded”,”Accept: */*”));
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
curl_setopt( $ch, CURLOPT_COOKIEJAR, $cookie );
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, true );
curl_setopt( $ch, CURLOPT_ENCODING, “” );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_AUTOREFERER, true );
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false ); # required for https urls
curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, $timeout );
curl_setopt( $ch, CURLOPT_TIMEOUT, $timeout );
curl_setopt( $ch, CURLOPT_MAXREDIRS, 10 );
curl_setopt($ch,CURLOPT_REFERER,”http://wwwg.way2sms.com//entry.jsp&#8221;);
$content = curl_exec( $ch );
$response = curl_getinfo( $ch );

$url = “http://wwwa.way2sms.com//jsp/InstantSMS.jsp?val=0&#8243;;
curl_setopt( $ch, CURLOPT_USERAGENT,”Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.5) Gecko/2008120122 Firefox/3.0.5″ );
curl_setopt( $ch, CURLOPT_URL, $url );
curl_setopt($ch, CURLOPT_POST, false);
curl_setopt( $ch, CURLOPT_COOKIEJAR, $cookie );
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, true );
curl_setopt( $ch, CURLOPT_ENCODING, “” );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_AUTOREFERER, true );
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false );
curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, $timeout );
curl_setopt( $ch, CURLOPT_TIMEOUT, $timeout );
curl_setopt( $ch, CURLOPT_MAXREDIRS, 0 );
$content = curl_exec( $ch );
$response = curl_getinfo( $ch );
//site content in the instant sms
$tmp = substr ($content,strrpos($content,”Action”,0)+15,15);
//value of Action=custfromnnnn which will be different for each customer
$id = substr($tmp,0,strrpos($tmp,”"”,0));
//echo $id;

// Add sent to mobile number and your message
$post_data = “custid=undefined&HiddenAction=instantsms&Action=$id&login=&pass=&MobNo=MobileNumber&textArea=You text message”;
$url = “http://wwwa.way2sms.com/FirstServletsms?custid=&#8221;;
curl_setopt( $ch, CURLOPT_USERAGENT,”Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.5) Gecko/2008120122 Firefox/3.0.5″ );
curl_setopt( $ch, CURLOPT_URL, $url );
curl_setopt ($ch, CURLOPT_HTTPHEADER, Array(“Content-Type: application/x-www-form-urlencoded”,”Accept: */*”));
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
curl_setopt( $ch, CURLOPT_COOKIEJAR, $cookie );
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, true );
curl_setopt( $ch, CURLOPT_ENCODING, “” );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_AUTOREFERER, true );
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false ); # required for https urls
curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, $timeout );
curl_setopt( $ch, CURLOPT_TIMEOUT, $timeout );
curl_setopt( $ch, CURLOPT_MAXREDIRS, 0 );
$content = curl_exec( $ch );
//$response = curl_getinfo( $ch );
//print_r($response);
//echo $content;

$url = “http://wwwa.way2sms.com/jsp/logout.jsp&#8221;;
curl_setopt( $ch, CURLOPT_USERAGENT,”Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.5) Gecko/2008120122 Firefox/3.0.5″ );
curl_setopt( $ch, CURLOPT_URL, $url );
curl_setopt ($ch, CURLOPT_HTTPHEADER, Array(“Content-Type: application/x-www-form-urlencoded”,”Accept: */*”));
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
curl_setopt( $ch, CURLOPT_COOKIEJAR, $cookie );
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, true );
curl_setopt( $ch, CURLOPT_ENCODING, “” );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_AUTOREFERER, true );
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false ); # required for https urls
curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, $timeout );
curl_setopt( $ch, CURLOPT_TIMEOUT, $timeout );
curl_setopt( $ch, CURLOPT_MAXREDIRS, 0 );
$content = curl_exec( $ch );
//echo $content;
?>

About these ads

From → PHP

4 Comments
  1. Sridhar permalink

    do u have solution to do the same with Java?

  2. I’m any sure about any such API for right now, but you can deploy these as web service and you can call it from which ever platform you want it.

  3. lavanya permalink

    hi
    this is lavanya
    doing B.E
    i just copied the code and placed in a php file,but when i executed it blank window appears.
    It will be more helpful if u explain with an example.

    • First you need to create way2sms account. In the above code i have been highlighted codes to modify the things like your user name & password to login into ways2sms account and then another highlighted code for sending SMS to particular mobile number and the message content. It wont display any content in the page for notification, but it will send the SMS. You can customize the code as u like as GUI. Thanks for spending your valuable time with us.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 80 other followers

%d bloggers like this: