2012-08-08 4 views
2

IMAP 서버에 연결하고 [email protected]으로 보낸 모든 전자 메일을 찾고 싶습니다. 나는 시도 :PHP를 사용하는 IMAP 서버에서 정확한 전자 메일 주소로 전자 메일 찾기

$mbox = imap_open("{imap.server.tld/norsh}", "[email protected]", "5ecure3"); 
$result = imap_search($mbox, "TO \"[email protected]\"", SE_UID); 

하지만,이 또한 예를 들어, 송신 된 전자 메일을 나열 [email protected]. 어떻게하면 정확한 일치 검색을 할 수 있습니까?

답변

2

짧은 답 : 할 수 없습니다. 내가 할 수 있다고 말하는 RFC 2060 - Internet Message Access Protocol - Version 4rev1에서 아무것도 찾지 못했습니다.

그러나 해결 방법이 있습니다. 먼저 [email protected]이 포함 된 모든 이메일을 가져온 다음 결과를 반복하고 정확한 일치 항목 만 선택하십시오.

$searchEmail = "[email protected]"; 
$emails = imap_search($mbox, "TO $searchEmail"); 
$exactMatches = array(); 

foreach ($emails as $email) { 
    // get email headers 
    $info = imap_headerinfo($mbox, $email); 

    // fetch all emails in the TO: header 
    $toAddresses = array(); 
    foreach ($info->to as $to) { 
     $toAddresses[] = $to->mailbox . '@' . $to->host; 
    } 

    // is there a match? 
    if (in_array($searchEmail, $toAddresses)) { 
     $exactMatches[] = $email; 
    } 
} 

지금 모든 이메일 $exactMatches

+0

멋진 대답 [email protected] 일치해야 물론이 해결뿐만 아니라, subject' '같은 다른 필드를 검색을 위해 작동합니다. –

관련 문제