How do I work this out so I can mail to all the matches I get from my database?
PHP Code:$email_list = mysql_query("SELECT mail FROM Users WHERE updateme='Yes'");
$mail_body = "New Mail";
$subject = "Hello";
mail($email_list, $subject, $mail_body);
| SitePoint Sponsor |
How do I work this out so I can mail to all the matches I get from my database?
PHP Code:$email_list = mysql_query("SELECT mail FROM Users WHERE updateme='Yes'");
$mail_body = "New Mail";
$subject = "Hello";
mail($email_list, $subject, $mail_body);




Just using mysql_query like that won't yield the expected results.
You need something like this:
Code PHP:$mail_body = "New Mail"; $subject = "Hello"; $result = mysql_query("SELECT mail FROM Users WHERE updateme='Yes'"); while($row = mysql_fetch_assoc($result) { mail($row['mail'], $subject, $mail_body); }
This also assumes you have set up the MySQL connection correctly.
PHP Code:<?php
set_time_limit(0);
ini_set("display_errors", 1);
error_reporting(E_ALL);
mysql_connect("localhost", "users", "pass") or die(mysql_error());
mysql_select_db("db") or die(mysql_error());
$email_list = mysql_query("SELECT mail FROM Users WHERE updateme='Yes'") or die(mysql_error());
function fetch_all_array($query_string)
{
$out = array();
while ($row = mysql_fetch_array($query_string))
{
$out[] = $row;
}
return $out;
}
$all_rows = fetch_all_array($email_list);
foreach ($all_rows as $key)
{
$text[] = $key['mail'];
}
// send a copy to you
$to = "you@host.com";
$list = implode(",", $text);
$subject = "reminder";
$message = "hello!";
$headers = "From: webmaster@host.com \r\n" .
"Reply-To: webmaster@host.com \r\n" .
"Bcc: $list\r\n";
$headers .= "X-Mailer: PHP/" . phpversion();
mail($to, $subject, $message, $headers);
my mobile portal
ghiris.ro
Bookmarks