...

View Full Version : Resolved [help] teach me how to send mail through email()



samoi
12-11-2008, 11:12 PM
hello guys,

I have a database, and it contains users with emails and other stuff.

I need to send them emails by the updates in my site, can I?

I don't want to send them one by one, I want to send them all in once!

should I use something like,




<?php
$users = "SELECT email FROM tableusers";
$SQL_users = mysql_query($users);

$send = mail($users, "subject", "email message");

if ($send) {
while ($me = mysql_fetch_assoc($send)) {
echo $me['username'];
echo "-----";
echo $me['email'];
echo "---- Has been contacted";
}
} else {
echo "Failed";
}

?>




I just made up this code right now, to be able to delevier my question !

Thank you in advance !

_Aerospace_Eng_
12-11-2008, 11:25 PM
Just move the mail() function to inside of your while loop. Searching would have yielded how to do this...

<?php
$users = "SELECT email FROM tableusers";
$result = mysql_query($users) or die(mysql_error());


while ($me = mysql_fetch_assoc($result)) {
if(mail($me['email'], "subject", "email message"))
{
echo $me['username'];
echo "-----";
echo $me['email'];
echo "---- Has been contacted";
}
else
{
echo "Failed";
}
}

?>

samoi
12-12-2008, 03:35 AM
Just move the mail() function to inside of your while loop. Searching would have yielded how to do this...

<?php
$users = "SELECT email FROM tableusers";
$result = mysql_query($users) or die(mysql_error());


while ($me = mysql_fetch_assoc($result)) {
if(mail($me['email'], "subject", "email message"))
{
echo $me['username'];
echo "-----";
echo $me['email'];
echo "---- Has been contacted";
}
else
{
echo "Failed";
}
}

?>



Very helpful,

Thanks a lot !



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum