当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。