2012-06-28 2 views
3

IMAP/POP 사서함에 로그인하고 새 이메일 주소로 콘텐츠를 전달한 다음 스크립트를 실행하여 사서함에서 스크립트를 제거합니다.PHP IMAP POP 전달 스크립트가 어떻게 든 이미지 첨부 파일을 보냅니다.

Ning의 사이트로 전송되는 첨부 된 이미지는 부숴 보이지만 Ning의 업로드 이메일 주소로 직접 전송 된 이미지 첨부 파일은 완벽하게 형성되는 반면에, 이상하게 설명 할 수없는 이유를 제외하고는 거의 작동합니다. 따라서 전달 된 이메일 형식에 대해 다른 점이 있습니다. 마치 첨부 파일의 이미지가 원래 있던 이미지와 정확히 같지 않은 것처럼 말입니다. 으 깨진 이미지의 예는 http://members.bigmanwalking.com/photo/a-test-photo?context=latest

어떤 도움이 좋을 것 업로드

... 그것은 이미지가이 스크립트를 통해 이동하여 갑자기 자신의 형태를 잃은해야하는 이유 퍼즐입니다.

<?php 

     // Change to your mail server 
     $host = "pop.1and1.co.uk"; 

     // Connecting to POP3 email server. 
     $connection = imap_open("{" . $host . ":110/pop3/notls}", '[email protected]', 'xxxx'); 

     // Total number of messages in Inbox 
     $count = imap_num_msg($connection); 
     echo $count . " messages found<br />"; 

     // Read Messages in Loop, Forward it to Actual User email and than delete it from current email account. 
     for ($i = 1; $i <= $count; $i++) { 
      $headers = imap_headerinfo($connection, $i); 

      $subject = $headers->subject; 

      $from = $headers->from[0]->mailbox . '@' . $headers->from[0]->host; 
      if ($headers->cc[0]->mailbox) 
       $cc = $headers->cc[0]->mailbox . '@' . $headers->cc[0]->host; 
      $subject = $headers->subject; 

      $structure = imap_fetchstructure($connection, $i); 
      //$type = $this->get_mime_type($structure); 

      // GET HTML BODY 
      //$body = $this->get_part($connection, $i, ""); 

      $raw_body = imap_body($connection, $i); 

      $attachments = array(); 

      if (isset($structure->parts) && count($structure->parts)) { 
       for ($e = 0; $e < count($structure->parts); $e++) { 
        $attachments[$e] = array('is_attachment' => false, 'filename' => '', 'name' => '', 'attachment' => ''); 

        if ($structure->parts[$e]->ifdparameters) { 
         foreach ($structure->parts[$e]->dparameters as $object) { 
          if (strtolower($object->attribute) == 'filename') { 
           $attachments[$e]['is_attachment'] = true; 
           $attachments[$e]['filename'] = $object->value; 
          } //if (strtolower($object->attribute) == 'filename') 
         } //foreach ($structure->parts[$e]->dparameters as $object) 
        } //if ($structure->parts[$e]->ifdparameters) 

        if ($structure->parts[$e]->ifparameters) { 
         foreach ($structure->parts[$e]->parameters as $object) { 
          if (strtolower($object->attribute) == 'name') { 
           $attachments[$e]['is_attachment'] = true; 
           $attachments[$e]['name'] = $object->value; 
          } //if (strtolower($object->attribute) == 'name') 
         } //foreach ($structure->parts[$e]->parameters as $object) 
        } //if ($structure->parts[$e]->ifparameters) 

        if ($attachments[$e]['is_attachment']) { 
         $attachments[$e]['attachment'] = @imap_fetchbody($connection, $i, $e + 1); 
         if ($structure->parts[$e]->encoding == 3) { 
          // 3 = BASE64 
          $attachments[$e]['attachment'] = base64_decode($attachments[$e]['attachment']); 
         } //if ($structure->parts[$e]->encoding == 3) 
         elseif ($structure->parts[$e]->encoding == 4) { 
          // 4 = QUOTED-PRINTABLE 
          $attachments[$e]['attachment'] = quoted_printable_decode($attachments[$e]['attachment']); 
         } //elseif ($structure->parts[$e]->encoding == 4) 
        } //if ($attachments[$e]['is_attachment']) 

        if ($attachments[$e]['is_attachment']) { 
         $filename = $attachments[$e]['filename']; 
         $filename = $attachments[$e]['name']; 
         $filecontent = $attachments[$e]['attachment']; 
        } //if ($attachments[$e]['is_attachment']) 
       } //for ($e = 0; $e < count($structure->parts); $e++) 
      } //if (isset($structure->parts) && count($structure->parts)) 



      echo "<pre>"; 
      echo "From: " . $headers->Unseen . "<br />"; 
      echo "From: " . $from . "<br />"; 
      echo "Cc: " . $cc . "<br />"; 
      echo "Subject: " . $subject . "<br />"; 
      echo "Content Type: " . $type . "<br />"; 
      echo "Body: " . $body . "<br />"; 


      $mail = new Zend_Mail(); 

      $mail->settype(Zend_Mime::MULTIPART_MIXED); 

      for ($k = 0; $k < count($attachments); $k++) { 
       $filename = $attachments[$k]['name']; 
       $filecontent = $attachments[$k]['attachment']; 

       if ($filename && $filecontent) { 
        $file = $mail->createAttachment($filecontent); 
        $file->filename = $filename; 
       } //if ($filename && $filecontent) 
      } //for ($k = 0; $k < count($attachments); $k++) 


      $mail->setFrom($from); 
      $mail->addTo('[email protected]'); 
      if ($cc) 
       $mail->addCc($cc); 
      $mail->setSubject($subject); 
      $mail->setBodyHtml($body); 
      $mail->send(); 

      // Mark the email messages once read 
      imap_delete($connection, $i); 

     } //for ($i = 1; $i <= $count; $i++) 
     // Delete all marked message from current email account. 

     imap_expunge($connection); 

?>

+0

발견 나는 위의 스크립트의 첨부 파일에 MIME 타입을 적용하지 않는 문제를 좁혀했습니다. – Nimloc

답변

1

답을 찾을. 첨부 파일의 Mime 유형을 감지하고 보내는 이메일의 첨부 파일에 Mime 유형을 추가하는 것이 었습니다. 이 작업이 완료되면 Ning의 사진이 정확한 비율로 나타납니다.

내가 필요한 도움은 여기 http://php.net/manual/en/function.imap-fetchstructure.php