Send emails to all member in database table

the mail() function

Moderators: macek, egami, gesf

Post Reply
ZetaPrints
New php-forum User
New php-forum User
Posts: 8
Joined: Tue Feb 01, 2011 11:56 pm

Re: Send emails to all member in database table

Post by ZetaPrints » Mon May 02, 2011 9:23 am

You can make use of PHP's mail() function to send an email for every data fetched by your query. Your code might look something like this:

Code: Select all

$query  = "SELECT email FROM contacts";
$result = mysql_query($query);

while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
	$to = $row['email'];  // from your database
 	$subject = "Hello";
 	$content = "Content of Email";
 
	if (mail($to, $subject, $body)) {
   		echo("<p>Message successfully sent!</p>");
  	} else {
   		echo("<p>Message delivery failed...</p>");
  	}
} 

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests