Jump to content


Photo

PHP mail


  • Please log in to reply
2 replies to this topic

#1 jeliot

jeliot
  • Members
  • PipPip
  • Member
  • 23 posts

Posted 09 April 2006 - 10:44 PM

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



#2 Yesideez

Yesideez
  • Members
  • PipPipPip
  • Advanced Member
  • 2,334 posts
  • LocationDevon, UK

Posted 09 April 2006 - 10:51 PM

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:
$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>";}
}
Then close the connect at the end.

Off the top of my head, hope it works :)
Not a pro just an enthusiast :)

if (empty($coffee)) {$coffee=new coffee();}

Please surround any code using the CODE tags - I rarely look at anything without them

#3 jeliot

jeliot
  • Members
  • PipPip
  • Member
  • 23 posts

Posted 10 April 2006 - 05:42 PM

[!--quoteo(post=363132:date=Apr 9 2006, 06:51 PM:name=Yesideez)--][div class=\'quotetop\']QUOTE(Yesideez @ Apr 9 2006, 06:51 PM) View Post[/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:
$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>";}
}
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............




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users