Skip to main content

Send SMS in PHP using Way2sms API client

Way2SMS is a popular free sms service in India that offers users to send SMS to mobile numbers using internet.The service is reliable and delivers the SMS in few seconds but there is no public API available for Way2sms. But Unofficially there is an API which communicates with Way2sms and most important thing is this API still works unlike many others.


//send SMS to patient
       echo "Your messege has been sent will be deliever soon.";
        $curl = curl_init();
        $timeout = 30;
        $result = array();
        $ReciverMobile = '1234567890'; // Reciver Mobile Number
        $uid = urlencode('1234567890'); //Way2sms Userid
        $pwd = urlencode('1234567890'); //Way2sms login Password
        $msg = 'YOUR MESSAGE ';
        $autobalancer = 23;
        // Setup for login
        curl_setopt($curl, CURLOPT_URL, "http://site" . $autobalancer . ".way2sms.com/Login1.action");
        curl_setopt($curl, CURLOPT_POST, 1);
        curl_setopt($curl, CURLOPT_POSTFIELDS, "username=" . $uid . "&password=" . $pwd . "&button=Login");
        curl_setopt($curl, CURLOPT_COOKIESESSION, 1);
        curl_setopt($curl, CURLOPT_COOKIEFILE, "cookie_way2sms");
        curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
        curl_setopt($curl, CURLOPT_MAXREDIRS, 20);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($curl, 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($curl, CURLOPT_CONNECTTIMEOUT, $timeout);
        curl_setopt($curl, CURLOPT_REFERER, "http://site" . $autobalancer . ".way2sms.com/");
        $text = curl_exec($curl);
        // Check if any error occured
        if (curl_errno($curl))
            return "access error : " . curl_error($curl);
        // Check for proper login
        $pos = stripos(curl_getinfo($curl, CURLINFO_EFFECTIVE_URL), "ebrdg.action");
        if ($pos === "FALSE" || $pos == 0 || $pos == "")
            return "invalid login";
        // Check the message
        if (trim($msg) == "" || strlen($msg) == 0)
            return "invalid message";
        // Take only the first 140 characters of the message
        $msg = urlencode(substr($msg, 0, 140));
        // Store the numbers from the string to an array
        $pharr = explode(",", $ReciverMobile); //add dynamic mobile number here
        // Set the home page from where we can send message
        $refurl = curl_getinfo($curl, CURLINFO_EFFECTIVE_URL);
        $newurl = str_replace("ebrdg.action?id=", "main.action?section=s&Token=", $refurl);
        curl_setopt($curl, CURLOPT_URL, $newurl);
        // Extract the token from the URL
        $jstoken = substr($newurl, 50, -41);
        //Go to the homepage
        $text = curl_exec($curl);
        // Send SMS to each number
        foreach ($pharr as $p) {
            // Check the mobile number
            if (strlen($p) != 10 || !is_numeric($p) || strpos($p, ".") != false) {
                $result[] = array('phone' => $p, 'msg' => urldecode($msg), 'result' => "invalid number");
                continue;
            }
            $p = urlencode($p);
            // Setup to send SMS
            curl_setopt($curl, CURLOPT_URL, 'http://site' . $autobalancer . '.way2sms.com/smstoss.action');
            curl_setopt($curl, CURLOPT_REFERER, curl_getinfo($curl, CURLINFO_EFFECTIVE_URL));
            curl_setopt($curl, CURLOPT_POST, 1);
            curl_setopt($curl, CURLOPT_POSTFIELDS, "ssaction=ss&Token=" . $jstoken . "&mobile=" . $p . "&message=" . $msg . "&button=Login");
            $contents = curl_exec($curl);
            //Check Message Status
            $pos = strpos($contents, 'Message has been submitted successfully');
            $res = ($pos !== false) ? true : false;
            $result[] = array('phone' => $p, 'msg' => urldecode($msg), 'result' => $res);
        }

        // Logout
        curl_setopt($curl, CURLOPT_URL, "http://site" . $autobalancer . ".way2sms.com/LogOut");
        curl_setopt($curl, CURLOPT_REFERER, $refurl);
        $text = curl_exec($curl);
        curl_close($curl);
        return $result;
        //end sms

Comments

  1. I am expecting more interesting topics from you. And this was nice content and definitely it will be useful for many people.
    Digital Mobile Marketing
    SMS API
    SMS Marketing

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete
  3. waoo nice post regarding "Sed SMS in PHP using Way2sms API client"

    Thanks,

    Gold Tips Free Trial

    ReplyDelete
  4. such a excellent and wonderful post, thanks for sharing with us.

    NIOS Admission on Demand

    ReplyDelete
  5. Replies
    1. Hello Arijit,

      Please let me know where you get the issue using it..?

      Delete
  6. aha badaa ho gya ab developer! great work keep it up

    ReplyDelete
  7. Bulk SMS is utilized as promotional SMS and Transactional for SMS marketing. Our bulk SMS marketing solution helps you to send cheap bulk promotional SMS service provider in India. It's least expensive marketing solution to reach achieve imminent clients. MAXWELL Communication furnishes bulk SMS service with NDNC filter, so you don't have any lawful issues with NDNC Registry.Best Bulk Sms Provider In India

    ReplyDelete
  8. Yes, If you want to send large number of message in single click then this service is beneficial for you. You can easily integrate Bulk SMS API into your software and send bulk sms in few min.

    ReplyDelete
  9. This article turned out to be very gainful for me. I was searching for this all over the internet. You made my search easy, and I genuinely admire you for that. Certainly, this might be beneficial for many other learners as well. Keep sharing this tremendous articles and continue updating us.
    Website Design Agency | Website design company

    ReplyDelete
  10. Thanks for sharing this information. The most interesting part is that it provides all the required API tests and commands. This will take you only a few seconds to download and install it in your existing application or software.

    sms api php
    php sms gateway integration

    ReplyDelete
  11. Thanks for sharing the valuable information with us.These are really great and useful in all aspects,appreciated!
    PHP-MySQL Interview Questions
    Top 10 PHP Interview Questions
    PHP Functions asked in Interview

    ReplyDelete
  12. Hey Nice Blog!! Thanks For Sharing!!!Wonderful blog & good post.Its really helpful for me, waiting for a more new post. Keep Blogging!
    best java training in coimbatore
    php training in coimbatore
    best php training institutes in coimbatore

    ReplyDelete
  13. Hi, Thanks for sharing the useful source code in PHP to send SMS using Way2SMS API Client.

    Custom Web Application Development Company in Coimbatore

    ReplyDelete
  14. Our Ready php code/ script will help you to save time and efforts at a large level. Your enterprise/organization's php application can be easily integrated with our services. However, we provide ready to use bulk SMS API PHP code that helpfuls to send various information to your user's mobile.

    ReplyDelete
  15. Start Your own Software Company Without Developing any Software. Our Products Your Brand. Get Whitelabled softwares and put Your own Logo, Your Website, Your contact No. on the software and resale in market. Earn much as you can. Download Demo Softwares from Call For More info: +91-9876236634

    ReplyDelete
  16. It is amazing and wonderful to visit your site. The most interesting part is that it provides all the required API tests and commands.

    Bulk SMS API
    Bulk SMS API India

    ReplyDelete
  17. This blog is so informative for providing a valuable information about me.
    SMS API PHP Integration

    ReplyDelete
  18. Nice article. It's very helpful to me. Thank you for share with us. Can you please check my article create simple blood donation management system in PHP code.

    ReplyDelete
  19. Thank you so much for this useful information. looking more from your side to update us on more updates and advancements

    ReplyDelete
  20. UFC 248 Adesanya vs Romero Live Streaming Online
    https://issuu.com/livestream675/docs/ufc_248_adesanya_vs_romero_live_streaming_online.d
    https://issuu.com/livestream675/docs/ufc_248_adesanya_vs_romero_live_streaming_online.d
    https://medium.com/@livestream675/ufc-248-adesanya-vs-romero-live-streaming-online-2020-6ba41c15df6d?sk=f6ad974e1a1d26a571935800a5ab8f63
    https://medium.com/@livestream675/ufc-248-adesanya-vs-romero-live-streaming-online-2020-6ba41c15df6d?sk=f6ad974e1a1d26a571935800a5ab8f63
    Boxing Scott Quigg VS Jono Carroll Live Streaming Online
    https://issuu.com/livestream675/docs/boxing_scott_quigg_vs_jono_carroll_live_streaming_
    https://issuu.com/livestream675/docs/boxing_scott_quigg_vs_jono_carroll_live_streaming_
    https://medium.com/@livestream675/boxing-scott-quigg-vs-jono-carroll-live-streaming-online-a02e14c14ee6?sk=a579d95263d0595cd20e2af02ab16711
    https://medium.com/@livestream675/boxing-scott-quigg-vs-jono-carroll-live-streaming-online-a02e14c14ee6?sk=a579d95263d0595cd20e2af02ab16711
    NASCAR Ticketguardian 500 Live Streaming Online
    https://issuu.com/livestream675/docs/nascar_ticketguardian_500_live_streaming_online.do
    https://issuu.com/livestream675/docs/nascar_ticketguardian_500_live_streaming_online.do

    ReplyDelete
  21. Rare is a page like yours that uses the social platform to its true potential. I like that you have good attention to detail and are always making better posts. I am following your page for a long time and I have seen your style getting better and better as time passes. Best WordPress hosting

    ReplyDelete
  22. Si Contact Form Plugin using for captcha to setup contact form in get it proper way it make properly

    ReplyDelete
  23. fast secure contact form for setup contact form with captcha and secure in your wordpress site

    ReplyDelete
  24. Fast Secure Contact Form is replace with old si contact form plugin to using with wordpress as contact form plguin

    ReplyDelete

Post a Comment

Popular Posts