1

I've a SMS Api which send sms(not email) to my client with php. Now I'm trying to send sms from .txt file where all contact number exist:

My .txt file

shibbir, 8801678877639
babu, 8801534552503

So my while loop is look like this:

$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 );

But I get following error message:

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

My final goal is, User can send sms by uploading .txt file where all contact number exit. So once it's submit the form then sms must be send to those contact number's.

  1. Can you guys tell me why i get error message ?
  2. And it's show 2 Success confirmation but i want it's must be show 1 success confirmation.

Thanks.

8
  • 2
    These are not errors. They're notices. Also they point to specific line in code. How this code looks like? Which line is it? Commented Sep 17, 2013 at 7:56
  • what is the output of var_dump($line_of_text); ? Commented Sep 17, 2013 at 7:57
  • @MansoorkhanCherupuzha Output is : array(2) { [0]=> string(7) "shibbir" [1]=> string(14) " 8801671133639" } AND array(2) { [0]=> string(4) "babu" [1]=> string(14) " 8801534552503" } Commented Sep 17, 2013 at 7:59
  • fgetcsv returns an array, you cant then just add the <br> to it like you have Commented Sep 17, 2013 at 8:00
  • Is it working if you remove the statement $line_of_text[1] ."<BR>"; from the code? Commented Sep 17, 2013 at 8:04

4 Answers 4

1

Try this.

$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 TEST

my.txt

shibbir, 8801678877639
babu, 8801534552503

my.php (removed the call to 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>";
?>

OUTPUT

    Successfully sent your message to 8801678877639, 8801534552503
Thank You.
Sign up to request clarification or add additional context in comments.

14 Comments

Again, this will print the message 2 times which the OP does not want.
@ShankarDamodaran, yes it will print two times since their is two lines of text in the file
@Alex, let me test this in my local host.
@MansoorkhanCherupuzha, Now I don't get any error message but it's not sending SMS. You know if i want to send multiple sms then i've put comma(,) after one number like: 8801671144528, 8801547744854. So now is it the problem ? If so what can i do in my $Obj-> ?
@MansoorkhanCherupuzha, GREAT, JUST GREAT. It's showing me..Successfully sent your message to 8801675588639,8801535884503,, Thank You. I saw the double comma after last number.
|
1

try changing your code into this

$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);

Comments

1

1) Can you guys tell me why i get error message ?
2) And it's show 2 Success confirmation but i want it's must be show 1 success confirmation.

  1. They are not errors.

  2. Move the echo DIV tag out of your while loop.

Comments

0

Change this line :

$line_of_text[1] ."<BR>";  

It should be :

$line_of_text[1] .= "<BR>";       

and also your message is inside your loop , so it will be echoed more than once.

This task can be done easily using file() and explode()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.