dear fine fellows, saving email content to a database seems common, but how about compiling emails from database content?? Here's my attempt, which isn't working unfortunately (but i'm still at school, sorry). Any hints? <?php $database = "skyzone"; $username = "root"; $password = ""; // connect to database $db = new PDO("mysql:host=localhost;dbname=$database",$username,$password); $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>"); } } cheers, george
This line $to = $emails; PHP: May not be correct. You may need to use something like $to = $row['email']; PHP:
Thanx Brad I keep getting this: "Fatal error: Call to undefined function db_query() in C:\wamp\www\SkyZone\emailNewsletter.php on line 8" $result = db_query("SELECT email FROM users WHERE subscribe = '1'", ?); //line_08 any clues?
To be honest, I didn't understand some of your code because I usually do things differently. I rewrote your code, test it and let me know how it goes... <?php $database = "skyzone"; $username = "root"; $password = ""; // connect to database mysql_connect( 'localhost', $username, $password ); mysql_select_db( $database ); $result = mysql_query("SELECT email FROM users WHERE subscribe = '1'"); while ($row = mysql_fetch_row($result)) { $to = $row[0]; $subject = "SkyZone Newsletter"; $body = "Newsletter.pdf"; if (mail($to, $subject, $body)) { echo "<p>Message successfully sent!</p>"; } else { echo "<p>Message delivery failed...</p>"; } } ?> PHP:
GOT IT!!! cheers Brad, thanx a mil only a small prob with my smtp/outgoing mail settings now - but i'll try it out on my mac now, which'll by-pass this prob your a top bloke! thankx regards, george
Yeah, you usually needs some additional config before you can send emails out if its just a home pc. Best of luck with your scripts, if you need anything more im available via PM. Don't mind helping a few people out
You are using object method. So you can get database fields like $row->email (email is your database field) Please check this reference URL http://php.net/manual/en/function.mysql-fetch-object.php For mail, I use phpmailer class that you can download from www.phpclasses.org