【发布时间】:2013-07-17 08:31:02
【问题描述】:
我正在尝试使用 curl 和 PHP 使用 fullonsms.com 短信网关发送短信。
这里是代码:-
<?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。请帮助。
(请不要不必要地否决这个问题)
【问题讨论】:
-
这里是 wrking api 供参考,如果它可以帮助你:github.com/kingster/FullonSMS-API/blob/master/fullonsms-api.php..
-
@Coderanonymous:感谢您的回复。但问题是发送多条短信。上面的脚本在 1 条短信中运行良好,但是当我为多条短信修改它时,它不会发送任何短信。
-
我不知道你做了什么修改才能让它工作,我建议的只是恢复代码,一步一步地进行,并检查它在哪一步失败。否则提及或突出显示您正在更改的行。
-
@Coderanonymous :我刚刚添加了for循环和数据库的东西来动态设置
$tomobno。其余的都是一样的。 -
不确定,但也许您也应该在循环中使用
curl_init()和curl_exec()。
标签: php curl sms-gateway