Jump to content

Archived

This topic is now archived and is closed to further replies.

jeliot

PHP mail

Recommended Posts

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 close

mysql_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++;

Share this post


Link to post
Share on other sites
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 :)

Share this post


Link to post
Share on other sites
[!--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............

Share this post


Link to post
Share on other sites

×

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.