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 = "[EMAIL PROTECTED]";
                        
                        mail($to, $subject, $message, $fromaddress);
                        }//end of for
}//end of if


Reply via email to