Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/255.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/6/opengl/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
Php 是否存储来自IMAP的电子邮件(唯一电子邮件ID)?_Php_Imap - Fatal编程技术网

Php 是否存储来自IMAP的电子邮件(唯一电子邮件ID)?

Php 是否存储来自IMAP的电子邮件(唯一电子邮件ID)?,php,imap,Php,Imap,如何在数据库中存储来自该电子邮件的唯一ID 我试过$overview=imap\U fetch\U overview($inbox,$email\u number,0);我收到了一大堆号码,但问题是当其中一封邮件被删除时,号码会改变 我如何正确地储存它?MD5消息还是什么 基本上,我尝试在我的个人网络应用程序上接收电子邮件,在那里我可以管理和访问我自己的电子邮件。它使用imap调用gmail 总之,我可以在哪里检查和存储新的电子邮件 /* connect to gmail */

如何在数据库中存储来自该电子邮件的唯一ID

我试过$overview=imap\U fetch\U overview($inbox,$email\u number,0);我收到了一大堆号码,但问题是当其中一封邮件被删除时,号码会改变

我如何正确地储存它?MD5消息还是什么

基本上,我尝试在我的个人网络应用程序上接收电子邮件,在那里我可以管理和访问我自己的电子邮件。它使用imap调用gmail

总之,我可以在哪里检查和存储新的电子邮件

/* connect to gmail */
        $hostname = '{imap.gmail.com:993/imap/ssl}INBOX';
        $username = 'xxxx@gmail.com';
        $password = '';

        /* try to connect */
        $inbox = imap_open($hostname,$username,$password) or die('Cannot connect to Gmail: ' . imap_last_error());

        /* grab emails */
        $emails = imap_search($inbox,'ALL');
        dd($emails);
        /* if emails are returned, cycle through each... */
        if($emails) {

            /* begin output var */
            $output = '';

            /* put the newest emails on top */
            rsort($emails);

            /* for every email... */
            foreach($emails as $email_number) {

                /* get information specific to this email */
                $overview = imap_fetch_overview($inbox,$email_number,0);
                $message = imap_fetchbody($inbox,$email_number,2);

                /* output the email header information */
                $output.= '<div class="toggler '.($overview[0]->seen ? 'read' : 'unread').'">';
                $output.= '<span class="subject">'.$overview[0]->subject.'</span> ';
                $output.= '<span class="from">'.$overview[0]->from.'</span>';
                $output.= '<span class="date">on '.$overview[0]->date.'</span>';
                $output.= '</div>';

                /* output the email body */
                $output.= '<div class="body">'.$message.'</div>';
            }

            echo $output;
        } 

        /* close the connection */
        imap_close($inbox);
/*连接到gmail*/
$hostname='{imap.gmail.com:993/imap/ssl}收件箱';
$username='1xxxx@gmail.com';
$password='';
/*尝试连接*/
$inbox=imap_open($hostname,$username,$password)或die('cannotconnecttogmail:'。imap_last_error());
/*抓取电子邮件*/
$emails=imap_搜索($inbox,'ALL');
dd(电子邮件);
/*如果电子邮件被返回,请循环浏览每个*/
如果($电子邮件){
/*开始输出变量*/
$output='';
/*把最新的电子邮件放在最上面*/
rsort(电子邮件);
/*对于每封电子邮件*/
foreach($email作为$email\u编号){
/*获取此电子邮件的特定信息*/
$overview=imap\U fetch\U overview($inbox,$email\u number,0);
$message=imap\u fetchbody($inbox,$email\u number,2);
/*输出电子邮件标题信息*/
$output.='';
$output.=''.$overview[0]->subject';
$output.=''.$overview[0]->from';
$output.='on'.$overview[0]->date'.';
$output.='';
/*输出电子邮件正文*/
$output.=''.$message';
}
echo$输出;
} 
/*关闭连接*/
imap_关闭($收件箱);

出于此目的,
UID
应该保持不变,除非服务器提供不同的
UIDVALIDITY


UID
是IMAP标准的一部分,因此应该由所有IMAP服务器正确实施。如果您只针对gmail,那么您可能需要查看另一个值,因为相同的消息可以在不同的标签下看到,并且对于逻辑上相同的消息,
UID
可能不同。不过,我不知道gmail API。

如果这个问题更多的是关于实际的数据库设计,那么我会使用我自己生成的id(这样可以使它保持较小,从而更快),并在
UID上放置一个唯一的索引
(或者,如果您不想每次收到新的
uidvality
时都删除邮件,则使用带有
uidvality
值的复合唯一索引)。无论如何,RFC拥有所有信息。