Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何让phpmail发送给正确的用户,并限制特定用户的电子邮件数量?第二部分_Php_Mysql_Database_Variables - Fatal编程技术网

如何让phpmail发送给正确的用户,并限制特定用户的电子邮件数量?第二部分

如何让phpmail发送给正确的用户,并限制特定用户的电子邮件数量?第二部分,php,mysql,database,variables,Php,Mysql,Database,Variables,感谢Anthony的建议,我已经尝试简化我的逻辑和语法,这是我试图实现的目标,即当写博客时,作者会收到php邮件通知,其他人发表了评论。当作者发表评论时,除了他之外,其他所有发表评论的人都会收到一封不同的电子邮件。当其他用户发表评论时,作者会收到如上所述的通知,但其他发表评论的人都会收到一封电子邮件,与作者在自己的博客上发表评论时发出的电子邮件相同,是的,我还是个新手: if(isset($_POST['commentBlogSubmit']) && $auth) {

感谢Anthony的建议,我已经尝试简化我的逻辑和语法,这是我试图实现的目标,即当写博客时,作者会收到php邮件通知,其他人发表了评论。当作者发表评论时,除了他之外,其他所有发表评论的人都会收到一封不同的电子邮件。当其他用户发表评论时,作者会收到如上所述的通知,但其他发表评论的人都会收到一封电子邮件,与作者在自己的博客上发表评论时发出的电子邮件相同,是的,我还是个新手:

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 = "<noreply@site.com>";
        $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 = "<noprely@site.com>";
            $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(isset($\u POST['commentBlogSubmit'])&&&auth){
$query=“从`Users`中选择`Email`,其中`id`='”$prof->id.“;
$request=mysql\u query($query,$connection)或die(mysql\u error());
$result=mysql\u fetch\u数组($request);
$Email=$result['Email'];
$to=$Email;
$subject=“$auth->first\u name$auth->last\u name给您留下了博客评论”;
$message=“$auth->first_name$auth->last_name给您留下了新的博客评论:



; $from=“”; $headers='MIME版本:1.0'。“\r\n”; $headers.=“内容类型:text/html;字符集=iso-8859-1”。“\r\n”; $headers.=“发件人:$From”; 邮件($to、$subject、$message、$headers); 如果($blog->author!=$poster->id){ $query=“从`BlogComments`中选择*,其中`blogID`='”$blog->id.“; $request=mysql\u查询($query,$connection); 而($result=mysql\u fetch\u array($request)){ $emailPoster=($result['userID']); $to=$emailPoster; $subject=“$auth->first\u name$auth->last\u name Commented”; $message=“$auth->first\u name$auth->last\u name在博客$blog->title:


; $from=“”; $headers='MIME版本:1.0'。“\r\n”; $headers.=“内容类型:text/html;字符集=iso-8859-1”。“\r\n”; $headers.=“发件人:$From”; 邮件($to、$subject、$message、$headers); }
根据您发布的内容,我将首先确认第二个查询是否返回结果。第二,返回的结果是多少。不发送电子邮件给用户,而是将其输出到屏幕上。例如:

  while($result = mysql_fetch_array($request)) {
       echo $result['userID']."\n";
  }
可能添加
print\r($result)
以确认按键是否正确,等等

第二,如果它循环正确,并且值是正确的,那么我认为问题在于它没有遵循你想要的逻辑,这就是何时发送电子邮件和发送电子邮件给谁的条件

坦白地说,当你写出来的时候,它看起来有点混乱。也许用伪代码写它可以帮助你看到缺失的部分在哪里

如果是我,我会根据谁发帖制定规则。如果有帖子,给除了海报之外的所有人发电子邮件。这样,如果是博主,他不会在自己的帖子上收到电子邮件,但其他人会。如果不是博主,他会收到电子邮件,因为他的用户ID与评论人的ID不匹配

这样做消除了许多基于谁是谁的规则,只是使之成为一个简单的规则