PHP - imap_check() 函数



PHP 的 IMAP 函数帮助您访问电子邮件帐户,IMAP 代表 **I**nternet **M**ail **A**ccess **P**rotocol,使用这些函数您还可以使用 NNTP、POP3 协议和本地邮箱访问方法。

imap_check() 函数接受表示 IMAP 流的资源值作为参数,验证给定邮箱的信息并以对象的格式返回。

语法

imap_check($imap_stream);

参数

序号 参数和描述
1

imap_stream (必填)

这是一个字符串值,表示 IMAP 流,是 imap_open() 函数的返回值。

返回值

此函数返回一个包含当前邮箱信息的 对象,成功时返回对象,失败时返回布尔值 FALSE。

PHP 版本

此函数首次出现在 PHP 4 版本中,并在所有后续版本中可用。

示例

以下示例演示了 imap_check() 函数的用法:

<html>
   <body>
      <?php
         //Establishing connection
         $url = "{imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX";
         $id = "[email protected]";
         $pwd = "cohondob_123";
         $imap = imap_open($url, $id, $pwd);
         print("Connection established...."."<br>");
		 
         //Fetching the contents of a message
         print("Overview of the first message: "."<br>");
         $obj = imap_check($imap);
         print("<br>");	
         print("Date :".$obj->Date);
         print("<br>");		
         print("Driver: ".$obj−>Driver);
         print("<br>");	
         print("Mailbox: ".$obj−>Mailbox);
         print("<br>");		
         print("Nmsgs: ".$obj−>Nmsgs);
         print("<br>");		
         print("Recent: ".$obj−>Recent);
         print("<br>");

         //Closing the connection
         imap_close($imap);   
      ?>
   </body>
</html>

这将生成以下输出:

Connection established....
Overview of the first message:

Date :Mon, 26 Oct 2020 11:38:26 +0530 (India Standard Time)
Driver: imap
Mailbox: {imap.gmail.com:993/imap/notls/ssl/novalidate-cert/user="[email protected]"}INBOX
Nmsgs: 6
Recent: 0

示例

以下是此函数的另一个示例:

<html>
   <body>
      <?php
         //Establishing connection
         $url = "{imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX";
         $id = "[email protected]";
         $pwd = "cohondob_123";
         $imap = imap_open($url, $id, $pwd);
         print("Connection established...."."<br>");
		 
         //Fetching the contents of a message
         print("Overview of the first message: "."<br>");
         $MC = imap_check($imap);
         $overview = imap_fetch_overview($imap, "1:{$MC->Nmsgs}");
         foreach ($overview as $obj) {
            print("<br>");	
            print_r($obj);
            print("<br>");			
         }    
         //Closing the connection
         imap_close($imap);   
      ?>
   </body>
</html>

输出

这将生成以下输出:

Connection established....
Overview of the first message:

stdClass Object (
   [from] => Sender[to] => [email protected] 
   [date] => Thu, 22 Oct 2020 20:10:17 +0530 
   [message_id] => [size] => 4857 [uid] => 19 
   [msgno] => 1 [recent] => 0 [flagged] => 0 
   [answered] => 0 [deleted] => 0 [seen] => 1 
   [draft] => 0 [udate] => 1603377656 
)
stdClass Object ( 
   [from] => Sender[to] => [email protected] 
   [date] => Thu, 22 Oct 2020 20:10:52 +0530 
   [message_id] => [size] => 4858 [uid] => 20 
   [msgno] => 2 [recent] => 0 [flagged] => 0 
   [answered] => 0 [deleted] => 0 [seen] => 1 
   [draft] => 0 [udate] => 1603377691 
)
stdClass Object ( 
   [from] => Sender[to] => [email protected] 
   [date] => Sun, 25 Oct 2020 16:11:22 +0530 [message_id] => 
   [size] => 4880 [uid] => 42 [msgno] => 3 [recent] => 0 
   [flagged] => 0 [answered] => 0 [deleted] => 0 [seen] => 1 
   [draft] => 0 [udate] => 1603622523 
)
stdClass Object ( 
   [from] => Sender[to] => [email protected] 
   [date] => Sun, 25 Oct 2020 17:22:41 +0530 [message_id] => 
   [size] => 4882 [uid] => 49 [msgno] => 4 [recent] => 0 
   [flagged] => 0 [answered] => 0 [deleted] => 0 [seen] => 1 
   [draft] => 0 [udate] => 1603626802 
)
stdClass Object ( 
   [from] => Sender[to] => [email protected] 
   [date] => Sun, 25 Oct 2020 17:23:10 +0530 [message_id] => 
   [size] => 4884 [uid] => 50 [msgno] => 5 [recent] => 0 
   [flagged] => 0 [answered] => 0 [deleted] => 0 [seen] => 1 
   [draft] => 0 [udate] => 1603626831 
)
stdClass Object ( 
   [from] => Sender[to] => [email protected] 
   [date] => Sun, 25 Oct 2020 17:24:25 +0530 [message_id] => 
   [size] => 4883 [uid] => 51 [msgno] => 6 [recent] => 0 
   [flagged] => 0 [answered] => 0 [deleted] => 0 [seen] => 1 
   [draft] => 0 [udate] => 1603626906 
)
php_function_reference.htm
广告