for loop problem

From: Date: Wed, 20 Mar 2002 20:07:35 +0000
Subject: for loop problem
Groups: php.general 
Request: Send a blank email to php-general+get-89391@lists.php.net to get a copy of this message
I have a problem with a piece of code that uses the mail function in a for loop. It sends out mail to all the users in the database but it has a problem with attaching their specific name into the message. What happens is the first user in the database will get their name in the e-mail (Dear John,). Then the second user in the database will get the last users name and their name in the e-mail (Dear John, Dear Mike) ....and so on and so forth. How do I fix this problem? Your help is appreciated. Here is the code: If ($button != "") { $t = mysql_query("SELECT * from AddExisting"); $number_of_customers = mysql_num_rows($t); for($i=0; $i<$number_of_customers;$i++) { $r = mysql_fetch_array($t); $email = $r["EMAIL_ADDRESS"]; $cusname = $r["Name"]; $to = $email; $subject = "hello"; $message = "Dear $cusname,".$message; $fromaddress = "me@you.com"; mail($to, $subject, $message, $fromaddress); }//end of for }//end of if

« previous php.general (#89391) next »