
mailparse_msg_get_structure 함수는 이메일 메시지의 구조를 반환하는 함수로, 반환 값은 배열 형태로 구조를 나타냅니다.
struct 변수는 배열 데이터 타입을 가집니다.
struct 변수를 사용하여 메시지 구조를 출력하는 방법은 다음과 같습니다.
#hostingforum.kr
php
$message = mailparse_msg_open($file_path);
$struct = mailparse_msg_get_structure($message);
foreach ($struct as $part) {
echo $part['type'] . "n";
echo $part['subtype'] . "n";
echo $part['disposition'] . "n";
echo $part['parameters']['content-type'] . "n";
echo $part['parameters']['content-transfer-encoding'] . "n";
echo $part['parameters']['content-disposition'] . "n";
echo $part['parameters']['filename'] . "n";
}
위 코드는 메시지 구조를 출력하는 예시입니다.
To 헤더의 값을 출력하는 코드는 다음과 같습니다.
#hostingforum.kr
php
$message = mailparse_msg_open($file_path);
$struct = mailparse_msg_get_structure($message);
foreach ($struct as $part) {
if ($part['type'] == 'text' && $part['subtype'] == 'plain') {
$headers = mailparse_msg_get_part_data($message, $part['number']);
$headers = explode("n", $headers);
foreach ($headers as $header) {
if (strpos($header, 'To:') !== false) {
echo trim(substr($header, strpos($header, ':') + 1)) . "n";
}
}
}
}
위 코드는 To 헤더의 값을 출력하는 예시입니다.
이메일 메시지의 구조를 분석하고 헤더 값을 출력하는 코드를 작성하는 방법은 위 예시를 참고하시면 됩니다.
2025-05-15 10:45