PHP - imap_append() 函式



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

**imap_append()** 函式接受一個表示 IMAP 流的資源值,以及另外兩個表示郵箱名稱/URL 和訊息的字串值作為引數,並將給定訊息追加到指定的郵箱。

**imap_binary()** 函式 notranslate"> imap_append($imap_stream ,$mailbox ,$message [$options, $internal_date]);

引數

序號 引數及描述
1

imap_stream (必填)

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

2

mailbox(必填)

這是一個表示郵箱名稱/URL 的字串值。它包含伺服器名稱、郵箱路徑。

3

message(必填)

這是一個表示要追加的訊息的字串值。

4

options (可選)

這是一個可選的字串值,它將被追加到郵件指定的郵箱。

5

date (可選)

這是一個表示可選內部日期的字串值,該日期將新增到訊息中。

返回值

此函式返回一個布林值,成功時為 TRUE,失敗時為 FALSE。

PHP 版本

此函式首次引入於 PHP 版本 4,並在所有後續版本中均有效。

示例

以下示例演示了 **imap_append()** 函式的使用 −

<html>
   <body>
      <?php
         $url = "{imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX";
         $id = "tutorialspoint.test@gmail.com";
         $pwd = "cohondob_123";
         $stream = imap_open($url, $id, $pwd);
         print("Connection established....");
         print("<br>");
		 
         $num = imap_num_msg($stream);
         print("Number of messages: ".$num."\n");

         imap_append($stream, $url
            , "From: sender@test.com\r\n"
            . "To: reciever@test.com\r\n"
            . "Subject: test\r\n"
            . "\r\n"
            . "this is a test message, please ignore\r\n"
         );
         print("<br>");
         print("Number of messages after append: ".imap_num_msg($stream)."\n");

         imap_close($stream);
      ?>
   </body>
</html>

輸出

這將生成以下輸出 −

Connection established....
Number of messages: 10
Number of messages after append: 11

示例

以下是上述函式使用可選引數的示例 −

<html>
   <body>
      <?php
         $url = "{imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX";
         $id = "tutorialspoint.test@gmail.com";
         $pwd = "cohondob_123";
         $stream = imap_open($url, $id, $pwd);
         print("Connection established....");
         print("<br>");
		 
         $num = imap_num_msg($stream);
         print("Number of messages: ".$num."\n");

         $msg = "From: sender@test.com\r\n"
            . "To: reciever@test.com\r\n"
            . "Subject: test\r\n"
            . "\r\n"
            . "this is a test message, please ignore\r\n";

         imap_append($stream, $url, $msg, "", date("2/2/2020"));
         print("Message appended");
         imap_close($stream);
      ?>
   </body>
</html>

輸出

這將生成以下輸出 −

Message appended
php_function_reference.htm
廣告