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


PHP imap_savebody()用法及代码示例



PHP-IMAP 函数可帮助您访问电子邮件帐户,IMAP 代表I互联网M艾尔A访问权限Protocol 使用这些函数您还可以使用 NNTP、POP3 协议和本地邮箱访问方法。

这个imap_savebody()函数接受表示 IMAP 流的资源值、文件路径和表示特定消息的整数值作为参数,并将给定邮件的正文保存在指定的文件路径中。

用法

imap_savebody($imap_stream, $file, $msg [,part, $options]);

参数

Sr.No 参数及说明
1

imap_stream (Mandatory)

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

2

file (Mandatory)

这是您需要在其中保存邮件正文的文件路径。

3

msg (Mandatory)

这是一个表示消息/邮件编号的整数值。

4

part_number (Optional)

这是一个字符串值,包含由 “.” 分隔的身体部位值的索引。

5

options (Optional)

这是一个表示可选值的整数值,它可以是以下一项或多项:

  • FT_UID

  • FT_PEEK

  • FT_INTERNAL

返回值

此函数返回一个布尔值,成功时为 TRUE,失败时为 FALSE。

PHP版本

这个函数最初是在 PHP 版本 5 中引入的,并且适用于所有后续版本。

示例

下面的例子演示了imap_savebody()函数 -

<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>");
		 
         //Saving the message in a file 
         $path = "sample.txt";
         $file = fopen($path, "w");

         $msg = 1;
         $body = imap_savebody($imap, $file, 1);
         print($body);
         print("Message saved in the file");
    
         //Closing the connection
         imap_close($imap);   
      ?>
   </body>
</html>

输出

这将生成以下输出 -

Connection established....
Message saved in the file

示例

以下是带有可选参数的上述函数的示例 -

<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>");
		 
         //Saving the message in a file 
         $path = "sample.txt";
         $file = fopen($path, "w");

         $msg = 1;
         $body = imap_savebody($imap, $file, 1, 1);
         print($body);
         print("Message saved in the file");
         
         //Closing the connection
         imap_close($imap);   
      ?>
   </body>
</html>

输出

这将生成以下输出 -

Connection established....
Message saved in the file

相关用法


注:本文由纯净天空筛选整理自 PHP - imap_savebody() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。