PHP - imap_fetchtext() 函式



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

imap_fetchtext() 函式是imap_body() 的別名,它接受表示 IMAP 流的資源值和表示特定郵件的整數值作為引數,並以字串的形式讀取指定郵件/訊息的主體。

語法

imap_fetchtext($imap_stream ,$msg);

引數

選項(可選)

這是一個整數值,表示可選值 FT_UID,如果指定,則訊息將被視為 UID。

序號 引數和描述
1

imap_stream(必填)

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

2

msg(必填)

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

3

msg(必填)

這是一個整數值,表示要標記為刪除的郵件/訊息編號。

返回值

此函式返回一個物件,其中包含指定訊息結構的詳細資訊。

PHP 版本

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

示例

這是一個演示imap_fetchtext() 函式用法的示例:

<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>");
		 
         //Fetching the contents of a message
         print("Contents of the first message: "."<br>");
         $body = imap_fetchtext($imap, 1);
         print($body);
    
         //Closing the connection
         imap_close($imap);   
      ?>
   </body>
</html>

輸出

這將生成以下輸出:

Connection established....
Contents of the first message:
−−000000000000a0d34e05b24373f4 Content-Type: text/plain; charset="UTF−8" #sample_mail1 −−000000000000a0d34e05b24373f4 Content−Type: text/html; charset="UTF−8"
#sample_mail1
−−000000000000a0d34e05b24373f4−−

示例

這是此函式的另一個示例:

<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>");
         //Searching emails
         $emailData = imap_search($imap, '');
        
         if (! empty($emailData)) {  
            foreach ($emailData as $msg) {
               $msg = imap_fetchtext($imap, $msg);
               print(quoted_printable_decode($msg)."<br>");                
            }    
         } 
         //Closing the connection
         imap_close($imap);   
      ?>
   </body>
</html>

輸出

這將生成以下輸出:

Connection established....
--000000000000a0d34e05b24373f4 Content-Type: text/plain; 
charset="UTF-8" #sample_mail1 --000000000000a0d34e05b24373f4 
Content-Type: text/html; charset="UTF-8"
#sample_mail1
--000000000000a0d34e05b24373f4--
--000000000000bb1b8205b24375b9 Content-Type: text/plain; 
charset="UTF-8" #sample_mail2 --000000000000bb1b8205b24375b9 
Content-Type: text/html; charset="UTF-8"
#sample_mail2
--000000000000bb1b8205b24375b9--
--000000000000dceebf05b27c7601 Content-Type: text/plain; 
charset="UTF-8" #sample_mail3 --000000000000dceebf05b27c7601 
Content-Type: text/html; charset="UTF-8"
#sample_mail3
--000000000000dceebf05b27c7601--
--000000000000e7e7c705b27d7527 Content-Type: text/plain; 
charset="UTF-8" #sample_mail4 --000000000000e7e7c705b27d7527 
Content-Type: text/html; charset="UTF-8"
php_function_reference.htm
廣告
© . All rights reserved.