georgehowell Posted April 25, 2010 Share Posted April 25, 2010 hi there there seems to be lots of code out there for saving email content to a database, but what about sourcing email addresses from a database to compile mailouts? Here's my first attempt (which doesn't work), but i'm just a student (sorry)... <?php $database = "skyzone"; $username = "root"; $password = ""; // connect to database $db = new PDO("mysql:host=localhost;dbname=$database",$username,$password); //query database $result = db_query("SELECT email FROM users WHERE subscribe = '1'", $emails); while ($row = db_fetch_object($result)) { $to = $emails; $subject = "SkyZone Newsletter"; $body = "Newsletter.pdf"; if (mail($to, $subject, $body)) { echo("<p>Message successfully sent!</p>"); } else { echo("<p>Message delivery failed...</p>"); } } Does any body know? cheers, George Quote Link to comment https://forums.phpfreaks.com/topic/199637-db_query-to-email/ Share on other sites More sharing options...
ChemicalBliss Posted April 25, 2010 Share Posted April 25, 2010 $to = $emails; Grab the email from the row your looping from: $to = $row['email']; -cb- Quote Link to comment https://forums.phpfreaks.com/topic/199637-db_query-to-email/#findComment-1047856 Share on other sites More sharing options...
georgehowell Posted April 25, 2010 Author Share Posted April 25, 2010 thanx ChemicalBlis it works! you're a very considerate gentleman. May you have decades of good fortune Quote Link to comment https://forums.phpfreaks.com/topic/199637-db_query-to-email/#findComment-1047877 Share on other sites More sharing options...
oni-kun Posted April 25, 2010 Share Posted April 25, 2010 thanx ChemicalBlis it works! you're a very considerate gentleman. May you have decades of good fortune I want what he has. Quote Link to comment https://forums.phpfreaks.com/topic/199637-db_query-to-email/#findComment-1047879 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.