简体   繁体   English

从数据库发送批量短信

[英]send bulk sms from database

I've been trying to use the code below to send sms but it does not send when I loop. 我一直在尝试使用下面的代码发送短信,但是当我循环时它不会发送。 It only works if I just pick one number from database. 仅当我从数据库中选择一个号码时,它才有效。 I have over 5,000 numbers in the database and wish to send an sms to all of them at the same time, Please help. 我的数据库中有5,000多个号码,希望同时向所有人发送短信,请帮助。

mysql_select_db($database_xxx, $xxx);
$query_rs = "SELECT phone FROM `notify` order by id asc LIMIT $l1 , $l2";
$rs= mysql_query($query_rs, $xxx) or die(mysql_error());
$row_rs = mysql_fetch_assoc($rs);
$totalRows_rs= mysql_num_rows($rs);

$phone = $row_rs['phone'];

// Do while loop to send sms.
while($row=mysql_fetch_assoc($rs)){


                         // Let's do some formatting and keep smiling.
    $giringirin = ereg_replace("[^0-9]", "", $phone );
    if (strlen($giringirin) == 11) { 
    $phone1=substr($giringirin, 1);
    $phone= "234$phone1";
    } elseif (strlen($giringirin) == 13){ 
    $phone = $giringirin; 
    }

extract($_POST);


//set POST variables
$url = "http://sms.xxx.com/bulksms/bulksms.php?username=$username&password=$password&message=$smsmessage&mobile=$phone&sender=$sender";
$fields = array(
        );

//url-ify the data for the POST
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string,'&');

//open connection
$ch = curl_init();

//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST,count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);
//execute post
$result = curl_exec($ch);

if ($result == '1801') { echo "SMS has also been sent to the Customer ($phone) \n";} else { echo "Oooops, No sms was sent";}

//close connection
curl_close($ch);  
}

Your code is confusing... 您的代码令人困惑...

curl_setopt($ch,CURLOPT_POST,count($fields));

CURLOPT_POST is a boolean flag. CURLOPT_POST是一个布尔标志。 Either you're doing a post, or you're not. 您正在发表文章,还是没有。 The number of fields you're posting is irrelevant. 您要发布的字段数无关。

You're building up a series of variables/values to be posted, but doing it via string operations. 您正在构建一系列要发布的变量/值,但是要通过字符串操作来实现。 CURL is perfectly capable of taking an array and doing all that for you, reducing your entire foreach loop to just CURL非常有能力获取数组并为您完成所有操作,从而将整个foreach循环简化为

curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);

You're using extract() on $_POST , which pollutes your script's variable namespace with any garbage a malicious user cares to send over - you're essentially replicating PHP's utterly moronically brain-dead register_globals all over again. 您在$_POST上使用extract() ,这会污染脚本的变量名称空间,并带有恶意用户想要发送的任何垃圾-实质上是在重新复制PHP完全荒唐的脑残register_globals

You're using ereg , which has been deprecated for approximiately 5 million internet years. 您正在使用ereg ,它已经过时了大约500万互联网年。 You should be using the preg functions insteadl 您应该改用preg函数

What happens when you run this script in the browser? 在浏览器中运行此脚本会发生什么? Blank page? 空白页? Something? 有事吗 Error? 错误?

Start by changing 从改变开始

$url = "http://sms.xxx.com/bulksms/bulksms.php?username=$username&password=$password&message=$smsmessage&mobile=$phone&sender=$sender";

to

$url = "http://sms.xxx.com/bulksms/bulksms.php?username=".$username."&password=".$password."&message=".$smsmessage."&mobile=".$phone."&sender=".$sender."";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM