Take the 2-minute tour ×

In order to learn PHP my boss asked me to do some sort of project. I've done so far a To Do List & Reminder (www.frontpagewebdesign.com/newfolder) but what I'm trying to do right now is sending SMS notifications.

Because I cannot afford to buy a SMS gateway for such a small project, I decided to use my account on this website: www.sms-gratuite.ro. My trouble is the automatic Login and SMS sending with CURL.

I followed a tutorial and this is what I've done so far:


$form_vars = array();
//array for SMS sending form values

$username = '****@****.com';
$password = '********';
$loginUrl = 'http://sms-gratuite.ro/page/autentificare';
$form_vars['to'] = "076xxxxxxx"; 
//my own phone number
$form_vars['mesaj'] = "test";
//SMS text
$encoded_form_vars = http_build_query($form_vars);

//init curl
$ch = curl_init();

//Set the URL to work with
curl_setopt($ch, CURLOPT_URL, $loginUrl);

curl_setopt($ch, CURLOPT_POST, 1);

//Set the post parameters (mail and parola are the IDs of the form input fields)
curl_setopt($ch, CURLOPT_POSTFIELDS, 'mail='.$username.'&parola='.$password);

//Handle cookies for the login
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

curl_setopt ($ch, CURLOPT_USERAGENT, $user_agent);

//execute the request (the login)
$store = curl_exec($ch);

//check if the Login was succcesful by finding a string on the resulting page
if(strpos($store, "Trimite mesaj")===FALSE)
echo "logged in";
echo "not logged";

//set the landing url
curl_setopt($ch, CURLOPT_URL, 'http://sms-gratuite.ro/page/autentificare');


curl_setopt($ch, CURLOPT_URL, $postUrl);
//curl_setopt($ch, CURLOPT_HTTPHEADER,array("Expect:"));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_REFERER, $referer);
curl_setopt($ch, CURLOPT_POSTFIELDS, 'to='.$form_vars['to'].'&mesaj='.$form_vars['mesaj']);
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);

$result = curl_exec($ch);

if(strpos($result, "Mesajul a fost trimis")===FALSE)
echo "<br>sms sent";
echo "<br>sms not sent";



I don't have any errors but it surely doesn't work. First of all the login fails. Is this form a particular one and the curl cannot handle it?

share|improve this question
First of all, you should get in touch with the stuff of the website and ask for help there... or get other service offering a REST API. ...but to your question - it should work. Make sure you have all the cookies the website sets before submitting the login request... also it's possible they check user agent variable, you can try to fake it like eg. Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0) –  Kamil Šrot Nov 16 '12 at 13:08
Thanks Kamil! Done the edits and I think I managed to log in. At least that's what the browser says. Using the same method (strpos) I tried to submit the second form but it didn't get a positive result. –  Samuel Coman Nov 16 '12 at 16:35
I don't have access to the form to do the actual submit of SMS / just in general: make sure, all the HTML inputs from the form are in your CURLOPT_POSTFIELDS, inclusive the type="submit" if it has the name attribute. Also you should pass the CURLOPT_COOKIEJAR from the first call (login) as the CURLOPT_COOKIEFILE to the second call to pass the cookies get from the login call to the sms call, to fake normal access –  Kamil Šrot Nov 16 '12 at 17:00
This kind of information isn't easy to get. I added your suggestions to my script and I managed to log in. –  Samuel Coman Nov 21 '12 at 15:05
Nice to hear it worked out... :-) the reason it's not widely published is, the service providers don't like their services used in such way :-) –  Kamil Šrot Nov 21 '12 at 15:10

1 Answer 1

  1. You could to put every curl request result into a different file, say page1.html, page2.html, etc. This way you can open then in browser and see what's the exact page you got in return for your request
  2. You need to make exactly same request, as browser would do. There are browser addons like HttpFox (if you are using FireFox) that can show you all fields that were sent, all cookies and everything else related. You can compare that lists to what your curl is forming to find lacking pieces

Try theese steps and comment with further errors that you got, preferably detailed.

share|improve this answer
I got past the first point (the login) and now I am stuck at the second. I got some information about the HTTP request details from Firebug, I tried to understand it along with the curl options and think I covered all the HTTP headers. I didn't knew of such a plugin. I'll try it when I get home and I'll keep you posted. Thanks! –  Samuel Coman Nov 21 '12 at 15:09

Your Answer


