附带附件的PHP邮件,附件已发送,但没有正文

时间:2017-12-01 07:41:45

标签: php email attachment

当我发送电子邮件时,电子邮件仅附带附件,并且不会显示消息部分。预览说没有文字正文。什么地方出了错?代码如下:

  <?php
  include 'header.php';
  if(isset($_POST['bookingsubmit']))
  {
    //print_r($_POST); 
    $to = "dungeonr977@gmail.com"; 
    $from = $_POST['email']; 
    $first_name = $_POST['fName'];
    $last_name = $_POST['lName'];
    $mobile= $_POST['mobile'];
    $airline= $_POST['airline'];
    $subject = "Flight Change Request";

    $file_name = $_FILES['file']['name'];  
    $temp_name = $_FILES['file']['tmp_name'];  
    $file_type = $_FILES['file']['type']; 

    $base = basename($file_name);
    $extension = substr($base, strrpos($base, ".")-1);
    $file = $temp_name;
    $content = chunk_split(base64_encode(file_get_contents($file)));
    $uid = md5(uniqid(time()));  //unique identifier

    $message = "Mr/Mrs/Ms ".$first_name." ".$last_name." wrote the following:"."\r\n".$_POST['message'];  

    $headers = 'MIME-Version: 1.0';
    $headers .= "From:" . $from;
    $headers .= "X-Mailer: PHP/".phpversion()."\r\n";        
    //$headers .= "--".$uid."\r\n";        
    $headers .= "Content-Type: ".$file_type."; name=\"".$file_name."\"\r\n";
    $headers .= "Content-Transfer-Encoding: base64\r\n";
    $headers .= "Content-Disposition: attachment; filename=\"".$file_name."\"\r\n";
    $headers .= $content; 
    //$headers2 = "From:" . $to;

    mail($to,$subject,$message,$headers);
   }
   ?>

0 个答案:

没有答案