Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6576795
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:33:22+00:00 2026-05-25T15:33:22+00:00

Please guide me with sample code for sending sms through website. How to include

  • 0

Please guide me with sample code for sending sms through website. How to include sms gateway. Please tell me, can i use way2sms.com as gateway?

is it the right way to use? please suggest me only this much of code works?

<?php
error_reporting(E_ALL);
ob_implicit_flush(true);


include_once "class.curl.php";
include_once "class.sms.php";

$smsapp=new sms();
$smsapp->setGateway('way2sms'); 


echo "Logging in  ... ";
$smsapp->login('10 digit number','way2sms password');

echo "Sending SMS ... ";
$result=$smsapp->send('receipient number','text message');

if($result=='true')
{
    echo "Message sent";
}
else
{   
    echo "Error encountered : ".$smsapp->getLastError();
}

?>

here is my class.curl.php

<?php
class sms
{
    var $username;
    var $password;
    var $curl;
    var $server;
    var $loginDone;
    var $debugMode;
    var $data;
    var $error;
    public function __construct()
    {
        $this->curl=new cURL();
    //  $this->curl->setProxy("");
        $this->loginDone=false;
        $this->debugMode=false;
        $this->data=array();
    }
    public function setGateway($serverName)
    {
        switch($serverName)
        {
            case '160by2':
            $this->server='160by2';
            break;

            case 'way2sms':
            $this->server='way2sms';
            break;

            case 'airtel':
            $this->server='airtel';
            break;

            default :
            $this->server='way2sms';

        }
    }
    public function login($username,$password)
    {
        $server=$this->server;

        call_user_func(array($this,"login_$server"),$username,$password);
        $this->loginDone=true;

    }
    public function send($number,$msg)
    {
        $server=$this->server;
        if($this->loginDone)
        return call_user_func(array($this,"send_$server"),$number,$msg);
        else
        {
            echo "<h2>Please login first before sending SMS</h2>";
        }

    }
    private function login_way2sms($username,$password)
    {
        $out=($this->curl->post("http://www.way2sms.com","1=1"));
        $pattern="/Location:(.+?)\n/";
        preg_match($pattern,$out,$matches);
        $domain=trim($matches[1]);

        $this->data['domain']=$domain;

        $out= $this->curl->post("{$domain}auth.cl","username=$username&password=$password&Submit=Sign+in");

        $pattern="/Location:(.+?)\n/";
        preg_match($pattern,$out,$matches);
        $referer=trim($matches[1]);
        $this->data['referer']=$referer;


    }


    private function send_way2sms($number,$msg)
    {
        $domain=$this->data['domain'];
        $html=$this->curl->post("{$domain}jsp/InstantSMS.jsp?val=0","1=1",$this->data['referer']);
        if($this->debugMode)
        {
        echo "<h2>After logging in, the HTML returned by server is</h2>";
        echo $html;
        }

        $pattern = '/name="Action".+?value="(.*)"/';
        preg_match($pattern, $html, $matches);

        $custfrom=$matches[1];
        $msg=urlencode($msg);
        $html=$this->curl->post("{$domain}FirstServletsms?custid=","custid=undefined&HiddenAction=instantsms&Action={$custfrom}&login=&pass=&MobNo=$number&textArea=$msg");
        $pattern = '/class="style1">(.+?)<\/span>/';
        preg_match($pattern, $html, $matches);
        $out=($matches[1]);

        if(!preg_match("/successfully/",$out))
        {
        $this->setError($out);
        return false;
        }
        else
        {
        return true;
        $this->setError("No errors");
        }

    }
    public function getLastError()
    {
        return $this->error;

    }
    private function setError($error)
    {
        $this->error=$error;
    }
    private function login_160by2($username,$password)
    {
    //  $out2=$this->curl->get("http://m.160by2.com");
        $out=$this->curl->post("http://m.160by2.com/LoginCheck.asp?l=1&txt_msg=&mno=","txtUserName=$username&txtPasswd=$password&RememberMe=Yes&cmdSubmit=Login");
        $pattern="/MyMenu.asp\?Msg=(.+?)&/";

        preg_match($pattern,$out,$matches);
        $id=trim($matches[1]);
        $this->data['id']=$id;

    }

    private function send_160by2($number,$msg)
    {
        $msg=urlencode($msg);
        $id=$this->data['id'];
        $out1=$this->curl->post("http://m.160by2.com/SaveCompose.asp?l=1","txt_mobileno=$number&txt_msg=$msg&cmdSend=Send+SMS&TID=&T_MsgId=&Msg=$id");
        //echo $out1;
        $pattern = '/\<table.+?\>(.+)\<\/table/s';
        preg_match($pattern, $out1, $matches);

        $out=strip_tags(@$matches[1]);
        if(count($matches)<1)
        {
        $pattern="/\<div.+?background:.+?yellow.+?\>(.+?)\<\/div\>/s";

        preg_match($pattern,$out1,$matches);

        $out=strip_tags($matches[1]);
        }

//
    //  echo "out is $out";

        if(!preg_match("/successfully/i",$out))
        {

        $this->setError($out);

        return false;
        }
        else
        {
        return true;
        $this->setError("No errors");
        }

    }

    private function login_airtel($username,$password)
    {
        $this->data['username']=$username;
        $this->data['password']=$password;

    }


    private function send_airtel($number,$msg)
    {

    }
}

?>

in the place of username and password, which username and password i should use?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T15:33:23+00:00Added an answer on May 25, 2026 at 3:33 pm

    Yeah, or you could use the gateways as provided by the wireless carriers themselves, as then it’s as simple as sending them an email with PHP’s mail function.

    Where (Number) is, you must include their 10 digit phone number. So that means that you must include their area code.

    AT&T
    (Number)@txt.att.net

    T-Mobile
    (Number)@tmomail.net

    Sprint
    (Number)@messaging.sprintpcs.com

    Verizon
    (Number)@vtext.com OR (Number)@vzwpix.com

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can some one please guide me to understand which jar file i need to
Can you please guide me what is session and session variables? I don't need
I am trying to use the code from the 'Certificate,Key and trust programming guide'.
Please can anyone recommend a quick checklist / best practice guide to help us
I'm trying to connect to Informix database using sample code from https://www.ibm.com/developerworks/data/library/techarticle/dm-0510durity/ I'm using
Please guide what is meaning by Web is stateless in simple words ? Kindly
Please recommend some websites with a quick guide. MSDN is good but it's hard
Please tell me how to validate GUID in .net and it is unique for
I've tried the following code in my sample page and it doesn't work.All I'm
Can u give me the simple code snippt using org.apache.poi.ss.formula.FormulaParser. FormulaParser class having the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.