PHP - imap_savebody() 函式



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

**imap_savebody()** 函式接受表示 IMAP 流的資源值、檔案路徑和表示特定郵件的整數值作為引數,並將給定郵件的主體儲存到指定的檔案路徑中。

語法

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

引數

序號 引數及描述
1

imap_stream (必填)

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

2

file (必填)

這是您需要將郵件主體儲存到的檔案路徑。

3

msg (必填)

這是一個整數值,表示郵件/郵件編號。

4

part_number (可選)

這是一個字串值,包含主體部分索引值,用“.”分隔。

5

options (可選)

這是一個整數值,表示可選值,可以是以下一個或多個

  • 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_function_reference.htm
廣告