php with mail!

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
rwahdan
Forum Newbie
Posts: 23
Joined: Thu Feb 12, 2009 1:49 am

php with mail!

Post by rwahdan »

i am trying to get the email addresses from my table in mysql but i cant! can someone help?
$sql2= "SELECT * FROM tbl_auth_user WHERE subid =5" or die(mysql_error());
$result2 = mysql_query($sql2) or die('Query failed. ' . mysql_error());

if (mysql_num_rows($result) > 0)
{

if ($theday == "Sunday"){

while($row = mysql_fetch_assoc($result))
{

$to = 'rwahdan@gmail.com';
$subject = 'This is the alert report';
if i do it the way it is shown above, it works and i get the email in my inbox but i want to take it from the table because i have many addresses to send to. now i am getting as many emails but sent only to rwahdan@gmail.com because i spacify only one email. how to get the emails from the table?
fredericomf
Forum Newbie
Posts: 2
Joined: Tue Mar 24, 2009 6:58 pm

Re: php with mail!

Post by fredericomf »

Hi!

We need most details about the table: fields.

Regards,
Frederico Mottinha de Figueiredo (facebook)
tech603
Forum Commoner
Posts: 84
Joined: Thu Mar 19, 2009 12:27 am

Re: php with mail!

Post by tech603 »

You would need to loop through your result and email to all the email addresses for your users.

Code: Select all

 
$sql2= "SELECT * FROM tbl_auth_user WHERE subid =5" or die(mysql_error());
$result2 = mysql_query($sql2) or die('Query failed. ' . mysql_error());
 
if (mysql_num_rows($result) > 0)
{
 
if ($theday == "Sunday"){
 
while($row = mysql_fetch_assoc($result))
{
 
foreach($result as $entry)
{
$to = $entry['email'] //or whatever your row name is
$subject = 'This is the alert report'; 
 
//any other information that should go to the user (from address ect..)
 
}
 
What the foreach loop will do is loop through your result and then run the email code for each user it finds, this should email to all users in your result :)

Hope that helps

Matthew Vass
QA Analyst
mvass@hostmysite.com
http://www.hostmysite.com?utm_source=bb
Post Reply