Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

parse error on a simple multiple recipient email script

Status
Not open for further replies.

tippytarka

Programmer
Joined
Jul 19, 2004
Messages
115
Location
GB
i'm having some difficulty parsing this code, which sends an email to multiple recipients.

i keep on getting the following error message. what am i doing wrong??

Parse error: parse error, unexpected T_VARIABLE in /homepages/...... on line 7

line 7 is ......
 
$email_list;


Code:
<?
 // read list of emails from file.
 $email_list = file("elist.txt");

 // loop through email list
 for ($i = 0; $i < count($email_list); $i++) {
    $email_list;
    }

 // implode the list into a single variable, put commas in, apply as $to value.
 $to = implode(",",$email_list);

 $subject = "My email test.";
 $message = "Hello, how are you?";

 if ( mail($to,$subject,$message) ) {
    echo "The email has been sent!";
    } else {
    echo "The email has failed!";
    }
 ?>

cheers!
 
You posted this code
Code:
<?
// read list of emails from file.
$email_list = file("elist.txt");

// loop through email list
for ($i = 0; $i < count($email_list); $i++) {
   $email_list;
   }
and asked what was wrong?

What do you think line that reads "$email_list;" is supposed to do? That is not a valid PHP statement. Don't you want to do something with each member of the $email_list array in the for loop?
Code:
// loop through email list
for ($i = 0; $i < count($email_list); $i++) {
   $xyz = $email_list[$i];
// do somthing with $xyz
   }

Ken
 
right you are ..i've been feeling hungry all day and i'm losing my concentration ..BUT i'm still getting the same error message??

Code:
<?
 // read list of emails from file.
 $email_list = file("elist.txt");

 // loop through email list
 for ($i = 0; $i < count($email_list); $i++) {
    $xyz = $email_list[$i];
    }

 // implode the list into a single variable, put commas in, apply as $to value.
 $to = implode(",",$xyz);

 $subject = "My email test.";
 $message = "Hello, how are you?";

 if ( mail($to,$subject,$message) ) {
    echo "The email has been sent!";
    } else {
    echo "The email has failed!";
    }
 ?>
 
Code:
// loop through email list
 for ($i = 0; $i < count($email_list); $i++) {
    $xyz = $email_list[$i];
    }

1. You are not doing anything with $xyz in the loop. It goes through all cases and assigns it to a string, next email, next.... but nothing happens since the

2. The code makes no sense to me:
a) read file of email addresses into array
b) iterate each of them
c) put them back into another array ???
d) implode the new array

Why not:
a) read the file and make sure it didn't fail (!)
b) implode the array right then
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top