PHP - imap_fetchstructure() 函数



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

**imap_fetchstructure()** 函数接受表示 IMAP 流的资源值、表示邮箱中邮件的整数作为参数,并读取指定邮件的结构。

语法

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

参数

options(可选)

这是一个可选参数,可以是以下一个或多个:

  • FT_UID

  • FT_PEEK

  • FT_INTERNAL

序号 参数和描述
1

imap_stream(必填)

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

2

msg(必填)

这是一个整数,表示邮件/邮件编号,即要标记为删除的邮件。

3

msg(必填)

这是一个整数,表示邮件/邮件编号,即要标记为删除的邮件。

返回值

此函数返回一个字符串,表示检索到的邮件/消息的部分。

PHP 版本

此函数首次引入于 PHP 4 版,并在所有后续版本中均有效。

示例

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

<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 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 = "[email protected]";
         $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 = "[email protected]";
         $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_function_reference.htm
广告