我有一个SMS Api,发送短信(而不是电子邮件)给我的客户与php。现在,我正在尝试从.txt文件发送短信,所有联系人号码都在这里:
我的.txt文件
shibbir, 8801678877639
babu, 8801534552503,所以我的while循环如下所示:
$file_handle = fopen("$file", "r");
while ( !feof( $file_handle ) ) {
$line_of_text = fgetcsv($file_handle, 1024);
$line_of_text[1] ."<BR>";
$obj = new Sender("myservername","myport","username","password","$sender", "$msg",
"$line_of_text","2","1");
$obj->Submit();
echo "<div class='success'>Successfully sent your message to " . $line_of_text[1] . " Thank
You.</div>";
}
fclose( $file_handle );,但我得到以下错误消息:
Notice: Array to string conversion in D:\Software Installed\xampp\htdocs\evan\toplevel
\bulksms.php on line 108
Notice: Undefined offset: 1 in D:\Software Installed\xampp\htdocs\evan\toplevel\bulksms.php on
line 106
Notice: Undefined offset: 1 in D:\Software Installed\xampp\htdocs\evan\toplevel\bulksms.php on
line 107我的最终目标是,用户可以通过上传.txt文件发送短信,所有联系人号码退出。因此,一旦它提交了表格,那么短信必须发送到那些联系电话号码。
谢谢。
发布于 2013-09-17 08:05:08
尝尝这个。
$file_handle = fopen("$file", "r");
$success_number = array();
while ( !feof( $file_handle ) ) {
$line_of_text = fgetcsv($file_handle, 1024);
$success_number[]=$line_of_text[1]; //call this statement if msg sent successfully.
$line_of_text = implode(',',$line_of_text ); // i think we need to pass string to the api.
$obj = new Sender("myservername","myport","username","password","$sender", "$msg",
"$line_of_text","2","1");
$obj->Submit();
}
echo "<div class='success'>Successfully sent your message to ".implode(',',$success_number) ."<BR> Thank You.</div>";
fclose( $file_handle );我的测试
my.txt
shibbir, 8801678877639
babu, 8801534552503my.php (删除了对api的调用)
<?php
$file = "my.txt";
$file_handle = fopen($file, "r");
$success_number = array();
while ( !feof( $file_handle ) ) {
$line_of_text = fgetcsv($file_handle, 1024);
$success_number[]=$line_of_text[1]; //call this statement if msg sent successfully.
}
fclose( $file_handle );
echo "<div class='success'>Successfully sent your message to " . implode(',',$success_number) ."<BR> Thank You.</div>";
?>输出
Successfully sent your message to 8801678877639, 8801534552503
Thank You.发布于 2013-09-17 08:00:15
尝试将您的代码更改为
$file_handle = fopen("$file", "r");
while (!feof($file_handle) )
{
$line_of_text = fgetcsv($file_handle, 1024);
$line_of_text[1]=$line_of_text[1] ."<BR>";
$obj = new Sender("myservername","myport","username","password","$sender", "$msg",
$line_of_text[1],"2","1");
$obj->Submit();
echo "<div class='success'>Successfully sent your message to " . $line_of_text[1] . " Thank
You.</div>";
}
fclose($file_handle);发布于 2013-09-17 08:01:00
( 1)你们能告诉我为什么会收到错误信息吗? 2)这是显示2成功确认,但我希望它必须是显示1成功确认。
echo DIV标记移出while循环。https://stackoverflow.com/questions/18844257
复制相似问题