imap_body

(PHP 4, PHP 5, PHP 7, PHP 8)

imap_bodyメッセージ本文を読む

説明

imap_body(resource $imap, int $message_num, int $flags = 0): string|false

imap_body() は、現在のメールボックスにある message_num 番目のメッセージの本文を返します。

imap_body() は、メッセージの本文と全く同じ コピーのみを返します。マルチパート MIME エンコードされたメッセージの 一部を展開するには、その構造を解析するために imap_fetch_structure() を使用し、単一の部分要素の コピーを展開する際には、 imap_fetchbody() を使用する必要があります。

パラメータ

imap

imap_open() が返す IMAP ストリーム。

message_num

メッセージ番号。

flags

オプションの flags はビットマスクであり、 以下の要素の組み合わせとなります。

  • FT_UID - message_num は UID です
  • FT_PEEK - 既に設定されていない場合、\Seen フラグを設定しない
  • FT_INTERNAL - 内部フォーマットで文字列を返す。 CRLF に正規化しない。

返り値

指定したメッセージの本文を文字列で返します。 失敗した場合に false を返します

add a note add a note

User Contributed Notes 2 notes

up
10
deenfirdoush at gmail dot com
14 years ago
Simple example on how to read body message of the recent mail.

<?php
$imap
= imap_open("{pop.example.com:995/pop3/ssl/novalidate-cert}", "username", "password");

if(
$imap ) {
   
    
//Check no.of.msgs
    
$num = imap_num_msg($imap);

    
//if there is a message in your inbox
    
if( $num >0 ) {
         
//read that mail recently arrived
         
echo imap_qprint(imap_body($imap, $num));
     }

    
//close the stream
    
imap_close($imap);
}
?>
up
8
theloverkills at gmail dot com
7 years ago
Please note that the UID is NOT unique.
UID of the email may be not unique on the server (2 messages in different folders may have same UID).

Basically, don't use the UID as a unique identifier.
To Top