title: Sending free sms using PHP
body: <p>I am trying to develop a PHP based application to send sms across India to contacts picked from the database. After searching for hours, I found the following working (I tested it) script which makes use of <code>fullonsms.com</code> as sms gateway but it sends a single message at a time and then loads the homepage.
  But I don't know a lot about curl. </p>
  
  <p>So </p>
  
  <ol>
  <li>I need help to understand what is actually being done.</li>
  <li>Secondly,how can I modify it to optimally send sms to multiple people(like will it be optimal to put it in a loop) without wasting data or unnecessary page loads.
  3.After sending each SMS ,it loads homepage.So won't it try to load the homepage before sending SMS.If yes,can I remove the starred(** **) line to prevent this.</li>
  </ol>
  
  <p>Here is my code:</p>
  
  <pre><code>&lt;?php
      $cookie_file_path = "/cookie.txt"; 
      $username="username";
      $password="password";
      $tomobno="1234567890";
      $message=urlencode("Hi buddy");  
  
            $agent = "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.12) Gecko/20050915 Firefox/1.0.7";
          $ch = curl_init();
          curl_setopt($ch, CURLOPT_URL,"http://sms.fullonsms.com/login.php");    
          curl_setopt($ch, CURLOPT_USERAGENT, $agent);
          curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_fie_path);
          curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);
          curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
          curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
          curl_setopt($ch, CURLOPT_HEADER, 1);
          curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
          curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
          curl_setopt($ch, CURLOPT_POSTFIELDS, "MobileNoLogin=$username&amp;LoginPassword=$password&amp;x=16&amp;y=14");
          $html=curl_exec($ch);
          **curl_setopt($ch, CURLOPT_URL,"http://sms.fullonsms.com/home.php");**
          curl_setopt($ch, CURLOPT_USERAGENT, $agent);
          curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_fie_path);
          curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);
          curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
          curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
          curl_setopt($ch, CURLOPT_HEADER, 1);
          curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
          curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
          curl_setopt($ch, CURLOPT_POSTFIELDS, "ActionScript=%2Fhome.php&amp;CancelScript=%2Fhome.php&amp;HtmlTemplate=%2Fvar%2Fwww%2Fhtml%2Ffullonsms%2FStaticSpamWarning.html&amp;MessageLength=140&amp;MobileNos=$tomobno&amp;Message=$message&amp;Gender=0&amp;FriendName=Your+Friend+Name&amp;ETemplatesId=&amp;TabValue=contacts");
  
            $html = curl_exec($ch);
            echo $html;
  ?&gt;
  </code></pre>
  
  <p>There's is a similar question asked but answer accepted is off the topic and it uses a different gateway <a href="https://stackoverflow.com/questions/7360010/sms-sending-through-free-gateway">SMS sending through free gateway</a></p>