I have set up a blog system that allows users to post comments to blog topics. I also want users to be notified if other users have responded to their comments. Not unlike a message board system where users respond to posts in a message board.
What is happening is that when a user fills out the form that user also gets a copy of his comment as well as other's responses. I only want to make it so that a user only receives an email if others have responded.
My thought process is that $mail -> SetFrom($email, $name); which are the variables of the person who filled in the form in the phpMailer script should not equal a $row['email'], $row['name'] in the while loop but grab all other email addresses and send out the email instead.
I think that is the right logic but may be wrong.
Below is the relevant php code.
require_once('../PHPMailer_v5.1/class.phpmailer.php');
$mail = new PHPMailer ();
$mail -> IsSMTP ();
$mail -> Host = "mail.mydomain.com";
$mail -> SMTPDebug = 2; // enables SMTP debug information (for testing)
$mail -> Port = 25;
$mail -> SMTPAuth = true;
$mail -> Username = "me@mydomain.com";
$mail -> Password = "mypassword";
$mail -> SetFrom($email, $name);//who filled out the form on the web site
$mail -> AddAddress($site_owner_email, $site_owner_name); //message goes to webmaster
$mail -> Subject = 'Someone has commented on an article';
//check to see if there are previous comments to this article from other people to notify through email
$sqlComments = mysql_query("SELECT * FROM comments WHERE aid='$id'") or die(mysql_error());
while($row = mysql_fetch_assoc($sqlComments)){
$mail -> AddCC($row['email'], $row['name']);
}
$mail -> AddAddress($site_owner_email, $site_owner_name); //message goes to webmaster
$mail -> Body = ($htmlBody);
$mail -> isHTML(true);
$mail -> AltBody = ($textBody);
$mail -> send();
$mail->ClearAddresses();