
mailparse_msg_parse 함수의 return 값은 MailparseMessage 구조체로 반환됩니다. 이 구조체는 다음과 같은 필드를 포함합니다.
- headers: 메일의 헤더 정보를 포함하는 배열입니다.
- body: 메일의 본문 정보를 포함하는 배열입니다.
- attachments: 메일의 첨부파일 정보를 포함하는 배열입니다.
이러한 필드를 접근하기 위해서는, mailparse_msg_parse 함수의 return 값을 MailparseMessage 구조체로 캐스팅해야 합니다.
예를 들어, 다음과 같이 헤더와 본문을 구분하고 첨부파일의 정보를 접근할 수 있습니다.
#hostingforum.kr
php
$parse_result = mailparse_msg_parse($email_message);
$headers = $parse_result->headers;
$body = $parse_result->body;
$attachments = $parse_result->attachments;
foreach ($headers as $header) {
echo $header->name . ": " . $header->value . "n";
}
foreach ($body as $part) {
echo $part->ctype . "n";
echo $part->disposition . "n";
echo $part->filename . "n";
echo $part->language . "n";
echo $part->mimetype . "n";
echo $part->size . "n";
echo $part->type . "n";
}
foreach ($attachments as $attachment) {
echo $attachment->ctype . "n";
echo $attachment->disposition . "n";
echo $attachment->filename . "n";
echo $attachment->language . "n";
echo $attachment->mimetype . "n";
echo $attachment->size . "n";
echo $attachment->type . "n";
}
이러한 예제를 통해, mailparse_msg_parse 함수의 return 값을 어떻게 구조화되어 있는지와 헤더와 본문을 구분하고 첨부파일의 정보를 접근하는 방법을 이해할 수 있습니다.
2025-04-25 14:29