2013-07-18 51 views
0

我想使用curl和PHP發送使用fullonsms.com SMS網關的短信。需要幫助來查找PHP和Curl代碼中的錯誤

下面是代碼: -

<?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; 
?> 

劇本是工作的罰款1個SMS但是當我加入了LOP和數據庫的事情來設置$tomobno(手機號碼)動態地,它停止發送消息。 問題是: -

我在我的數據庫中有三個手機號碼,但我沒有收到任何短信。

(我已經回覆了數字,腳本選擇了所有這些。問題出在CURL代碼上。)我是CURL中的一個tyro。請幫助。

(請不要不必要downvote問題)

+0

這裏是參考wrking API,如果它可以幫助你:https://github.com/kingster/FullonSMS-API/blob/master/fullonsms-api.php .. –

+0

@Coderanonymous:謝謝爲響應。但問題是發送多個SMS.The上面的腳本工作正常1 sms,但當我修改它多個短信,它不會發送任何短信。 –

+0

我不知道你做了哪些修改來完成這項工作,我建議的所有操作都是恢復代碼,一步步完成,並檢查它失敗的步驟。否則提及或突出顯示您正在更改的行。 –

回答

0

夫婦的事情,改變代碼,以便在出現)容易閱讀和b)回聲出你創造了什麼,C)進行urlencode整個字符串後,你有建立它。 這應該有助於您發現錯字。

猜測存儲在數據庫中的電話號碼有一個空格字符,無論是作爲prefic還是後綴。

$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));