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

  • Home
  • SEARCH
  • 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 8211113
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T10:19:09+00:00 2026-06-07T10:19:09+00:00

I am developing a script involving Php Curl to send sms using http://www.gysms.com/freesms.php The

  • 0

I am developing a script involving Php Curl to send sms using http://www.gysms.com/freesms.php
The page stores a cookie PHPSESSID and also a hidden field named token is passed during the posting.

I have written a script involving two curl requests. 1st curl request parse the page and obtain the token value .

Here is the code for that:

<?php

$phone = '9197xxxxxxx';
$msg = 'Hi this is curlpost';
$get_cookie_page = 'http://www.gysms.com/freesms.php';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $get_cookie_page);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$sabin = curl_exec($ch);
$html=explode('<input  type="hidden" name="trigger" value="',$sabin);
$html=explode('"/>',$html[1]);
//store the token value to $html[0]
?>

Curl post is done using the following code:

<?php
$fields = array(
                            'trigger'=>urlencode($html[0]), //token value
                            'number'=>urlencode($phone),  //phone no
                            'message'=>urlencode($msg) //message

                );

//posting curl request
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string,'&');
$url = 'http://www.gysms.com/freesms.php';
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt');

//execute post
$result = curl_exec($ch);
echo $result;
curl_close($ch);
?>

The sms is not sending Using the above code.
If the sms is sent It should show sms is send to-No.
I don’t Know where I went wrong. Please help, I am new to PHP.
Finally this attempt is only for my educational purpouse.

  • 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-06-07T10:19:10+00:00Added an answer on June 7, 2026 at 10:19 am

    Here is some code I came up with that worked. Hope it helps. Some explanations and feedback about your code follow.

    <?php
    
    $number     = '14155556666';
    $message    = 'This is my text in all its glory.';
    
    $url        = 'http://www.gysms.com/freesms.php';
    $cookieFile = tempnam(null, 'SMS');
    $userAgent  = 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:11.0) Gecko/20100101 Firefox/11.0';
    
    if (strlen($message) > 100) {
        die('Message length cannot exceed 100 characters.');
    }
    
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_COOKIEFILE, $cookieFile);
    curl_setopt($ch, CURLOPT_COOKIEJAR,  $cookieFile);
    curl_setopt($ch, CURLOPT_USERAGENT,  $userAgent); // empty user agents probably not accepted
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_AUTOREFERER,    1); // enable this - they check referer on POST
    
    $html = curl_exec($ch);
    
    // <input  type="hidden" name="trigger" value="CXXrtmqVC7KbUnJ22UBodFy1kBj4ign5PsQ3qNR91nH2055307b4xP4"/>
    if (!preg_match('/name=.trigger.\s+value=.([^\'"]+)/i', $html, $trigger)) {
        die('Failed to locate hidden input value');
    }
    
    sleep(5);  // without a slight delay, i often would not receive sms
    
    $trigger = $trigger[1];
    
    // build array of post values - all are important
    $post = array('number'  => $number,
                  'trigger' => $trigger,
                  'message' => $message,
                  'remLen'  => 100 - strlen($message),
                  $trigger  => 'Send Message');
    
    // switch request to POST, use http_build_query to encode post data for us
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post));
    
    $html = curl_exec($ch);
    
    if (strpos($html, '<b>Message sent to</b>') !== false) {
        echo "Message sent!";
    } else {
        echo "<b>Message not sent :(</b><br /><br />";
        echo $html;
    }
    

    I think you may have had trouble for several reasons:

    • A User-Agent should be specified in the request, they seem to reject if you leave it empty
    • I used http_build_query to build the POST string (preference)
    • You were missing 2 fields in the request, remLen, and the trigger value as the submit button
    • I often would not receive the messages if I didn’t sleep a few seconds before sending the message after getting the trigger value.

    In most of the cases where I didn’t get the message, it still showed the “Message sent to phone #” on the screen even though it never came. Once I combined all the right things (sleep time, user agent, valid post fields) I would see the success message but also get the response.

    I think the most critical thing left out from your code was that on the first request where you grab the trigger value, they also set a cookie (PHPSESSID) that you are required to capture. Without sending that on the POST request it was probably an automatic reject.

    To get around this, make sure you capture cookies on the first request as well as subsequent requests. I chose to re-use the same curl handle for both requests. You don’t have to do it that way, but you would have to use the same cookie file and cookie jar between requests.

    Hope that helps.

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

Sidebar

Related Questions

I'm developing a php script involving parsing data from xls files. I'm using library
I am developing an HTML/Javascript/JQuery page retrieving a JSON returned by a PHP script:
I am developing a script in my localhst using PHP and mysql and I
I'm developing a PHP script to send the content of a file from one
I'm creating a login script for a website i'm developing, and am using PHP
I'm developing a dependent select script using jQuery, PHP and JSON as the response.
With PHP, I am developing a script that generates a contract once the script
I am currently developing a very simple script in AutoHotKey, but it involves using
I'm developing a little script using ash shell (not bash). Now i have a
I'm developing some ajax script and using wordpress and my question is: is there

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.