使用Imap PHP获取处于读取状态的Gmail电子邮件
我用这个代码从Gmail获取数据使用Imap PHP获取处于读取状态的Gmail电子邮件,php,ajax,gmail,imap,Php,Ajax,Gmail,Imap,我用这个代码从Gmail获取数据 <?php $data = array( // email account 'email' => array( 'hostname' => '{imap.gmail.com:993/imap/ssl}INBOX', 'username' => $emailAddress, 'password' => $emailPassword ),
<?php $data = array(
// email account
'email' => array(
'hostname' => '{imap.gmail.com:993/imap/ssl}INBOX',
'username' => $emailAddress,
'password' => $emailPassword
),
// inbox pagination
'pagination' => array(
'sort' => $sortBy,
'limit' => 10,
'offset' => $offset
)
);
$result = array();
$imap = imap_open($data['email']['hostname'], $data['email']['username'], $data['email']['password']) or die ('Cannot connect to yourdomain.com: ' . imap_last_error());
$read = imap_search($imap, 'ALL');
$overview = imap_fetch_overview($imap, $read[$i], 0);
$header = imap_headerinfo($imap, $read[$i], 0);
$mail = $header->from[0]->mailbox . '@' . $header->from[0]->host;
$image = '';
$structure = imap_fetchstructure($imap, $read[$i]);
if(isset($structure->parts) && is_array($structure->parts) && isset($structure->parts[1])) {
$part = $structure->parts[1];
if($part->encoding == 3) {
$message = imap_fetchbody($imap,$read[$i],1.2);
$message = imap_qprint($message);
} else if($part->encoding == 1) {
$message = imap_8bit($message);
} else {
$message = imap_fetchbody($imap,$read[$i],2);
$message = imap_qprint($message);
}
}else{
$message = imap_body($imap, $read[$i],0);
}
我收到的所有数据都是正确的,但是当我进入电子邮件列表页面时,收到的电子邮件变成了阅读
使用一段时间后,这个问题出现了。
知道原因是什么吗?在imap_fetchbody中,添加FT_PEEK标志以防止自动清除\Seen标志
imap_fetchbody($imap, $read[$i], 1.2, FT_PEEK);
请参阅。获取电子邮件会将其标记为默认可见,除非您使用PEEK变量。您的代码所做的只是登录,其余的在哪里?Hi@Max我编辑了问题。我应该在什么功能中使用PEEK variant?