PHP - imap_createmailbox() 函式



PHP 的 IMAP 函式幫助您訪問電子郵件帳戶,IMAP 代表Internet Mail Access Protocol,使用這些函式,您還可以使用 NNTP、POP3 協議和本地郵箱訪問方法。

imap_createmailbox() 函式接受一個表示 IMAP 流的資源值和一個表示郵箱 URL/名稱的字串值,並建立一個新的郵箱。

語法

imap_createmailbox ($imap_stream, $mailbox);

引數

序號 引數及描述
1

imap_stream (必填)

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

2

mailbox (必填)

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

返回值

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

PHP 版本

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

示例

以下示例演示了 imap_createmailbox() 函式的用法:

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

         //Creating a mailbox
         $newmailbox = "{imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX.new_mail_box";
         $res = imap_createmailbox($mailbox, imap_utf7_encode($newmailbox));
		 
         if($res){
            print("Mailbox created successfully");
         } else {
            print("Error occurred");
         }		 
      ?>
   </body>
</html>

輸出

以上程式生成以下輸出:

Connection established....
Mailbox created successfully

示例

以下是此函式的另一個示例:

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

         //Creating a mailbox
         $newmailbox = "{imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX.test_mail1";
         $res = imap_createmailbox($mailbox, imap_utf7_encode($newmailbox));
		 
         //Retrieving the contents of mail boxes
         $list = imap_getmailboxes($mailbox, $url, "*");
         foreach ($list as $key => $val) {
            print_r($val->name);
            print("<br>");
         }   
      ?>
   </body>
</html>

輸出

以上程式生成以下輸出:

Connection established....
{imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX.
{imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX.test_mail1
php_function_reference.htm
廣告