Forum Post E Mail

I’m trying to create a code that upon a member posting to a forum that someone else has already started will send a notification e mail to everyone involved with the forum except for the person that just made the post.

The script needs to limit the e mails to once per user incase they have previously posted to that forum many times so they won’t receive multiple e mails at once.

Below is a sample script that gets me to the point where I now need to use something like a foreach or while and input the e mail information. It works great but once I put either a while or foreach on it the script either has errors or will run forever. Any help would be great!



$get_users = “SELECT created_by FROM forumPosts WHERE topic_id=’$topic_id’ AND created_by!=’$name’”;

$run_get_users = mysql_query(”$get_users”);

$get_all_users = mysql_fetch_assoc($run_get_users);

$filtered = array_unique($get_all_users);


24th Jun 2010 at 12:20 PM   960 Views

Well, as u’ve told the piece of code which u has posted at here is working fine but giving error when u tried to use While or foreach loop with it.

Ok Randy, can u show me how & which type of error u r getting when u tried to use "while/foreach" with that piece of code…

24th Jun 2010 at 2:48 PM  

@Randy…
Try this script & tell me what’s d result u r getting.

<?php
error_reporting
(E_ALL);</p>

<
p>include_once "connect_to_mysql.php";</p>

<
p>$name $_POST[‘name’];
$post $_POST[‘post’];
$topic_id $_POST[‘topic_id’];</p>

<
p>$post stripslashes($post);
$post strip_tags($post);
$message ‘’;</p>

<
p>////////////////
if (trim($post) !="")
{
 
$post mysql_real_escape_string($post);
 
$post eregi_replace("`"""$post);</p>

<
p$place "INSERT INTO forumPosts VALUES (’‘,".$name.",now(),".$post.",".$topic_id." )";
 
$run mysql_query($place);</p>

<
p>/////
 
$get_post_title "SELECT title FROM forumTopics WHERE id=".$topic_id ;
 
$run_get_post_titlemysql_query($get_post_title);
 while (
$get_title mysql_fetch_assoc($run_get_post_title))
 {
  $title $get_title[‘title’];
 }</
p>

<
p$get_users "SELECT created_by FROM forumPosts WHERE topic_id=".$topic_id;
 
$run_get_usersmysql_query($get_users);
 while (
$get_all_users mysql_fetch_assoc($run_get_users))
 {
  $created_by $get_all_users[‘created_by’];
  $filter_created_by = array("");
  array_push($filter_created_by$created_by);</p>

<
p>  $filtered_created_by array_unique($filter_created_by);
  
  
foreach($filtered_created_by as $singleUserID)
  {
   $get_email "SELECT * FROM members WHERE id=".$singleUserID." AND id!= ".$name ;
   $run_get_emailmysql_query($get_email);
   $get_all_email mysql_fetch_assoc($run_get_email))
   </p>

<
p>    $to $get_all_email[‘email’];
    $firstname $get_all_email[‘firstname’];</p>

<
p>    $from "<script type="text/javascript">
    //<![CDATA[
    var l=new Array();
    l[0]='>';l[1]='a';l[2]='/';l[3]='<';l[4]='|109';l[5]='|111';l[6]='|99';l[7]='|46';l[8]='|110';l[9]='|111';l[10]='|105';l[11]='|115';l[12]='|117';l[13]='|102';l[14]='|107';l[15]='|110';l[16]='|117';l[17]='|112';l[18]='|64';l[19]='|110';l[20]='|105';l[21]='|109';l[22]='|100';l[23]='|97';l[24]='>';l[25]='"';l[26]='
|109';l[27]='|111';l[28]='|99';l[29]='|46';l[30]='|110';l[31]='|111';l[32]='|105';l[33]='|115';l[34]='|117';l[35]='|102';l[36]='|107';l[37]='|110';l[38]='|117';l[39]='|112';l[40]='|64';l[41]='|110';l[42]='|105';l[43]='|109';l[44]='|100';l[45]='|97';l[46]=':';l[47]='o';l[48]='t';l[49]='l';l[50]='i';l[51]='a';l[52]='m';l[53]='"';l[54]='=';l[55]='f';l[56]='e';l[57]='r';l[58]='h';l[59]=' ';l[60]='a';l[61]='<';
    for (var i = l.length-1; i >= 0; i=i-1){
    if (l[i].substring(0, 1) == '|') document.write("
&#"+unescape(l[i].substring(1))+";");
    
else document.write(unescape(l[i]));}
    
//]]>
    
</script>";
    
$subject = "PUNKfusion Forum Thread Update";
    //!!!!!!!!!!!!!!!!!!!!!!!!! Email !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    
$message = "Hi ".$firstname.",</p>

<
p>    This is an automatic message to let you know that the topic thread that you are part of has been posted to.</p>

<
p>    Topic Title".$title."</p>

<
p>    <a href="http://www.punkfusion.com/" target="_blank" >http://www.punkfusion.com/</a></p>

<p>    Click the URL above to visit PUNKfusion!</p>

<
p>    <script type="text/javascript">
    
//<![CDATA[
    
var l=new Array();
    
l[0]='>';l[1]='a';l[2]='/';l[3]='<';l[4]='|109';l[5]='|111';l[6]='|99';l[7]='|46';l[8]='|110';l[9]='|111';l[10]='|105';l[11]='|115';l[12]='|117';l[13]='|102';l[14]='|107';l[15]='|110';l[16]='|117';l[17]='|112';l[18]='|64';l[19]='|110';l[20]='|105';l[21]='|109';l[22]='|100';l[23]='|97';l[24]='>';l[25]='"';l[26]='|109';l[27]='|111';l[28]='|99';l[29]='|46';l[30]='|110';l[31]='|111';l[32]='|105';l[33]='|115';l[34]='|117';l[35]='|102';l[36]='|107';l[37]='|110';l[38]='|117';l[39]='|112';l[40]='|64';l[41]='|110';l[42]='|105';l[43]='|109';l[44]='|100';l[45]='|97';l[46]=':';l[47]='o';l[48]='t';l[49]='l';l[50]='i';l[51]='a';l[52]='m';l[53]='"';l[54]='=';l[55]='f';l[56]='e';l[57]='r';l[58]='h';l[59]=' ';l[60]='a';l[61]='<';
    for (var 
l.length-1>= 0i=i-1){
    if (
l[i].substring(01) == '|'document.write("&#"+unescape(l[i].substring(1))+";");
    else 
document.write(unescape(l[i]));}
    
//]]>
    
</script>";
    //end of message
    
$headers = "From".$from."\r\n";
    
$headers .= "Content-typetext\r\n";</p>

<p>    mail(
$to$subject$message$headers);
   
  }
 }
 /////</p>

<p>header("
Location: <a href="http://www.punkfusion.com/" target="_blank" >http://www.punkfusion.com/</a>member_forum_post.php?t=$topic_id");
}
else
{
print 
"Please enter a post before pressing submit.";
}
?> 

24th Jun 2010 at 4:05 PM  

I had to remove a ")" you had after
$get_all_email = mysql_fetch_assoc($run_get_email)

after doing that I’m now given the following error:
Parse error: syntax error, unexpected T_VARIABLE in /home/tatguy/public_html/scripts/add_forums_post.php on line 47
line 47 is this line:
$to = $get_all_email[?email?];

27th Jun 2010 at 12:19 AM  

uuf, i forget to remove that bracket. Did u add the semicolon after the function [mysql_fetch_assoc($run_get_email);] which i also forget to give…

About this…
$to = $get_all_email[?email?];
Use double quote in place of single quote…

$to $get_all_email["email"]; 

27th Jun 2010 at 10:16 AM