Page 1 of 1

Email to Multiple Recipients from DB

Posted: Sat Apr 17, 2004 8:12 am
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!

Posted: Sat Apr 17, 2004 8:20 am
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.....

Posted: Sat Apr 17, 2004 9:00 am
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);
}

Posted: Sat Apr 17, 2004 9:21 am
by ehause
You guys are awesome! Thanks!