我正在尝试使用 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。请帮助。
(请不要不必要地否决这个问题)