当我通过php文件通过电子邮件发送时,我无法正确显示我的html代码(没有html标签)。我收不到$header
或$nmessage
,以便在收件人收到电子邮件时正确显示?
我的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";
?>
答案 0 :(得分:1)
将您的Content-Type
更改为:
$nmessage .= "Content-type: text/html\r\n";
由此:
$nmessage .= "Content-type:text/plain; charset=iso-8859-1\r\n";