2014-02-13 3 views
1

PHP를 사용하여 AmazonSES를 통해 이미지 첨부 파일이있는 원시 이메일을 보내려고합니다. 이메일을 gmail 계정으로 보내면 핫메일 계정에 빈 이미지가 전송됩니다. 다시 말해, 핫메일은 첨부 파일이 있다는 것을 인식하는 것으로 보이며이 첨부 파일은 내가 지정한 정확한 이름을 가지고 있습니다. 단지 0 바이트 크기의 항상 비어 있습니다. 인터넷 검색이 도움이되지 않습니다 ... 미리 감사드립니다!이미지 첨부 파일을 수신하지 못합니다.

$amazonSES = new AmazonSES(); 

// if (empty($attach)==0) { 
    // $response = $amazonSES->send_email(AWS_SES_FROM_EMAIL, 
     // array('ToAddresses' => array($to)), 
     // array('Subject.Data' => $subject,'Body.Text.Data' => $messagein,) 
    //); 
// } else { 
    $rstring = 'ajfas90lsjhntlen89y34oi598'; 

    $message= "To: ".$to."\n"; 
    $message.= "From: " . AWS_SES_FROM_EMAIL . "\n"; 
    $message.= "Subject: " . $subject . "\n"; 
    $message.= "MIME-Version: 1.0\n"; 
    $message.= 'Content-Type: multipart/mixed; boundary="ARandomString'.$rstring.'"'; 
    $message.= "\n\n"; 
    $message.= "--ARandomString$rstring\n"; 
    $message.= 'Content-Type: text/plain; charset="utf-8"'; 
    $message.= "\n"; 
    $message.= "Content-Transfer-Encoding: 7bit\n"; 
    $message.= "Content-Disposition: inline\n"; 
    $message.= "\n"; 
    $message.= $messagein; 
    $message.= "\n\n"; 
    $message.= "--ARandomString$rstring\n"; 

    foreach ($attach as $attachment) { 
     // $message.= "Content-ID: \<[email protected]_IS_ADDED\>\n"; 
     $message.= "Content-ID: \<". md5(uniqid(rand(), true)) ."@biomechanico.com\>\n"; 
     $message.= 'Content-Type: application/zip; name="shell.zip"'; 
     $message.= "\n"; 
     $message.= "Content-Transfer-Encoding: base64\n"; 
     $message.= 'Content-Disposition: attachment; filename="' . $attachment["name"] . '"'; 
     $message.= "\n" . base64_encode(file_get_contents($attachment["file"])) . "\n"; 
     $message.= "--ARandomString$rstring\n"; 
    } 

    $response = $amazonSES->send_raw_email(array(
        'Data'=> base64_encode($message)), 
         array('Source'=>AWS_SES_FROM_EMAIL, 'Destinations'=> $to)); 

답변

2

잘못된 형식의 메시지를 생성하고 있습니다.

메일 메시지를 생성 할 때 원시 문자열에서 함께 묶는 대신 적절한 라이브러리를 사용하는 것이 좋습니다.

그렇지 않은 경우 여기를 클릭하십시오. 첨부 파일에서

--ARandomStringajfas90lsjhntlen89y34oi598--

보다는

--ARandomStringajfas90lsjhntlen89y34oi598

  • :

    1. 최종 멀티 경계해야합니다 마지막 줄 즉, 별도의 --로 끝나야 부품 사이에 빈 줄이없는 경우 Content-Disposition 헤더 행과 본문.

    2. 메시지 행은 998자를 초과 할 수 없지만 Base64로 인코딩 된 첨부 데이터는 항상 한 행에 있습니다.

    3. Content-ID: \<whatever\>을 생산하지만 생산해야한다고에서 지금까지 내가 PHP를 이해, 부착 부분에 Content-ID에 대한 구문이 잘못 Content-ID: <whatever>

    4. 라인이 CR LF (\r\n)하지만 종료해야 LF (\n) 있습니다.

    디버그 메시지 문제에 대한 좋은 방법은 실제 전체 생성 된 메시지 소스 ($message)를 타고 Message Lint를 통해 실행하는 것입니다. 위의 제안 사항이 도움이되지 않으면 PHP 코드가 아닌 생성 된 메시지 소스를 게시하십시오.

    인터넷 메시지 형식은 RFC 5322을 참조하십시오. 멀티 파트 메시지 구문은 RFC 2046을 참조하십시오.

  • +0

    내 문제가 해결되었습니다. 나는 PHPmailer를 사용하려고 시도했지만 어떻게 그것을 amazonses와 함께 작동시킬 수 있는지 알 수 없었다. 다시 한 번 감사드립니다 – nbunderson

    +1

    @nbunderson ['getSentMIMEMessage'] (http://phpmailer.github.io/PHPMailer/classes/PHPMailer.html#method_getSentMIMEMessage)와 같은 것을 호출하고 결과 문자열을'$ message'에 할당해야합니다. –

    관련 문제