Jump to content

[SOLVED] Taking email addresses from mysql & Using them with php mail function.


whelpton

Recommended Posts

Hi everyone,

 

Okay, titles pretty self explanitory, I'm trying to take email addresses from a mysql database and insert them into a mail script, to create a mass mail ability so that I can contact my members easilly.

 

I presume it would be easier to use a variable such as '$email' to list everyone mail addresses, this might not be true...

 

$send = mail($email , "Subject" , "Generic Email Topic", "FROM: [email protected]");

 

But, how do I insert email addresses from the mysql database into the code?

 

My mysql table name is 'Users' and the row for email addresses is 'Email'.

 

Thanks for your time

I found this code here http://forums.devarticles.com/php-development-48/mass-mail-with-php-1071.html and cut and pasted it below, should be able to modify it to your needs

 

function sendMail() {
$subject = "";
$message = "";
$toAddr = "";
$sql = SELECT DISTINCT email FROM members;
$result = mysql_query($sql);
while ($row = mysql_fetch_row($result)) {
    $toAddr .= "$row[0];";
   }
if (mail($toAddr,$subject,$message)) return true;
else return false;
}  

Okay, thanks for the help.

 

Ive managed to cobble together this but it dosnt seem to be sending anything.

$subject = trim(addslashes($_POST['Subject']));
$message = trim(addslashes($_POST['Message']));
$toAddr = "";
$result = mysql_query("SELECT Email FROM Users") or die(mysql_error());
while ($row = mysql_fetch_row($result)) {
    $toAddr .= "$row[0];";
   }
(mail($toAddr,$subject,$message,'[email protected]'));


echo '<script>location.replace("index.php");</script>';

 

Any suggestions?

 

Thanks

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.