943,974 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Marked Solved
  • Views: 1095
  • PHP RSS
Mar 9th, 2009
0

send email on mysql db update

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

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['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);
Similar Threads
Reputation Points: 27
Solved Threads: 1
Posting Whiz
kevin wood is offline Offline
347 posts
since Feb 2008
Mar 9th, 2009
0

Re: send email on mysql db update

[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.....
Reputation Points: 11
Solved Threads: 7
Junior Poster in Training
ahmksssv is offline Offline
84 posts
since Feb 2009
Mar 9th, 2009
0

Re: send email on mysql db update

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.
Reputation Points: 27
Solved Threads: 1
Posting Whiz
kevin wood is offline Offline
347 posts
since Feb 2008
Mar 10th, 2009
1

Re: send email on mysql db update

@Kevin wood, Your script seems fine.
Try this.
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. $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)
Moderator
Featured Poster
Reputation Points: 524
Solved Threads: 356
Purple hazed!
nav33n is offline Offline
3,878 posts
since Nov 2007
Mar 10th, 2009
0

Re: send email on mysql db update

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.
Reputation Points: 27
Solved Threads: 1
Posting Whiz
kevin wood is offline Offline
347 posts
since Feb 2008
Mar 10th, 2009
0

Re: send email on mysql db update

You are welcome.. Cheers man!
Moderator
Featured Poster
Reputation Points: 524
Solved Threads: 356
Purple hazed!
nav33n is offline Offline
3,878 posts
since Nov 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

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: IP Penguin Shower
Next Thread in PHP Forum Timeline: Check out the code ...





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


Follow us on Twitter


© 2011 DaniWeb® LLC