2012-10-07 2 views
0

나는 메시지점점 이상한 결과

function sendemail($to, $from, $subject, $filename, $attachment_name) { 

    $random_hash = md5(date('r', time())); 

    $headers = "From: $from\r\nReply-To: $from"; 

    $headers .= "\r\nContent-Type: multipart/mixed; boundary=\"PHP-mixed-" . $random_hash . "\""; 

    $attachment = chunk_split(base64_encode(file_get_contents($filename))); 

    $output = " 
--PHP-mixed-$random_hash 
Content-Type: multipart/alternative; boundary='\"PHP-alt-$random_hash\"' 

Hello World! 
This is the simple text version of the email message. 


--PHP-alt-$random_hash 
Content-Type: text/html; charset=\"UTF8\" 
Content-Transfer-Encoding: 7bit 


<h2>Hello World!</h2> 
<p>This is the <b>HTML</b> version of the email message.</p> 

--PHP-alt-$random_hash-- 

--PHP-mixed-$random_hash 
Content-Type: application/zip; name=$attachment_name 
Content-Transfer-Encoding: base64 
Content-Disposition: attachment 

$attachment 
--PHP-mixed-$random_hash--"; 

    if (@mail($to, $subject, $output, $headers)) { 
     echo 'good'; 
    } else { 
     echo 'bad'; 
    } 
} 

를 함께 첨부 파일을 이메일로이 기능을 사용하지만, 여기에 실제 메시지의 스크린 샷이다있어 내가 얻을 : enter image description here

은 어떻게받을 수 있나요 이메일에있는

--PHP-alt-a08184c8a852c31ac8c508fe6ca357d8 
Content-Type: text/html; charset="UTF8" 
Content-Transfer-Encoding: 7bit 

제거하고 실제로 메타

+0

SWIFT 메일러 또는 PHPmailer를 사용하지 않는 이유는 무엇입니까? –

+0

이 메일은 내가 사용하는 유일한 이메일이기 때문에 – qwertymk

+0

빠른 우편물을 사용하면 문제가 사라질 것입니다. –

답변

2

로 사용 공통 변수

$to = '[email protected]'; 
$from = '[email protected]'; 
$subject = 'Subject 123'; 
$body = '<b>Hello World</b>'; 
$filename = 'index.rar'; 

귀하의 코드

function sendemail($to, $from, $subject, $body, $filename) { 
    $random_hash = md5(date('r', time())); 
    $headers = "From: $from\r\nReply-To: $from"; 
    $headers .= "\r\nContent-Type: multipart/mixed; boundary=\"PHP-mixed-" . $random_hash . "\""; 
    $attachment = chunk_split(base64_encode(file_get_contents($filename))); 
    $output = " 
--PHP-mixed-$random_hash 
Content-Type: multipart/alternative; boundary='\"PHP-alt-$random_hash\"' 

" . strip_tags($body) . " 

--PHP-alt-$random_hash 
Content-Type: text/html; charset=\"UTF8\" 
Content-Transfer-Encoding: 7bit 

" . $body . " 

--PHP-alt-$random_hash-- 

--PHP-mixed-$random_hash 
Content-Type: application/zip; name=" . basename($filename) . " 
Content-Transfer-Encoding: base64 
Content-Disposition: attachment 

$attachment 
--PHP-mixed-$random_hash--"; 
    return mail($to, $subject, $output, $headers); 
} 
sendemail($to, $from, $subject, $body, $filename); 

귀하 보낸 이메일

Date: Sun, 07 Oct 2012 19:54:06 +0200 
Subject: Subject 123 
To: [email protected] 
X-PHP-Originating-Script: 0:index.php 
From: [email protected] 
Reply-To: [email protected] 
Content-Type: multipart/mixed; boundary="PHP-mixed-488d21ec53bdcff8cfe3f5ab49010354" 


--PHP-mixed-488d21ec53bdcff8cfe3f5ab49010354 
Content-Type: multipart/alternative; boundary='"PHP-alt-488d21ec53bdcff8cfe3f5ab49010354"' 

Hello World 

--PHP-alt-488d21ec53bdcff8cfe3f5ab49010354 
Content-Type: text/html; charset="UTF8" 
Content-Transfer-Encoding: 7bit 

<b>Hello World</b> 

--PHP-alt-488d21ec53bdcff8cfe3f5ab49010354-- 

--PHP-mixed-488d21ec53bdcff8cfe3f5ab49010354 
Content-Type: application/zip; name=index.rar 
Content-Transfer-Encoding: base64 
Content-Disposition: attachment 

UmFyIRoHAM+QcwAADQAAAAAAAABUw3QgkC4AGQMAAIkGAAACwova3OadR0EdMwkAIAAAAGluZGV4 
LnBocACwSVdsDYFRDMy9FBW9ipX8O1CJPYlHGddFJLQKBVTwEqiwR41JrY3sjYPpHuwtgI/7ngWy 
N7r3N1xxyQLUHvPGN5085nRx/nM5zOrdzc3F8vvx2H0Svy7+9BHA4UhhMvmihcJNNJMVm6xkHDQt 
zBR62LkxJdKY68ovAto6/Ixawy0NxWg9u+fZpb7bfToLwVa9Gg9uIceZAbZI2zkyk6qE02RBc+dJ 
eIV0cvWWP+xbMgrhYZ0vphkoeFDBTXnZImQrNvIjuJTxX//R8XNj+dJRlQOfV5eHxeNbrHI9nU3w 
4+LlJCfTHyp/hewtz6qtQQkjHETspVepfpeHMpzocmamNNMkbCfwcJGOkQGN1hZPXWKxa6wsFusa 
6XcY/B+sB+t9Y+TrcfGV8ASJ7yieGYgmUQncho6RXNBg1Rb5BolmKETa5ABL9QT0TdEfwJLDnaxS 
amVrdkXgkqifXTWhzRHTnlIdcWaFEUqTA0CDqI9gYplSgj6bPw9Frm5eZpbVq0fu2aLwUu1rA02m 
G6/EFXAszhAH0cLSZAYWM6yebyOBshPaRlX8cykM47UQlFZg9ZcEfml0SrkoBpqwi7I7RPa2OOcJ 
sQjPfsTYstmqzwPNqkUKyrYVW4U0yAHEjZSiXqq4q47+9WQ7s83SJOupHakJwBfqMQRAMe/HFyef 
S7EdCiFDtdr2qwaCHD34McBqyFYz3YxQu/vf74XHKGhnQwX2G/ul2lpWbnDsascUw7ou1bEsg+yA 
sshYFVN9iylLU1s+3amLTSuNu9MQ2aaNjYRZYiirft3X10rhr86L/5L9anEUfXNBpHKbnQSoNsvT 
BkM3DBjq8XNT95XxcZCSHxfqwMr5eB0DnXC+8BbFW1v34ydPunaalVC5CitTPtR+fbcTZV6pBClH 
lJZJq99yV1W9uBi1riDlCl2iHMgnOJd+XNbnFJW3NJY1XsekkVQLr2rfBQODjgNWwFZI4/2zi1ZK 
Z19pZqfjee5gTAX8IuVxcsKeY648vgvUPfVr4aR4o9IGM/sr+njZkhRJjeFXiNzBKi0Oqki25qBB 
c9AfpMQ9ewBABwA= 

--PHP-mixed-488d21ec53bdcff8cfe3f5ab49010354-- 

스위프트 코드

require_once('swift/lib/swift_required.php'); 
$transport = Swift_MailTransport::newInstance(); 
$mailer = Swift_Mailer::newInstance($transport); 
$message = Swift_Message::newInstance($subject) 
    ->setFrom(array($from)) 
    ->setTo(array($to)) 
    ->setEncoder(Swift_Encoding::get7BitEncoding()) 
    ->setBody($body, 'text/html') 
    ->addPart(strip_tags($body), 'text/plain') 
    ->attach(Swift_Attachment::fromPath($filename)) 
; 
$mailer->send($message); 

스위프트가 보낸 이메일

Subject: Subject 123 
To: [email protected] 
X-PHP-Originating-Script: 0:SimpleMailInvoker.php 
Message-ID: <[email protected]> 
Date: Sun, 07 Oct 2012 19:49:22 +0200 
From: [email protected] 
MIME-Version: 1.0 
Content-Type: multipart/mixed; 
boundary="_=_swift_v4_13496321625071c0a297e85_=_" 


--_=_swift_v4_13496321625071c0a297e85_=_ 
Content-Type: multipart/alternative; 
boundary="_=_swift_v4_13496321625071c0a298e1b_=_" 


--_=_swift_v4_13496321625071c0a298e1b_=_ 
Content-Type: text/plain; charset=utf-8 
Content-Transfer-Encoding: quoted-printable 

Hello World 

--_=_swift_v4_13496321625071c0a298e1b_=_ 
Content-Type: text/html; charset=utf-8 
Content-Transfer-Encoding: 7bit 

<b>Hello World</b> 

--_=_swift_v4_13496321625071c0a298e1b_=_-- 


--_=_swift_v4_13496321625071c0a297e85_=_ 
Content-Type: application/x-rar-compressed; name=index.rar 
Content-Transfer-Encoding: base64 
Content-Disposition: attachment; filename=index.rar 

UmFyIRoHAM+QcwAADQAAAAAAAABUw3QgkC4AGQMAAIkGAAACwova3OadR0EdMwkAIAAAAGluZGV4 
LnBocACwSVdsDYFRDMy9FBW9ipX8O1CJPYlHGddFJLQKBVTwEqiwR41JrY3sjYPpHuwtgI/7ngWy 
N7r3N1xxyQLUHvPGN5085nRx/nM5zOrdzc3F8vvx2H0Svy7+9BHA4UhhMvmihcJNNJMVm6xkHDQt 
zBR62LkxJdKY68ovAto6/Ixawy0NxWg9u+fZpb7bfToLwVa9Gg9uIceZAbZI2zkyk6qE02RBc+dJ 
eIV0cvWWP+xbMgrhYZ0vphkoeFDBTXnZImQrNvIjuJTxX//R8XNj+dJRlQOfV5eHxeNbrHI9nU3w 
4+LlJCfTHyp/hewtz6qtQQkjHETspVepfpeHMpzocmamNNMkbCfwcJGOkQGN1hZPXWKxa6wsFusa 
6XcY/B+sB+t9Y+TrcfGV8ASJ7yieGYgmUQncho6RXNBg1Rb5BolmKETa5ABL9QT0TdEfwJLDnaxS 
amVrdkXgkqifXTWhzRHTnlIdcWaFEUqTA0CDqI9gYplSgj6bPw9Frm5eZpbVq0fu2aLwUu1rA02m 
G6/EFXAszhAH0cLSZAYWM6yebyOBshPaRlX8cykM47UQlFZg9ZcEfml0SrkoBpqwi7I7RPa2OOcJ 
sQjPfsTYstmqzwPNqkUKyrYVW4U0yAHEjZSiXqq4q47+9WQ7s83SJOupHakJwBfqMQRAMe/HFyef 
S7EdCiFDtdr2qwaCHD34McBqyFYz3YxQu/vf74XHKGhnQwX2G/ul2lpWbnDsascUw7ou1bEsg+yA 
sshYFVN9iylLU1s+3amLTSuNu9MQ2aaNjYRZYiirft3X10rhr86L/5L9anEUfXNBpHKbnQSoNsvT 
BkM3DBjq8XNT95XxcZCSHxfqwMr5eB0DnXC+8BbFW1v34ydPunaalVC5CitTPtR+fbcTZV6pBClH 
lJZJq99yV1W9uBi1riDlCl2iHMgnOJd+XNbnFJW3NJY1XsekkVQLr2rfBQODjgNWwFZI4/2zi1ZK 
Z19pZqfjee5gTAX8IuVxcsKeY648vgvUPfVr4aR4o9IGM/sr+njZkhRJjeFXiNzBKi0Oqki25qBB 
c9AfpMQ9ewBABwA= 

--_=_swift_v4_13496321625071c0a297e85_=_-- 

는 이메일 또는 SWIFTmailer를 사용 사이의 차이점을 찾아보십시오.

+0

@qwertymk 차이점을 찾으셨습니까? –