Page 1 of 1

Email when post matches other post

Posted: Thu Sep 24, 2009 12:24 pm
by ninethousandfeet
Hi,

My users make posts to buy or sell stuff. I want to email/notify a user when there is a similar post to theirs in an effort to increase traffic.
Right now, I have the SQL and the email script below. The user fills out a new post and is taken to a post confirmed page, which is where this script is laid out. The results, only the user that made the post is receiving the email to say 'hey, there is a new post you might like.' This is pretty much the opposite of what I want, but I am stuck.
I want every user with a similar post_title or product_name EXCEPT the posting user to receive an email, any ideas? I will provide more info if that will help, thank you!

Code: Select all

 
$var1_getProduct = "-1";
if (isset($_COOKIE['newpost'])) {
  $var1_getProduct = $_COOKIE['newpost'];
}
$var2_getProduct = "-1";
if (isset($_COOKIE['newproduct'])) {
  $var2_getProduct = $_COOKIE['newproduct'];
}
 
mysql_select_db($database_connUser, $connUser);
$query_getProduct = sprintf("SELECT postingTable.postID, postingTable.post_title, postingTable.product_name, postingTable.userID, postingTable.post_date, postingTable.buy_or_share, postingTable.image_data, postingTable.image_type, postingTable.valid, postingTable.pricerange, userTable.userID, userTable.username, userTable.email FROM postingTable JOIN userTable ON postingTable.userID = userTable.userID WHERE postingTable.post_title LIKE %s OR postingTable.product_name LIKE %s", GetSQLValueString($var1_getProduct, "text"), GetSQLValueString($var2_getProduct, "text"));
$getProduct = mysql_query($query_getProduct, $connUser) or die(mysql_error());
$row_getProduct = mysql_fetch_assoc($getProduct);
$totalRows_getProduct = mysql_num_rows($getProduct);
 
do {
$email = $row_getProduct['email'];
$subject = "You might like this post";
$headers  = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type: text/html; charset=UTF-8" . "\r\n";
$headers .= "From:me<me@mysite.com>" . "\r\n";
$headers .= "Reply-To:me<me@mysite.com>" . "\r\n";
$message = "
Check out this post...";
  mail($email, $subject, $message, $headers);
} while ($row_getProduct = mysql_fetch_assoc($getProduct));