send email on mysql db update

Reply

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 6th, 2009
i am trying to write a script that will send out an email to all the email addresses stored in a mysql db when the site has been updated. the code i have so far is as follows

  1. $sql= "INSERT INTO $table (date, title, article) VALUES ('$a', '$b', '$c')";
  2.  
  3. if (!mysql_query($sql,$con))
  4. {
  5. die('Error: ' . mysql_error());
  6. }
  7. $lastid = mysql_insert_id();
  8.  
  9. $message .= '<body leftmargin="0" topmargin="0">
  10. <table width="700" border="0" align="center" cellpadding="0" cellspacing="5">
  11. <tr>
  12. <td>The ' . $table . ' section of the <a href="piponline.info"> PiPonline website</a> has been updated. Please follow the link to see the new content.
  13. </tr>
  14. </table>
  15. </body>';
  16.  
  17.  
  18. $query = "SELECT email FROM emails";
  19. $result = mysql_query($query) or die(mysql_error());
  20.  
  21. while($row = mysql_fetch_array($result)){
  22. $contactemail = $row['email']. ", ";
  23. }
  24.  
  25.  
  26.  
  27. // Contacts
  28. //$replyName = $merc_replyId;
  29. //$replyEmail = $merc_replyAddress;
  30.  
  31. $replyName = "PiPonliine";
  32. $replyEmail = "info@piponline.info";
  33.  
  34. $contactname = "";
  35.  
  36.  
  37. // Subject
  38. $subject = "Website Update";
  39.  
  40. // Headers
  41. $headers = "MIME-Version: 1.0" . PHP_EOL;
  42. $headers .= "Content-type: text/html; charset=iso-8859-1" . PHP_EOL;
  43. $headers .= "From: ".$replyName." <".$replyEmail.">\r\n" . PHP_EOL;
  44. $headers .= "BCC: ".$contactname." <".$contactemail.">\r\n" . PHP_EOL;
  45.  
  46.  
  47. mail(implode(',', $contactemail), $subject, $message, $headers);
  48. echo "$contactemail";
  49. echo "<h2>Email notification sent</h2>";
  50. echo "<h2>1 record added</h2>";
  51.  
  52. mysql_close($con);

this code is giving me the following error message which as far as i know means that array is not being populated.

  1. Warning: implode(): Bad arguments

due to the error the emails are not being sent even if the code for that section is correct or not.
Last edited by kevin wood; Mar 6th, 2009 at 7:47 am.
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
  #2
Mar 6th, 2009
i have changed the code slightly now and have got it sending out one email. i have narrowed the problem down to the mysql query as this is not populating the array it is only putting on email address in.

here is the code for the mysql statement

  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[0]. ", ";
  7. }
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 1,076
Reputation: Shanti Chepuru is on a distinguished road 
Solved Threads: 98
Shanti Chepuru's Avatar
Shanti Chepuru Shanti Chepuru is offline Offline
Veteran Poster

Re: send email on mysql db update

 
0
  #3
Mar 6th, 2009
If you have a long number of mails in your db, then it is better to use sleep function to avoid overload of server....
Read more about this on gooogle.....
Be intelligent, But Don't try to cheat.. Be innocent But Don't get cheated..
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
  #4
Mar 6th, 2009
the sleep function pauses the mysql statement. i cannot see how that would solve the problem of my array not being populated.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 982 | Replies: 3
Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC