943,649 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 3523
  • PHP RSS
Mar 6th, 2009
0

send email on mysql db update

Expand Post »
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

PHP Syntax (Toggle Plain Text)
  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.

PHP Syntax (Toggle Plain Text)
  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.
Similar Threads
Reputation Points: 27
Solved Threads: 1
Posting Whiz
kevin wood is offline Offline
347 posts
since Feb 2008
Mar 6th, 2009
0

Re: send email on mysql db update

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

PHP Syntax (Toggle Plain Text)
  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. }
Reputation Points: 27
Solved Threads: 1
Posting Whiz
kevin wood is offline Offline
347 posts
since Feb 2008
Mar 6th, 2009
0

Re: send email on mysql db update

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.....
Reputation Points: 137
Solved Threads: 162
Posting Virtuoso
Shanti C is offline Offline
1,641 posts
since Jul 2008
Mar 6th, 2009
0

Re: send email on mysql db update

the sleep function pauses the mysql statement. i cannot see how that would solve the problem of my array not being populated.
Reputation Points: 27
Solved Threads: 1
Posting Whiz
kevin wood is offline Offline
347 posts
since Feb 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Validating input?
Next Thread in PHP Forum Timeline: PHP load balance





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC