Jump to content

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


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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.