需要帮助才能在PHP和Curl代码中找到错误

I am trying to send SMS using fullonsms.com SMS gateway using curl and PHP.

Here is the code :-

 <?php
    session_start();
    mysql_connect('localhost','root','') or die('Error connecting to database');
    mysql_select_db('SMSapp') or die('Database Selection Error');
    $query='Select * from contacts';
    $cookie_file_path = "/cookie.txt"; 
    $username="*****";
    $password="***";
    $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_file_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&LoginPassword=$password&x=16&y=14");

    $html=curl_exec($ch);        

    if($query_run=mysql_query($query))
    {
        $row_count=mysql_num_rows($query_run);
        if($row_count==0)
        {
            echo 'Zero rows received';
            die();
        }  
        else 
        {
            for($i=0;$i<3;$i++)
            {
                curl_setopt($ch, CURLOPT_URL,"http://sms.fullonsms.com/home.php");    
                curl_setopt($ch, CURLOPT_USERAGENT, $agent);
                curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_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);

                $tomobno=mysql_result($query_run,$i,'mobno');
                curl_setopt($ch, CURLOPT_POSTFIELDS, "ActionScript=%2Fhome.php&CancelScript=%2Fhome.php&HtmlTemplate=%2Fvar%2Fwww%2Fhtml%2Ffullonsms%2FStaticSpamWarning.html&MessageLength=140&MobileNos=$tomobno&Message=$message&Gender=0&FriendName=Your+Friend+Name&ETemplatesId=&TabValue=contacts");
                curl_exec($ch);
                sleep(1);
            }
        }
    }        
    $html = curl_exec($ch);
    echo $html;
?>

The script was working fine for 1 SMS but when i added the for lop and database thing to set $tomobno(mobile number) dynamically ,it stopped sending message. The problem is that :-

I have three mobile numbers in my database.But I am not getting any SMS.

(I have echoed the numbers,the script is picking all of them.The problem is with CURL code.)I am a tyro in CURL.Please Help.

(Please do not unnecessarily downvote the question)

Couple of things, change code so you can a) read it easily and b) echo out what you have created, c) urlencode the whole string after you have built it. This should help you spot the typo.

At a guess the phone number stored on the database has a space character in it, either as a prefic or suffix.

$tomobno=mysql_result($query_run,$i,'mobno');

$param = "ActionScript=\home.php&CancelScript=\home.php";
$param .= "&HtmlTemplate=\var\www\html\fullonsms\StaticSpamWarning.html&MessageLength=140";
$param .= "&MobileNos=$tomobno&Message=$message&Gender=0&FriendName=Your+Friend+Name&ETemplatesId=&TabValue=contacts";

echo $param;

curl_setopt($ch, CURLOPT_POSTFIELDS, urlencode( $param) );