views:

31

answers:

1

Thanks to Anthony's advice I've tried to simplify my logic and syntax of the goal I am trying to achieve which is when a blog is written, the AUTHOR gets notified by php mail that someone other than himself comments. When the AUTHOR comments everyone else who commented except him gets a different email. When another user comments, the AUTHOR gets notified as stated above, but everyone else who has commented gets an email, the same one that the AUTHOR sends OUT when he comments on his OWN blog and yes I'm STILL a newbie:

if(isset($_POST['commentBlogSubmit']) && $auth) {



        $query = "SELECT `Email` FROM `Users` WHERE `id` = '" . $prof->id . "'";
        $request = mysql_query($query,$connection) or die(mysql_error());
        $result = mysql_fetch_array($request); 

        $Email = $result['Email'];


        $to = $Email;
        $subject = "$auth->first_name $auth->last_name left you a blog comment";
        $message = "$auth->first_name $auth->last_name left you new blog comment:<br /> <br /> <a href='BlogProfile.php?id=" . $blog->id . "'>Click here to view</a><br /><br />";
            $from = "<[email protected]>";
        $headers  = 'MIME-Version: 1.0' . "\r\n";
        $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
        $headers .= "From:$from";
        mail($to, $subject, $message, $headers);

        if($blog->author != $poster->id) { 

        $query = "SELECT * FROM `BlogComments` WHERE `blogID` = '" .$blog->id. "'";
        $request = mysql_query($query,$connection);
        while($result = mysql_fetch_array($request)) { 

        $emailPoster = ($result['userID']);

            $to = $emailPoster;
            $subject = "$auth->first_name $auth->last_name Commented";
            $message = "$auth->first_name $auth->last_name commented on the blog $blog->title :<br /> <br /> <a href='BlogProfile.php?id=" . $blog->id . "'>Click here to view</a><br /><br />";

            $from = "<[email protected]>";
            $headers  = 'MIME-Version: 1.0' . "\r\n";
            $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
            $headers .= "From:$from";
            mail($to, $subject, $message, $headers);




        }
+1  A: 

Based on what you've posted, I would start with confirming that the second query is returning results. And second, how many. Instead of emailing the users, have it output to screen. Like:

  while($result = mysql_fetch_array($request)) {
       echo $result['userID']."\n";
  }

Maybe add print_r($result) to confirm the keys are right, etc.

Second, if it's looping right, and the values are right, then I'm left thinking the issue is that it's not following the logic you want, that is the conditions for when to email and who.

Frankly, it seemed a bit confusing when you wrote it out. Maybe writing it in pseudo-code might help you see where the missing piece is.

If it was me, I'd make the rule based on who was posting. If there is a post, email everyone but the poster. That way, if it's the blogger, he won't get emails on his own posts but everyone else will. If it's not the blogger, he'll get the email, because his user ID didn't match that of the commenter.

Doing it that way eliminates a lot of rules based on who's who, and just makes it one simple rule.

Anthony