Email to Multiple Recipients from DB

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ehause
Forum Newbie
Posts: 9
Joined: Sat Apr 17, 2004 8:12 am

Email to Multiple Recipients from DB

Post by ehause »

Hi:

I need some advice on how to handle this function of emailing contents of an online form to multiple recipients in a database.

I have an online inquiry form that collects info from a visitor. Upon submission, an email containing the info in a formatted email goes to all active email addresses from the database.

Ideas? Thanks so much in advance!
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

well the most simplest way (without opening sockets) would be something like:

Code: Select all

// pseudo code
$query = "SELECT email FROM mytable";
$result = mysql_query($query) or die (mysql_error());
$array1 = mysql_fetch_array($result, MYSQL_ASSOC);
// now mail the first user we'll later do the rest
mail("$array1[email]", "Subject Here", "Message HERE");
// now loop
while ($array2 = mysql_fetch_assoc($result)) 
// and send
mail("$array2[email]", "Subject Here", "Message HERE");
something along these lines would work.....
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

Code: Select all

// more psuedo code
$result = mysql_fetch_array(mysql_query("select email from table"));
for ($i=0;$i<=count($result);$i++) {
 mail($result[$i], $subject, $message);
}
ehause
Forum Newbie
Posts: 9
Joined: Sat Apr 17, 2004 8:12 am

Post by ehause »

You guys are awesome! Thanks!
Post Reply