2011-10-18 4 views
0

PHP로 이메일을 처리 할 때 꽤 새로운입니다.이메일 첨부 파일을 이메일 메시지로 저장하는 방법은 무엇입니까?

기본적으로 pop3 사서함을 읽고 메시지를 데이터베이스에 저장하고 첨부 파일을 폴더에 저장해야합니다. 그런 다음 동일한 이메일 (약간 변경됨)을 다른 이메일 수신자에게 다시 보냅니다.

나는이 모든 것이 작동한다고 생각하고 첨부 파일이 텍스트 (body64_decode 이후)로만 수신되는 다른 메일 메시지 인 것을 깨달았습니다.

첨부 된 전자 메일을 파일로 저장 한 다음 다른 메시지의 첨부 파일로 보낼 수 있습니까?

도움이 될 것입니다.

// This is the IMAP connection: imap_open("{"."$host:$port/pop3$ssl"."}$folder",$user,$pass,OP_SILENT); 
$mailConnection = $this->Maildata->mail_login($host,$port,$user,$pass,$folder,$ssl); 

// This retrieves the list of mails in the current folder 
$messageList = $this->Maildata->mail_list($mailConnection,$message); 
foreach ($messageList as $messageId => $messageListData) { 

    // This reads the mail object into an array 
    $mailMessage = $this->Maildata->mail_mime_to_array($mailConnection,$messageId,true); 

    // This loops through each mail 
    foreach ($mailMessage as $tmpId => $tmpData) { 
     // Excluded save to database since it is unrelated 

     // This checks if item is an attachment and saves it. 
     if (isset($tmpData['is_attachment']) && $tmpData['is_attachment'] === true) { 
      $tmpName = date('Y-m-d H:i:s', strtotime('now')); 
      $this->Maildata->mail_attachment_save($tmpData['data'], $tmpName .$tmpData['name']); 
     } 
    } 
} 

추신 : 여기

관점에 넣어 몇 가지 코드 이 모든 작동하지만, imap_fetchbody($mailConnection , $messageId, $prefix); 필요한 모든 데이터를 보내는 것 같지 않습니다.

+0

코드를 알려주십시오. 그것은 "다른 메시지"라고 말하는 것이 맞지 않습니다. 어떤 MIME 파서를 사용하고 있습니까? – DaveRandom

+0

이것은 도움이 될 수 있습니다 : http://php.net/manual/en/book.imap.php 'IMAP'이라고 쓰여 있지만 POP와도 호환 될 수 있다고 생각합니다. –

+0

@DaveRandom IMAP을 사용하여 메일 함에 연결하고 있습니다. 몇 가지 코드를 추가하겠습니다 만 도움이된다고는 생각하지 않습니다. – Nightwolf

답변

0

예.

첨부 된 메일 메시지를 파일로 저장할 수는 있지만 Microsoft Office Outlook에서 인식 할 수있는 형식이 아닙니다. 흥미롭게도 파일을 .eml로 저장하면 Windows Live Mail이 메시지를 완벽하게 처리합니다.

Outlook과 바람이 불고있는 라이브 메일처럼 첨부 된 메일 항목을 처리하는 웹 메일 서비스가 없으며 gmail이이를 완전히 무시합니다.

관련 문제