라이브러리
[PHP] imap_fetchheader - 메시지의 헤더를 반환합니다.
imap_fetchheader() 함수
`imap_fetchheader()` 함수는 IMAP 서버에서 메시지의 헤더를 가져옵니다. 이 함수는 메시지의 전체 헤더를 가져오거나, 특정 헤더를 가져올 수 있습니다.
함수 구조
`imap_fetchheader($imap_stream, $msg_number, $section)`
* `$imap_stream`: IMAP 연결 스트림
* `$msg_number`: 메시지 번호
* `$section`: 가져올 헤더 섹션 (선택 사항)
함수 반환
함수는 가져온 헤더를 문자열로 반환합니다.
예제
#hostingforum.kr
php
// IMAP 서버 연결
$imap_stream = imap_open("{imap.gmail.com:993/imap/ssl}INBOX", "your_email@gmail.com", "your_password");
// 메시지 번호
$msg_number = 1;
// 메시지 헤더 가져오기
$header = imap_fetchheader($imap_stream, $msg_number);
// 헤더 출력
echo "메시지 헤더:
";
echo $header;
// IMAP 연결 닫기
imap_close($imap_stream);
헤더 섹션 가져오기
`imap_fetchheader()` 함수의 `$section` 매개변수를 사용하면 특정 헤더 섹션만 가져올 수 있습니다. 예를 들어, `Subject` 헤더를 가져오려면 `$section`을 `"Subject"`로 설정합니다.
#hostingforum.kr
php
// 메시지 헤더 가져오기 (Subject만)
$header = imap_fetchheader($imap_stream, $msg_number, "Subject");
// 헤더 출력
echo "Subject:
";
echo $header;
헤더의 특정 부분 가져오기
`imap_fetchheader()` 함수의 `$section` 매개변수를 사용하면 헤더의 특정 부분만 가져올 수 있습니다. 예를 들어, `Subject` 헤더의 첫 10자만 가져오려면 `$section`을 `"Subject:0:10"`으로 설정합니다.
#hostingforum.kr
php
// 메시지 헤더 가져오기 (Subject의 첫 10자만)
$header = imap_fetchheader($imap_stream, $msg_number, "Subject:0:10");
// 헤더 출력
echo "Subject의 첫 10자:
";
echo $header;
이 예제는 `imap_fetchheader()` 함수의 기본 사용법과 헤더 섹션, 헤더의 특정 부분 가져오기 방법을 설명합니다.
-
- 나우호스팅 @pcs8404
-
호스팅포럼 화이팅!
댓글목록
등록된 댓글이 없습니다.