dongqigu0429 2016-04-24 07:53
浏览 64

带附件和HTML的php邮件

I have been trying to get mail to send html emails however it seems that whenever i change the header from
$message .= "Content-type:text/plain; charset=iso-8859-1 "; to
$message .= "Content-type:text/html; charset=iso-8859-1 ";

the email does not arrive.When using text/plain, i receive the email however the html is not rendered, in other words i received the code rather than formatted html. Changing to text/html, the email is not received at all. I have tried using UTF-8 but can not seem to solve it after hours of searching. Any help would be appreciated.

function mail_attachment($filename, $path, $mailto, $from_mail, $from_name, $replyto, $subject, $emessage) {
$file = $path.$filename;
$file_size = filesize($file);
$handle = fopen($file, "r");
$content = fread($handle, $file_size);
fclose($handle);
$content = chunk_split(base64_encode($content));
$uid = md5(uniqid(time()));
$name = basename($file);

$header = "From: ".$from_name." <".$from_mail.">
";
$header .= "Reply-To: ".$replyto."
";
$header .= "MIME-Version: 1.0
";
$header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"

";
$message = "--".$uid."
";
$message .= "Content-type:text/plain; charset=iso-8859-1
";
//$message .= "Content-Type: text/html; charset=\"UTF-8\""."
";
//$message .= "Content-type:text/html; charset=UTF-8
";
$message .= "Content-Transfer-Encoding: 7bit

";
$message .= $emessage."

";
$message .= "--".$uid."
";
$message .= "Content-Type: application/octet-stream; name=\"".$filename."\"
"; 
$message .= "Content-Transfer-Encoding: base64
";
$message .= "Content-Disposition: attachment; filename=\"".$filename."\"

";
$message .= $content."

";
$message .= "--".$uid."--";
return mail($mailto, $subject, $message, $header);
   }
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
    • ¥15 CSAPPattacklab
    • ¥15 一直显示正在等待HID—ISP
    • ¥15 Python turtle 画图
    • ¥15 关于大棚监测的pcb板设计
    • ¥15 stm32开发clion时遇到的编译问题
    • ¥15 lna设计 源简并电感型共源放大器
    • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
    • ¥15 Vue3地图和异步函数使用
    • ¥15 C++ yoloV5改写遇到的问题