2017-12-01 18 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

あなたのメールに適切なMIME境界を作成するのに役立つPEARまたは他のライブラリの使用を検討することもできます。これにより、SPAMのように見えなくなり、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"; 

関連する問題