2017-12-01 11 views
-1

PHP 코드를 전자 메일로 보내면 HTML 태그가 제대로 표시되지 않는 문제가 있습니다. 수신자가 전자 메일을 받으면 $header 또는 $nmessage이 제대로 표시되지 않습니다. 내 PHP 스크립트는 HTML 코드와 함께 다음과 같다PHP 파일을 통해 HTML을 전자 메일로 보내기

는 왼쪽으로 :

<?php 

if(@$_REQUEST['weakPassword'] != "TEST") 
{ 
echo "failed"; 
die(); 
} 

function mail_attachment_from_file($the_file, $filename , $mailto, $from_mail, $from_name, $replyto, $subject, $message) 
{ 
$content = $the_file; 
$content = chunk_split(base64_encode($content)); 
$uid = md5(uniqid(time())); 
$header = "From: ".$from_name." <".$from_mail.">\r\n"; 
$header .= "Reply-To: ".$replyto."\r\n"; 
$header .= "MIME-Version: 1.0\r\n"; 
$header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n"; 
$nmessage = "--".$uid."\r\n"; 
$nmessage .= "Content-type:text/plain; charset=iso-8859-1\r\n"; 
$nmessage .= "Content-Transfer-Encoding: 7bit\r\n\r\n"; 
$nmessage .= $message."\r\n\r\n"; 
$nmessage .= "--".$uid."\r\n"; 
$nmessage .= "Content-Type: application/octet-stream; name=\"".$filename."\"\r\n"; 
$nmessage .= "Content-Transfer-Encoding: base64\r\n"; 
$nmessage .= "Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n"; 
$nmessage .= $content."\r\n\r\n"; 
$nmessage .= "--".$uid."--"; 

mail($mailto, $subject, $nmessage, $header); 

return true; 
} 

$to = @$_REQUEST['emailGuest']; 
$from = @$_REQUEST['emailFrom']; 

$subject = @$_REQUEST['emailSubject']; 

$message = ' 
<html> 
// HTML code 
</html>'; 

$fileName = @$_REQUEST['fileName']; 

$sep = sha1(date('r', time())); 

// Read in our file attachment 
$the_file = file_get_contents($_FILES['Filedata']['tmp_name']); 

mail_attachment_from_file($the_file, $fileName , $to, $from, "BLAH", $from, $subject, $message); 

echo "done"; 

?> 
+1

'Content-type : text/plain; charset = iso-8859-1' 이것은 당신의 범인입니다. 전자 메일은 일반 텍스트 형식으로 전송됩니다. – hungrykoala

+0

PEAR 또는 메일에 적절한 MIME 경계를 만드는 데 도움이되는 다른 라이브러리를 사용할 수도 있습니다. 이렇게하면 스팸처럼 보이지 않고 RFC 표준을 충족하는 데 도움이됩니다. 또한 HTML 형식의 전자 메일을 보내는 경우 RFC 상태를 기억하십시오. 적절한 TEXT MIME 버전도 있어야합니다. – Twisty

+0

@Twisty PEAR 또는 [phpmailer] (https://github.com/PHPMailer/PHPMailer) 라이브러리를 권하겠습니까? – hungrykoala

답변

1

Content-Type이로 변경

$nmessage .= "Content-type:text/plain; charset=iso-8859-1\r\n"; 

확인 here이에서

$nmessage .= "Content-type: text/html\r\n"; 

: