send email when new comment posted
Posted: Mon Mar 23, 2009 2:04 am
hello,
i am looking for a little guidance... i allow users to either start a new conversation topic on other user's profile, or comment on existing conversations. my commentTable is pretty much sorted by the comment title for right now, which is another issue i needs to work out eventually, but my main question for now is this; how can i send an email to all users involved in an existing conversation when a comment is posted in that conversation?
my sql should be ok.. select * from commentTable where comment_title = $comment_title... now i just can't figure out how to structure the email script to send to all emails where $row['email']?
current email script and then the SQL:
i am looking for a little guidance... i allow users to either start a new conversation topic on other user's profile, or comment on existing conversations. my commentTable is pretty much sorted by the comment title for right now, which is another issue i needs to work out eventually, but my main question for now is this; how can i send an email to all users involved in an existing conversation when a comment is posted in that conversation?
my sql should be ok.. select * from commentTable where comment_title = $comment_title... now i just can't figure out how to structure the email script to send to all emails where $row['email']?
current email script and then the SQL:
Code: Select all
if (!$error) {
$username = $_POST['username'];
$commenttitle = $_POST['comment_title'];
$insertSQL = sprintf("INSERT INTO testComment (user_id, username, email, comment_id, comment_username, comment_title, `comment`, comment_date) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['user_id'], "int"),
GetSQLValueString($_POST['username'], "text"),
GetSQLValueString($_POST['email'], "text"),
GetSQLValueString($_POST['comment_id'], "int"),
GetSQLValueString($_POST['comment_username'], "text"),
GetSQLValueString($_POST['comment_title'], "text"),
GetSQLValueString($_POST['comment'], "text"),
GetSQLValueString($_POST['comment_date'], "defined", 'NOW()'));
mysql_select_db($database_connUser, $connUser);
$Result1 = mysql_query($insertSQL, $connUser) or die(mysql_error());
$insertGoTo = "openconversation.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
$headers = "From: me>";
$to = $_POST['email']; // user email(s) MY PROBLEM MAY BE HERE??
$subject = 'You have a new comment!';
// build message
$message = "Hello, $username!\r\n\r\n";
$message .= "A conversation you are involved in has a new post.\r\n\r\n";
$message .= "The conversation topic is: $commenttitle \r\n\r\n";
$mailSent = mail($to, $subject, $message, $headers);
header(sprintf("Location: %s", $insertGoTo));
}
}
Code: Select all
$var1_getOtherUser = "-1";
if (isset($_GET['comment_title'])) {
$var1_getOtherUser = $_GET['comment_title'];
}
mysql_select_db($database_connUser, $connUser);
$query_getOtherUser = sprintf("SELECT testComment.user_id, testComment.username, testComment.email, testComment.comment_username, testComment.comment_title FROM testComment WHERE testComment.comment_title = %s GROUP BY testComment.comment_title", GetSQLValueString($var1_getOtherUser, "int"));
$getOtherUser = mysql_query($query_getOtherUser, $connUser) or die(mysql_error());
$row_getOtherUser = mysql_fetch_assoc($getOtherUser);
$totalRows_getOtherUser = mysql_num_rows($getOtherUser);