當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


PHP imap_rfc822_parse_adrlist()用法及代碼示例


PHP-IMAP 函數可幫助您訪問電子郵件帳戶,IMAP 代表I互聯網M艾爾A訪問權限Protocol 使用這些函數您還可以使用 NNTP、POP3 協議和本地郵箱訪問方法。

這個imap_rfc822_parse_adrlist()函數接受表示地址和默認主機名的兩個字符串值作為參數並解析給定的地址字符串。

用法

imap_rfc822_parse_adrlist($address, $default_host);

參數

Sr.No 參數及說明
1

address (Mandatory)

這是一個表示地址的字符串值。

2

default_host (Mandatory)

這是一個表示默認主機名的字符串值。

返回值

此函數返回一個包含解析值的對象數組。

PHP版本

這個函數最初是在 PHP 版本 4 中引入的,並且適用於所有後續版本。

示例

下麵的例子演示了imap_rfc822_parse_adrlist()函數 -

<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>");
		 
         //Parsing a string address	 
         print("Parsing string address:"."<br>");
         $addr_str = "Sender <sender@test.com>, CC@test.com, root";
         $res = imap_rfc822_parse_adrlist($addr_str, "default_host");
         print_r($res);
    
         //Closing the connection
         imap_close($imap);   
      ?>
   </body>
</html>

輸出

這將生成以下輸出 -

Connection established....
Parsing string address:
Array ( 
   [0] => stdClass Object ( 
      [mailbox] => sender [host] => test.com [personal] => Sender 
   ) 
   [1] => stdClass Object ( 
      [mailbox] => CC [host] => test.com 
   ) 
   [2] => stdClass Object ( 
      [mailbox] => root [host] => default_host 
   ) 
)

示例

以下是上述函數的另一個例子 -

<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>");
         
         //Parsing a string address	 
         print("Parsing string address:"."<br>");
         $addr_str = "Sender <sender@test.com>, CC@test.com, root";
         $res = imap_rfc822_parse_adrlist($addr_str, "default_host");
         foreach ($res as  $val) {
         print($val -> mailbox);
            print("<br>");
            print($val -> host);
            print("<br>");
         }
         //Closing the connection
         imap_close($imap);   
      ?>
   </body>
</html>

輸出

這將生成以下輸出 -

Connection established....
Parsing string address:
sender
test.com
CC
test.com
root
default_host

相關用法


注:本文由純淨天空篩選整理自 PHP - imap_rfc822_parse_adrlist() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。