whelpton Posted March 14, 2009 Share Posted March 14, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/149393-solved-taking-email-addresses-from-mysql-using-them-with-php-mail-function/ Share on other sites More sharing options...
.josh Posted March 14, 2009 Share Posted March 14, 2009 http://www.phpfreaks.com/tutorial/php-basic-database-handling Quote Link to comment https://forums.phpfreaks.com/topic/149393-solved-taking-email-addresses-from-mysql-using-them-with-php-mail-function/#findComment-784662 Share on other sites More sharing options...
Stephen68 Posted March 14, 2009 Share Posted March 14, 2009 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; } Quote Link to comment https://forums.phpfreaks.com/topic/149393-solved-taking-email-addresses-from-mysql-using-them-with-php-mail-function/#findComment-784663 Share on other sites More sharing options...
whelpton Posted March 14, 2009 Author Share Posted March 14, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/149393-solved-taking-email-addresses-from-mysql-using-them-with-php-mail-function/#findComment-784675 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.