使用 PHP 通过 IMAP 或 POP3 检索(仅未读)电子邮件

发布于 2024-11-24 11:58:45 字数 65 浏览 2 评论 0原文

有没有办法使用 PHP 通过 POP3 或 IMAP 协议仅从第 3 方服务器(例如 hotmail)检索未读邮件?

Is there any way to retrieve only unread messages from a 3rd party server (e.g. hotmail) thru POP3 or IMAP protocol using PHP?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

陌生 2024-12-01 11:58:46

是的,有一种方法可以满足您的要求。您需要使用 PHP 的 IMAP 扩展来处理电子邮件数据。以下是一些可以帮助您入门的链接:

基本教程:

http://davidwalsh.name/gmail -php-imap

来自 PHP.net 的 IMAP 扩展的官方描述:

https://www.php.net/manual/en/book.imap.php

希望有帮助!

Yes, there is a way to do what you're asking. You'll need to use PHP's IMAP extension to process the email data. Here are a couple of links that will get you started:

Basic tutorial:

http://davidwalsh.name/gmail-php-imap

Official description of the IMAP extension from PHP.net:

https://www.php.net/manual/en/book.imap.php

Hope that helps!

三生池水覆流年 2024-12-01 11:58:45
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 = '[email protected]';
$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
  }
 }
?>

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 = '[email protected]';
$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
  }
 }
?>

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文