doupang9080 2015-07-24 09:44
浏览 39

带附件的PHP邮件

Hello i'm trying to send email from form^) Here is my code

<?php
$to = "some email";
$from = "site";
$subject = "Resume";
$boundary = "---";

if (isset($_POST['ok'])){
    $filename = $_POST['fileField'];
    $resumeLink = $_POST['linkField'];
    $message = "Attachment: " .$resumeLink;
    /* Headers*/
    $headers = "From: $from
Reply-To: $from
";
    $headers .= "Content-Type: multipart/mixed; boundary=\"$boundary\"";
    $body = "--$boundary
";  
    /* Add message */
    $body .= "Content-type: text/html; charset='utf-8'
";
    $body .= "Content-Transfer-Encoding: quoted-printablenn";
    $body .= "Content-Disposition: attachment; filename==?utf-8?B?".base64_encode($filename)."?=

";
    $body .= $message."
";
    $body .= "--$boundary
";
    $file = fopen($filename, "r"); //open file
    $text = fread($file, filesize($filename)); //read file
    fclose($file); //close file
    /* Add message type */
    $body .= "Content-Type: application/octet-stream; name==?utf-8?B?".base64_encode($filename)."?=
"; 
    $body .= "Content-Transfer-Encoding: base64
";
    $body .= "Content-Disposition: attachment; filename==?utf-8?B?".base64_encode($filename)."?=

";
    $body .= chunk_split(base64_encode($text))."
";
    $body .= "--".$boundary ."--
";
    if(mail($to, $subject, $body, $headers)){header("Location: /");}

}
?>

Attachment will send, but it size will be 1 byte without any content inside. Whats wrong?

  • 写回答

1条回答 默认 最新

  • dsfdfdfd6576578 2015-07-24 10:50
    关注

    It's hard to tell exactly, but you've added header fields into mail body, you should add them in headers

    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题