Re: for loop problem

From: Date: Wed, 20 Mar 2002 20:07:26 +0000
Subject: Re: for loop problem
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-89394@lists.php.net to get a copy of this message
Opps, last messages had the definition of $originalMessage in the wrong place. Try this: If ($button != "") { $t = mysql_query("SELECT * from AddExisting"); $number_of_customers = mysql_num_rows($t); $originalMessage = $message; 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,".$originalMessage; $fromaddress = "me@you.com"; mail($to, $subject, $message, $fromaddress); }//end of for }//end of if * * Cal Evans * Techno-Mage * http://www.calevans.com * ----- Original Message ----- From: "Kris Vose" <KVose@alidaconnection.com> To: <php-general@lists.php.net> Sent: Wednesday, March 20, 2002 2:07 PM Subject: [PHP] for loop problem 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 (#89394) next »