當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


PHP imap_fetchstructure()用法及代碼示例



PHP-IMAP 函數可幫助您訪問電子郵件帳戶,IMAP 代表I互聯網M艾爾A訪問權限Protocol 使用這些函數您還可以使用 NNTP、POP3 協議和本地郵箱訪問方法。

這個imap_fetchstructure()函數接受表示 IMAP 流的資源值、表示郵箱中消息的整數值作為參數,並讀取指定消息的結構。

用法

imap_fetchstructure($imap_stream, $msg [, $options]); 

參數

options(Optional)

這是一個可選參數,可以是以下一項或多項 -

  • FT_UID

  • FT_PEEK

  • FT_INTERNAL

Sr.No 參數及說明
1

imap_stream (Mandatory)

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

2

msg (Mandatory)

這是一個表示消息/郵件編號的整數值,即標記為刪除。

3

msg (Mandatory)

這是一個表示消息/郵件編號的整數值,即標記為刪除。

返回值

此函數返回一個字符串值,代表郵件/消息的檢索部分。

PHP版本

這個函數最初是在 PHP 版本 4 中引入的,並且適用於所有後續版本。

示例

下麵的例子演示了imap_fetchstructure()函數 -

<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 Structure
         print("Structure:"."<br>");
         $body = imap_fetchstructure($imap, 1);
         print_r($body);
    
         //Closing the connection
         imap_close($imap);   
      ?>
   </body>
</html>

輸出

這將生成以下輸出 -

Connection established....
Structure:
stdClass Object ( 
   [type] => 1 [encoding] => 0 [ifsubtype] => 1 
   [subtype] => ALTERNATIVE [ifdescription] => 0 
   [ifid] => 0 [ifdisposition] => 0 [ifdparameters] => 0 
   [ifparameters] => 1 [parameters] => 
   Array ( 
      [0] => stdClass Object ( 
         [attribute] => BOUNDARY 
         [value] => 000000000000a0d34e05b24373f4 
      ) 
   ) 
   [parts] => Array (
      [0] => stdClass Object ( 
         [type] => 0 [encoding] => 0 [ifsubtype] => 1 
         [subtype] => PLAIN [ifdescription] => 0 
         [ifid] => 0 [lines] => 1 [bytes] => 15 
         [ifdisposition] => 0 [ifdparameters] => 0 
         [ifparameters] => 1 [parameters] => Array ( 
            [0] => stdClass Object ( 
               [attribute] => CHARSET [value] => UTF-8 
            ) 
         ) 
      ) 
      [1] => stdClass Object ( 
         [type] => 0 [encoding] => 0 [ifsubtype] => 1 
         [subtype] => HTML [ifdescription] => 0 [ifid] => 0 
         [lines] => 1 [bytes] => 40 [ifdisposition] => 0 
         [ifdparameters] => 0 [ifparameters] => 1 
         [parameters] => Array (
            [0] => stdClass Object (
               [attribute] => CHARSET [value] => UTF-8 
            ) 
         ) 
      )
   ) 
)

示例

以下是此函數的另一個示例 -

<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>");
         //Searching emails
         $emailData = imap_search($imap, '');
        
         if (! empty($emailData)) {  
            foreach ($emailData as $msg) {
               $msg = imap_fetchstructure($imap, $msg);
               print($msg."<br>");      			   
            }    
         } 
         //Closing the connection
         imap_close($imap);   
      ?>
   </body>
</html>

輸出

這將生成以下輸出 -

Connection established....
stdClass Object ( 
   [type] => 1 [encoding] => 0 [ifsubtype] => 1 
   [subtype] => ALTERNATIVE [ifdescription] => 0 
   [ifid] => 0 [ifdisposition] => 0 [ifdparameters] => 0 
   [ifparameters] => 1 [parameters] => 
   Array ( 
      [0] => stdClass Object ( 
         [attribute] => BOUNDARY [value] => 000000000000a0d34e05b24373f4 
      ) 
   ) 
   [parts] => 
   Array ( 
      [0] => stdClass Object ( 
         [type] => 0 [encoding] => 0 [ifsubtype] => 1 
         [subtype] => PLAIN [ifdescription] => 0 [ifid] => 0 
         [lines] => 1 [bytes] => 15 [ifdisposition] => 0 
         [ifdparameters] => 0 [ifparameters] => 1 
         [parameters] => Array ( 
            [0] => stdClass Object (
               [attribute] => CHARSET [value] => UTF-8 
            ) 
         ) 
      ) 
      [1] => stdClass Object ( 
         [type] => 0 [encoding] => 0 [ifsubtype] => 1 
         [subtype] => HTML [ifdescription] => 0 [ifid] => 0 
         [lines] => 1 [bytes] => 40 [ifdisposition] => 0 
         [ifdparameters] => 0 [ifparameters] => 1 [parameters] => 
         Array (
            [0] => stdClass Object ( 
               [attribute] => CHARSET [value] => UTF-8 
            ) 
         ) 
      ) 
   ) 
)
stdClass Object ( 
   [type] => 1 [encoding] => 0 [ifsubtype] => 1 
   [subtype] => ALTERNATIVE [ifdescription] => 0 [ifid] => 0 
   [ifdisposition] => 0 [ifdparameters] => 0 [ifparameters] => 1 
   [parameters] => 
   Array ( 
      [0] => stdClass Object ( 
         [attribute] => BOUNDARY [value] => 000000000000bb1b8205b24375b9 
      ) 
   ) 
   [parts] => 
   Array ( 
      [0] => stdClass Object ( 
         [type] => 0 [encoding] => 0 [ifsubtype] => 1 
         [subtype] => PLAIN [ifdescription] => 0 [ifid] => 0 
         [lines] => 1 [bytes] => 16 [ifdisposition] => 0 
         [ifdparameters] => 0 [ifparameters] => 1 [parameters] => 
         Array ( 
            [0] => stdClass Object ( 
               [attribute] => CHARSET [value] => UTF-8 
            ) 
         ) 
      ) 
      [1] => stdClass Object (
         [type] => 0 [encoding] => 0 
         [ifsubtype] => 1 [subtype] => HTML [ifdescription] => 0 
         [ifid] => 0 [lines] => 1 [bytes] => 42 [ifdisposition] => 0 
         [ifdparameters] => 0 [ifparameters] => 1 [parameters] => 
         Array ( 
            [0] => stdClass Object ( 
               [attribute] => CHARSET [value] => UTF-8 
            ) 
         ) 
      ) 
   ) 
)

示例

以下是帶有可選參數的上述函數的示例 -

<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 Structure
         print("Structure:"."<br>");
         $body = imap_fetchstructure($imap, imap_uid($imap, 1), FT_UID);
         print_r($body);
    
         //Closing the connection
         imap_close($imap);   
      ?>
   </body>
</html>

輸出

這將生成以下輸出 -

Connection established....
Structure:
stdClass Object ( 
   [type] => 1 [encoding] => 0 [ifsubtype] => 1 
   [subtype] => ALTERNATIVE [ifdescription] => 0 [ifid] => 0 
   [ifdisposition] => 0 [ifdparameters] => 0 [ifparameters] => 1 
   [parameters] => 
   Array ( 
      [0] => stdClass Object ( 
         [attribute] => BOUNDARY [value] => 000000000000a0d34e05b24373f4 
      ) 
   ) 
   [parts] => 
   Array ( 
      [0] => stdClass Object ( 
         [type] => 0 [encoding] => 0 [ifsubtype] => 1 
         [subtype] => PLAIN [ifdescription] => 0 [ifid] => 0 
         [lines] => 1 [bytes] => 15 [ifdisposition] => 0 
         [ifdparameters] => 0 [ifparameters] => 1 [parameters] => 
         Array ( 
            [0] => stdClass Object ( 
               [attribute] => CHARSET [value] => UTF-8 
            ) 
         ) 
      ) [1] => stdClass Object ( 
         [type] => 0 [encoding] => 0 
         [ifsubtype] => 1 [subtype] => HTML [ifdescription] => 0 
         [ifid] => 0 [lines] => 1 [bytes] => 40 
         [ifdisposition] => 0 [ifdparameters] => 0 
         [ifparameters] => 1 [parameters] => 
         Array ( 
            [0] => stdClass Object ( 
               [attribute] => CHARSET [value] => UTF-8 
            ) 
         ) 
      ) 
   ) 
)

相關用法


注:本文由純淨天空篩選整理自 PHP - imap_fetchstructure() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。