0

我正在尝试使用 curl 和 PHP 使用 fullonsms.com SMS 网关发送 SMS。

这是代码:-

 <?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 运行良好,但是当我添加 for lop 和数据库的东西以$tomobno动态设置(手机号码)时,它停止发送消息。问题是:-

我的数据库中有三个手机号码。但我没有收到任何短信。

(我已经回显了这些数字,脚本正在挑选所有这些数字。问题出在 CURL 代码上。)我是 CURL 中的 tyro。请帮助。

(请不要不必要地否决这个问题)

4

1 回答 1

0

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) );
于 2013-07-18T12:52:35.383 回答