라이브러리

[PHP] imap_fetchstructure - 특정 메시지의 구조를 읽습니다.




imap_fetchstructure란?

PHP의 imap_fetchstructure 함수는 IMAP 서버에서 메시지의 구조를 가져올 수 있는 함수입니다. 이 함수는 메시지의 헤더, 본문, 첨부 파일 등에 대한 정보를 가져올 수 있습니다.

함수 사용법

imap_fetchstructure 함수의 사용법은 다음과 같습니다.

#hostingforum.kr
php

imap_fetchstructure($imap_stream, $msg_number)



* `$imap_stream` : IMAP 서버와 연결된 스트림
* `$msg_number` : 가져올 메시지 번호

예제

다음은 imap_fetchstructure 함수를 사용하여 메시지의 구조를 가져오는 예제입니다.

#hostingforum.kr
php

<?php



// IMAP 서버와 연결

$imap_stream = imap_open('{imap.example.com:993/imap/ssl}INBOX', 'username', 'password');



// 메시지 번호 가져오기

$msg_number = imap_num_msg($imap_stream);



// 메시지의 구조 가져오기

$structure = imap_fetchstructure($imap_stream, $msg_number);



// 메시지의 헤더 가져오기

$headers = imap_headerinfo($imap_stream, $msg_number);



// 메시지의 본문 가져오기

$body = imap_body($imap_stream, $msg_number);



// 메시지의 첨부 파일 가져오기

$attachments = imap_fetchattach($imap_stream, $msg_number, 1);



// 메시지의 구조 출력

echo "메시지 번호: $msg_number
";

echo "메시지 제목: " . $headers->subject . "
";

echo "메시지 작성자: " . $headers->fromaddress . "
";

echo "메시지 본문:
";

echo $body . "
";

echo "메시지 첨부 파일:
";

echo $attachments->filename . "
";



// IMAP 서버와 연결 끊기

imap_close($imap_stream);



?>



출력 결과

이 예제를 실행하면 메시지의 구조, 헤더, 본문, 첨부 파일 등에 대한 정보가 출력됩니다.

#hostingforum.kr


메시지 번호: 1

메시지 제목: Test Message

메시지 작성자: test@example.com

메시지 본문:

Hello, World!

메시지 첨부 파일:

example.txt



주의사항

imap_fetchstructure 함수는 메시지의 구조를 가져올 때, 메시지의 첨부 파일을 포함하여 모든 데이터를 가져오므로, 메시지의 크기가 큰 경우 메모리 사용량이 증가할 수 있습니다. 또한, 메시지의 구조를 가져올 때, 메시지의 헤더와 본문이 중복으로 가져올 수 있으므로, 메시지의 헤더와 본문을 분리하여 가져올 필요가 있습니다.
  • profile_image
    나우호스팅 @pcs8404 

    호스팅포럼 화이팅!

    댓글목록

    등록된 댓글이 없습니다.

  • 전체 10,077건 / 457 페이지

검색

게시물 검색