有没有办法只使用PHP通过POP3或IMAP协议从第三方服务器(例如hotmail)检索未读消息?
答案 0 :(得分:2)
using PHP IMAP functions http://php.net/manual/en/function.imap-fetch-overview.php
$emails = imap_search($inbox,'UNSEEN');
If you want to print seen email simply change it to seen
$emails = imap_search($inbox,'UNSEEN');
<table class="table table-striped table-hover" width="400" >
<tbody >
<tr class="warning">
<td class="inbox-small-cells">
<input type="checkbox" class="mail-checkbox">
</td>
<td ><i class="fa fa-star"></i></td>
<td >#</td>
<td >Sender</td>
<td >Subject</td>
<td ><i class="fa fa-paperclip"></i></td>
<td >Date</td>
<td >Message</td>
<?php
$hostname='{imap.gmail.com:993/imap/ssl}INBOX';
$username = 'myemail@gmail.com';
$password = 'mypass';
$inbox = imap_open($hostname,$username,$password) or die('Cannot connect to Tiriyo: ' . imap_last_error());
//$emails = imap_search($inbox,'ALL');
$emails = imap_search($inbox,'UNSEEN');
//$x=count($MB);
if($emails) {
rsort($emails);
/* for every email... */
foreach($emails as $email_number) {
//$email_number=$emails[0];
//print_r($emails);
/* get information specific to this email */
$overview = imap_fetch_overview($inbox,$email_number,0);
$message = imap_fetchbody($inbox,$email_number, 1);
$email_number;
$overview[0]->subject;
$overview[0]->from;
$overview[0]->date;
$overview[0]->size ;
?>
<tr class="text-info" >
<td class="inbox-small-cells" >
<input type="checkbox" class="mail-checkbox">
</td>
<td ><i class="fa fa-star"></i></td>
<td> <?php echo $email_number; ?></td>
<td ><?php echo $overview[0]->from;?></a></td>
<td><?php echo $overview[0]->subject; ?></td>
<td class="view-message inbox-small-cells"><i class="fa fa-paperclip"></i></td>
<td ><?php echo $overview[0]->date; ?> </td>
</tr>
<?Php
}
}
?>
&#13;
答案 1 :(得分:0)
是的,有办法做你要问的事。您需要使用PHP的IMAP扩展来处理电子邮件数据。以下是一些可以帮助您入门的链接:
基础教程:
http://davidwalsh.name/gmail-php-imap
PHP.net的IMAP扩展程序的官方说明:
http://us3.php.net/manual/en/book.imap.php
希望有所帮助!