PHP - IMAP 命令存储出错:消息集无效

PHP - Error in IMAP command STORE: Invalid messageset

我将 imap 与 php 一起使用,我发现了这个错误:

未知:IMAP 协议错误:IMAP 命令存储出错:消息集无效(0.001 + 0.000 秒)。 (errflg=2)

这只发生在一些邮箱上(例如 misterdomain.eu 上托管的邮箱)。

错误发生在脚本末尾,在imap_close().

之后

这是简单的代码。如果大家有什么建议(远到我的第一个问题),真的采纳了。

$inbox = imap_open($hostname,$username,$password) or die('Cannot connect: ' . imap_last_error());
$emails = imap_search($inbox,'SINCE "'.date("d-M-y",strtotime("-3 days")).'"',SE_UID);

if($emails) {
    rsort($emails);
    foreach($emails as $email_number) {

        echo "<h1>".$email_number."</h1>";
        $overview = imap_fetch_overview($inbox,$email_number, FT_UID);

        if($overview[0]->seen)
            imap_clearflag_full($inbox,$email_number,"//Seen");
        else
            imap_clearflag_full($inbox,$email_number,"//Unseen");

        $structure = imap_fetchstructure($inbox,$email_number, FT_UID);

        if(isset($structure->parts)){
            $flattenedParts = flattenParts($structure->parts);
            echo "<pre>";
            print_r($flattenedParts);
            echo "</pre>";
            echo "</br>";           
            getmsg($inbox, $email_number);

            echo "<p>".htmlspecialchars_decode(utf8_decode($plainmsg))."</p>";
        }else{
            $string_email = utf8_decode(imap_body($inbox, $email_number, FT_UID));
            $string_email= strip_tags($string_email);
            $string_email = html_entity_decode($string_email,ENT_QUOTES);
            echo "<p>".$string_email."</p>";
        }

    }
} 
imap_close($inbox);

您正在使用 UID 进行搜索和提取,但使用消息序列号进行存储。这些消息编号方式不匹配,因此您正在发送无效的消息编号进行存储。将适当的 ST_UID 标记添加到 imap_clearflag_full.

此外,系统标志使用 反斜杠 ,而不是正斜杠:'\Seen'\Unseen 不是定义的标志。您可能想要 添加 \Seen 标志。