本文介绍了在IMAP服务器上将电子邮件设置为SEEN的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从Imap服务器(Gmail)读取邮件。我会检查是否有新邮件(看不见)并进行查看。
我写了这段代码,但

I am trying to read mail from an Imap Server (Gmail). I would check if there are new mail (unseen) and check it as seen.I wrote this code but

imap_setflag_full

似乎不起作用。
如果我有一封新邮件,该脚本无法放置SEEN标志,并回显我总是有一封看不见的邮件。

seems to not work. If I have a new mail the script is unable to put the SEEN flag and it echo me that there is always one unseen mail.

  $mbox=imap_open( "{imap.gmail.com:993/ssl/novalidate-cert}" , $this->username, $this->password);
    if ($mbox) 
            {  echo "Connected\n<br><br>"; 
            }  else { exit ("Can't connect: " . imap_last_error() ."\n");  echo "FAIL!\n";  }; 

        if ($hdr = imap_check($mbox)) {
          $msgCount = $hdr->Nmsgs;
          echo "There are ".$msgCount." mail";
        } else {
          echo "Failed to get mail";

        }

        $result = imap_search($mbox, 'UNSEEN');
        echo "<br>Result: ";
        print_r($result);
        if($result==false)
            echo "No email";
        else{
            echo "you have mail"; 
            echo("<br>now I set the Seen flag for this mail");
            rsort($result);
            $status = imap_setflag_full($mbox, "1", "\\Seen \\Flagged", ST_UID);      
        }

        echo"<br><br>";


        $result = imap_search($mbox, 'UNSEEN');
        echo "<br>Result: ";
        print_r($result);
        if($result==false)
            echo "no mail";
        else{
            echo "there are still"; 

        }

非常感谢。

推荐答案

我认为问题在于硬编码的 1。我将 1替换为:

I think the problem is with the "1" you have hardcoded. I replaced the "1" with:

foreach ($result as $mail) {
    $status = imap_setflag_full($mbox, $mail, "\\Seen \\Flagged", ST_UID);
}

似乎有效。使用ST_UID时,实际上意味着一个ID,而不是序列号。

and it seems to work. When using ST_UID, this means actually an ID, and not a sequence number.

这篇关于在IMAP服务器上将电子邮件设置为SEEN的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-16 19:42