
mailparse_rfc822_parse_addresses 함수는 이메일 주소를 파싱할 때, 주소가 여러 개인 경우도 처리할 수 있습니다.
예를 들어, 'John Doe , Jane Doe ' 이라는 이메일 주소를 파싱할 때, 다음과 같이 처리됩니다.
#hostingforum.kr
php
$result = mailparse_rfc822_parse_addresses('John Doe , Jane Doe ');
print_r($result);
이 함수의 파싱 결과는 다음과 같습니다.
#hostingforum.kr
php
Array
(
[0] => Array
(
[mailbox] => John Doe
[addrtype] => rcpt
[host] => example.com
[localpart] => john.doe
[raw] => John Doe
)
[1] => Array
(
[mailbox] => Jane Doe
[addrtype] => rcpt
[host] => example.com
[localpart] => jane.doe
[raw] => Jane Doe
)
)
이메일 주소의 수를 확인하기 위해서는 파싱 결과의 길이를 확인하면 됩니다.
#hostingforum.kr
php
$count = count($result);
echo "이메일 주소의 수: $count";
이 함수를 사용하여 이메일 주소의 유효성을 검사하는 방법은 다음과 같습니다.
#hostingforum.kr
php
function isValidEmail($email) {
$result = mailparse_rfc822_parse_addresses($email);
if (count($result) > 0) {
return true;
} else {
return false;
}
}
$email = 'John Doe ';
if (isValidEmail($email)) {
echo "$email은 유효한 이메일 주소입니다.";
} else {
echo "$email은 유효하지 않은 이메일 주소입니다.";
}
이 함수는 이메일 주소가 유효한지 확인하기 위해 mailparse_rfc822_parse_addresses 함수를 사용합니다. 유효한 이메일 주소의 경우, 파싱 결과가 비어있지 않다면 true를 반환하고, 유효하지 않은 이메일 주소의 경우 false를 반환합니다.
2025-06-13 08:24