jeliot Posted April 9, 2006 Share Posted April 9, 2006 After a week and a half of researching and trial and error I'm in desperate need of some help........I can't get my script to retrieve a specific field of data from MySQL....ie.....email addresses.....and send out a email to each of the addresses......Here's the script i have now....I've changed it so many times at this point I might not even be closemysql_connect("host", "user", "password") or die(mysql_error()); mysql_select_db("test") or die(mysql_error()); $query = " SELECT email FROM email_list"; $result = mysql_query($query); $num=mysql_numrows($result); mysql_close($link); $subject = "Ggap Show Reminder"; $body = "This is a test email for Ggap New Show Reminders"; $headers = "From: jason@domain.com"; $i=0; while ($i < $num) { $email=mysql_result($result,$i,"email"); // on the line above I've tried 'email', "'email'", and "email" and still nothing mail($email,$subject,$body,$headers}; $i++; Quote Link to comment Share on other sites More sharing options...
Yesideez Posted April 9, 2006 Share Posted April 9, 2006 OK you're closing the connection to the database after running a query then counting the result. Any further calls to the database will not work as there is no longer a connection.What you need to do is keep the connection open then use something like this:[code]$header="From: Ggap <jason@domain.com>\r\n";$body="This is a test email for Ggap New Show Reminders";$subject="Ggap Show Reminder";$query=mysql_query("SELECT email FROM email_list");while ($fetch=mysql_fetch_array($query)) { $email=$fetch[email]; if (!mail($email,$subject,$body,$header)) {echo "Email failed for $email<br>";}}[/code]Then close the connect at the end.Off the top of my head, hope it works :) Quote Link to comment Share on other sites More sharing options...
jeliot Posted April 10, 2006 Author Share Posted April 10, 2006 [!--quoteo(post=363132:date=Apr 9 2006, 06:51 PM:name=Yesideez)--][div class=\'quotetop\']QUOTE(Yesideez @ Apr 9 2006, 06:51 PM) [snapback]363132[/snapback][/div][div class=\'quotemain\'][!--quotec--]OK you're closing the connection to the database after running a query then counting the result. Any further calls to the database will not work as there is no longer a connection.What you need to do is keep the connection open then use something like this:[code]$header="From: Ggap <jason@domain.com>\r\n";$body="This is a test email for Ggap New Show Reminders";$subject="Ggap Show Reminder";$query=mysql_query("SELECT email FROM email_list");while ($fetch=mysql_fetch_array($query)) { $email=$fetch[email]; if (!mail($email,$subject,$body,$header)) {echo "Email failed for $email<br>";}}[/code]Then close the connect at the end.Off the top of my head, hope it works :)[/quote]Thanks SO...................Much you where right on the money............ Quote Link to comment 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.