CakeFest 2024: The Official CakePHP Conference

imap_body

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

imap_bodyメッセージ本文を読む

説明

imap_body(IMAP\Connection $imap, int $message_num, int $flags = 0): string|false

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

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

パラメータ

imap

IMAP\Connection クラスのインスタンス。

message_num

メッセージ番号。

flags

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

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

戻り値

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

変更履歴

バージョン 説明
8.1.0 引数 imap は、IMAP\Connection クラスのインスタンスを期待するようになりました。 これより前のバージョンでは、有効な imap リソース が期待されていました。
add a note

User Contributed Notes 2 notes

up
6
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
5
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