send email on mysql db update

Thread Solved

Join Date: Feb 2008
Posts: 347
Reputation: kevin wood is an unknown quantity at this point 
Solved Threads: 1
kevin wood's Avatar
kevin wood kevin wood is offline Offline
Posting Whiz

send email on mysql db update

 
0
  #1
Mar 9th, 2009
i am trying to get this code to work but there is something wrong with the array (not to good at these). the main part of the code works it is sending out the email but only ever to one registered user.

here is the code i have so far.

  1. $query = "SELECT email FROM emails";
  2. $result = mysql_query($query) or die(mysql_error());
  3.  
  4. while($row = mysql_fetch_array($result)) {
  5.  
  6. $contactemail = $row['email'];
  7.  
  8.  
  9.  
  10.  
  11. // Contacts
  12. //$replyName = $merc_replyId;
  13. //$replyEmail = $merc_replyAddress;
  14.  
  15. $replyName = "PiPonliine";
  16. $replyEmail = "info@piponline.info";
  17.  
  18. $contactname = "";
  19.  
  20.  
  21. // Subject
  22. $subject = "Website Update";
  23.  
  24. // Headers
  25. $headers = "MIME-Version: 1.0" . PHP_EOL;
  26. $headers .= "Content-type: text/html; charset=iso-8859-1" . PHP_EOL;
  27. $headers .= "From: ".$replyName." <".$replyEmail.">" . PHP_EOL;
  28. $headers .= "BCC: ".$contactname." <".$contactemail.">\r\n" . PHP_EOL;
  29.  
  30.  
  31. mail($contactemail, $subject, $message, $headers);
  32. }
  33. echo "$contactemail";
  34. echo "<h2>Email notification sent</h2>";
  35. echo "<h2>1 record added</h2>";
  36.  
  37. mysql_close($con);
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 83
Reputation: ahmksssv is an unknown quantity at this point 
Solved Threads: 7
ahmksssv ahmksssv is offline Offline
Junior Poster in Training

Re: send email on mysql db update

 
0
  #2
Mar 9th, 2009
[QUOTE=kevin wood;821441]i am trying to get this code to work but there is something wrong with the array (not to good at these). the main part of the code works it is sending out the email but only ever to one registered user.



Hi..
i dont know the exact solution....but, try to do this...

1) if there is any id in database, try to using id by incrementing.......
2) try to use FOREACH instead of while......


this is just try, i dont know the exact way.....
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 347
Reputation: kevin wood is an unknown quantity at this point 
Solved Threads: 1
kevin wood's Avatar
kevin wood kevin wood is offline Offline
Posting Whiz

Re: send email on mysql db update

 
0
  #3
Mar 9th, 2009
a foreach loop will need to start with a while loop and i do not see the need to use the id of the table as i only need to loop through the email address and user these to send the email.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3,760
Reputation: nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough 
Solved Threads: 332
Moderator
Featured Poster
nav33n's Avatar
nav33n nav33n is offline Offline
Senior Poster

Re: send email on mysql db update

 
1
  #4
Mar 10th, 2009
@Kevin wood, Your script seems fine.
Try this.
  1. $query = "SELECT email FROM emails";
  2. $result = mysql_query($query) or die(mysql_error());
  3.  
  4. while($row = mysql_fetch_array($result)) {
  5.  
  6. $emailaddress[] = $row['email'];
  7. }
  8.  
  9.  
  10. // Contacts
  11. //$replyName = $merc_replyId;
  12. //$replyEmail = $merc_replyAddress;
  13. $i=0;
  14. foreach($emailaddress as $contactemail) {
  15. $replyName = "PiPonliine";
  16. $replyEmail = "info@piponline.info";
  17.  
  18. $contactname = "";
  19.  
  20.  
  21. // Subject
  22. $subject = "Website Update";
  23.  
  24. // Headers
  25. $headers = "MIME-Version: 1.0" . PHP_EOL;
  26. $headers .= "Content-type: text/html; charset=iso-8859-1" . PHP_EOL;
  27. $headers .= "From: ".$replyName." <".$replyEmail.">" . PHP_EOL;
  28. $headers .= "BCC: ".$contactname." <".$contactemail.">\r\n" . PHP_EOL;
  29.  
  30.  
  31. mail($contactemail, $subject, $message, $headers);
  32. $i++;
  33. }
  34. echo "$contactemail"; //this will print only 1 email address, which is the last one
  35. echo "<h2>Email notification sent</h2>";
  36. echo "<h2>".$i." mails sent</h2>";
This definitely works. (I tried with 3 email addresses)
Ignorance is definitely not bliss!

*PM asking for help will be ignored*
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 347
Reputation: kevin wood is an unknown quantity at this point 
Solved Threads: 1
kevin wood's Avatar
kevin wood kevin wood is offline Offline
Posting Whiz

Re: send email on mysql db update

 
0
  #5
Mar 10th, 2009
thank you for the reply i ended up getting it working late last night with a similar piece of code. thank you again for the reply.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3,760
Reputation: nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough 
Solved Threads: 332
Moderator
Featured Poster
nav33n's Avatar
nav33n nav33n is offline Offline
Senior Poster

Re: send email on mysql db update

 
0
  #6
Mar 10th, 2009
You are welcome.. Cheers man!
Ignorance is definitely not bliss!

*PM asking for help will be ignored*
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC