Jump to content

PHP mail


jeliot

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

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.