Page 1 of 1

How to send Mail to email addresses in mysql table

Posted: Thu May 21, 2015 7:38 am
by adsegzy
Hello Friend,

I tried sending mail to the 30 email addresses in mysql table with the below code. But the problem am having is that, the code is sending the same mail to all the emails 30 times.

Code: Select all


$get_emails = mysql_query("SELECT email FROM customers");
						
while($row = mysql_fetch_array($get_emails)){
	 $email = $row[email];

	mail($email, $sub, nl2br($message), $headers);
}
I also tried something like this but still gave the same result.

Code: Select all


$get_emails = mysql_query("SELECT email FROM customers");
						
$all_emails = array();
while($row = mysql_fetch_array($get_emails)){
	 $all_emails[] = $row[email];
 }
	foreach($all_emails as $to_email){
	mail($to_email, $sub, nl2br($message), $headers);
}
}
Pls what's the way out

Thanks

Re: How to send Mail to email addresses in mysql table

Posted: Thu May 21, 2015 11:24 am
by requinix
The first one is correct and the second is functionally identical.

If you look at all the "email"s in the "customers" table, what do you see? Does it look right?

Re: How to send Mail to email addresses in mysql table

Posted: Thu May 21, 2015 9:11 pm
by adsegzy
Thanks Spammer :|,

The emails in customers are ok. Just that it sends to all the 30 emails 30 times. Noe the emails has increased to 34, it will sent the same email to them 34 times.

Re: How to send Mail to email addresses in mysql table

Posted: Thu May 21, 2015 9:33 pm
by adsegzy
Thanks,
I have sorted it out

Re: How to send Mail to email addresses in mysql table

Posted: Thu May 21, 2015 9:36 pm
by requinix
I'm guessing you had another loop, not included in the code you posted, that was running once for each member?