I’m extremely new to PHP and my first project was developing a comment system. So now it is great but I would like to give the commenters the choice to get emails when there is a new comment. First I decide to create another row in my table called:
’email_notifications’. In the submit.php for the comment form.
To email everyone…. I wan’t to use:
$emails = mysql_query("SELECT * FROM email_notifications");
while($row=mysql_fetch_assoc($emails)) {
mail($row['email'],'New Comment on...','There was a new comment o....',"From: no-reply@jdrag.x10.mx");
}
I’m not even sure this would work. But my first concern was that it was going to email people more than once.
Because, if people comment more than once with the same email, wont it just email that email more than once when it goes though the database for all the emails. Thats my big concern. Anyway I could email people when there is a new comment without email people more than once each time there is a new comment.
Summary(what I want to accomplish):
1. Someone submits a comment.
2. everyone above gets an email
I hope I made myself clear. If not, I apologize. Thanks in advance. Remember, im still a beginner 🙂
Assuming your table contains everyones email address this should work:
However I would try to use Prepared Statments or Stored Proceedures for your database calls.
Heres the same example using Prepared Statements: