2017-05-15 14 views
2

PHP의 inbuild mail() 기능을 사용하여 전자 메일을 보내려하지만이 메일에 두 개의 첨부 파일을 보내는 방법을 알지 못합니다. 나는 이미 Plaintext, Html Text와 하나의 첨부 파일을 내 메일에 보낼 수 있지만, 다른 하나는 보내지 못한다.PHP 전자 메일 헤더 다중 첨부 파일

나는 확실히 내 mailheader에 뭐가 잘못되었지만 무엇을 모르겠다.

$attachment = chunk_split(base64_encode(file_get_contents('/var/www/html/style/img/smalllogo.png'))); 
$attachment2 = chunk_split(base64_encode(file_get_contents('/var/www/html/style/img/header.png'))); 
//define the body of the message. 
ob_start(); //Turn on output buffering 
?> 
--PHP-mixed-<?php echo $random_hash; ?> 
Content-Type: multipart/alternative; boundary="PHP-alt-<?php echo $random_hash; ?>" 

--PHP-alt-<?php echo $random_hash; ?> 
Content-Type: text/plain; charset="iso-8859-1" 
Content-Transfer-Encoding: 7bit 

<?php echo $txtMailPlain;?> 

--PHP-alt-<?php echo $random_hash; ?> 
Content-Type: text/html; charset="iso-8859-1" 
Content-Transfer-Encoding: 7bit 

<?php echo $txtMailHtml;?> 

--PHP-alt-<?php echo $random_hash; ?>-- 

--PHP-mixed-<?php echo $random_hash; ?> 
Content-Type: image/png; name="smalllogo.png" 
Content-Transfer-Encoding: base64 
Content-Disposition: attachment 
X-Attackment-Id: 1 

<?php echo $attachment; ?> 
--PHP-mixed-<?php echo $random_hash; ?>-- 

--PHP-mixed-<?php echo $random_hash; ?> 
Content-Type: image/png; name="smalsllogo.png" 
Content-Transfer-Encoding: base64 
Content-Disposition: attachment 
X-Attackment-Id: 2 

<?php echo $attachment; ?> 
--PHP-mixed-<?php echo $random_hash; ?>-- 


<?php 
//copy current buffer contents into $message variable and delete current output buffer 
$message = ob_get_clean(); 
//send the email 
$mail_sent = @mail($to, $subject, $message, $headers); 
//if the message is sent successfully print "Mail sent". Otherwise print "Mail failed" 
echo $mail_sent ? "Mail sent" : "Mail failed"; 

나는 "smalllogo.png"라는 첫 번째 첨부 파일을 얻을하지만 난 다른 하나를 얻을 didnt는 : 은 여기 내 PHP 코드 이메일을 생성합니다. 그리고 나는 만일 내가 바른 평문 메시지를 얻었는지 확실하지 않다. 사전에

감사합니다, J. 미상)

답변

0

당신이

<?php echo $attachment; ?> 

당신이 장소 중 하나 작성해야 두 장소에 쓴이 같은 첨부 파일 분에서해야 정상적으로 <?php echo $attachment2; ?>

+0

입니다 실제로 또 다른 이름으로. 그러나 나는 그것을 바꾸려고 노력했다. 그리고 그것은 또한 일을 didnt한다. –