PHP - imap_msgno() 函式



PHP 的 IMAP 函式幫助您訪問電子郵件帳戶,IMAP 代表 **I**nternet **M**ail **A**ccess **P**rotocol,使用這些函式,您還可以使用 NNTP、POP3 協議和本地郵箱訪問方法。

imap_msgno() 函式接受表示 IMAP 流的資源值和表示郵件 UID 的整數值作為引數,並檢索對應於給定 UID 的郵件的序列號。

語法

imap_msgno($imap_stream, $uid);

引數

序號 引數和描述
1

imap_stream(必填)

這是一個字串值,表示 IMAP 流,是 imap_open() 函式的返回值。

2

uid(必填)

這是一個整數值。

返回值

此函式返回一個整數值,表示郵件序列號。

PHP 版本

此函式首次引入於 PHP 4 版本,並在所有後續版本中均有效。

示例

<html>
   <body>
      <?php
         //Establishing connection
         $url = "{imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX";
         $id = "tutorialspoint.test@gmail.com";
         $pwd = "cohondob_123";
         $imap = imap_open($url, $id, $pwd);
         print("Connection established...."."<br>");
		 
         //Fetching the contents of a message
         print("UID of the 1st message: ");
         $UID = imap_uid($imap, 1);
         print($UID);
         print("<br>");

         //Retrieving the message number
         $msg = imap_msgno($imap, $UID);
         print($msg); 		 
         //Closing the connection
         imap_close($imap);   
      ?>
   </body>
</html>

輸出

這將生成以下輸出:

Connection established....
UID of the 1st message: 19
1

示例

以下是此函式的另一個示例:

<html>
   <body>
      <?php
         //Establishing connection
         $url = "{imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX";
         $id = "tutorialspoint.test@gmail.com";
         $pwd = "cohondob_123";
         $imap = imap_open($url, $id, $pwd);
         print("Connection established...."."<br>");
		 
         //Fetching the contents of a message
         print("UID of the 1st message: ");
         $UID = imap_uid($imap, 1);
         print($UID);
         print("<br>");

         //Retrieving the message number
         $msg = imap_msgno($imap, $UID);
         print($msg);
		   
         $emailData = imap_search($imap, '');
         foreach ($emailData as $msg) {
            $msg = imap_msgno($imap, imap_uid($imap, $msg));
            print($msg);
            print("<br>");
         }    
         //Closing the connection
         imap_close($imap);   
      ?>
   </body>
</html>

輸出

這將生成以下輸出:

Connection established....
UID of the 1st message: 19
11
2
3
4
5
6
7
php_function_reference.htm
廣告
© . All rights reserved.