Hi Friends,

I am trying to send a file via email and upload on a server as well, but unfortunately the file uploaded successfully while attachment sent to email there when i preview or download so it contained error, below following code is:


if(isset($_POST["Submit"])) {    

  $to = "abc@gmail.com";

  $subject= "New Enquiry ";         

$message .= "Attached File Name: " . $fileName."\n";


$fileName = $_FILES["attached_file"]["name"]; // The file name
$fileTmpLoc = $_FILES["attached_file"]["tmp_name"]; // File in the PHP tmp folder
$fileType = $_FILES["attached_file"]["type"]; // The type of file it is
$fileSize = $_FILES["attached_file"]["size"]; // File size in bytes
$fileErrorMsg = $_FILES["attached_file"]["error"]; // 0 for false... and 1 for true

move_uploaded_file($fileTmpLoc, "upload/$fileName");

      $headers.="From: ".$email."\r\n" . "MIME-Version: 1.0\r\n" . "Content-Type: multipart/mixed;\r\n" . " boundary=\"{$mime_boundary}\"";

     $message = "This is a multi-part message in MIME format.\n\n" . "--{$mime_boundary}\n" .
         "Content-Type: text/plain; charset=\"iso-8859-1\"\n" .
         "Content-Transfer-Encoding: 7bit\n\n" .
         $message . "\n\n";

    $message .= "--{$mime_boundary}\n";

 $message .= "Content-Type: {\"application/octet-stream\"};\n" . " name=\"$fileName\"\n" . 
    "Content-Disposition: attachment;\n" . " filename=\"$fileName\"\n" . 
    "Content-Transfer-Encoding: base64\n\n" . $data . "\n\n";
    $message .= "--{$mime_boundary}\n";

mail($to, $subject, $message, $headers);


<form action="" method="post" enctype="multipart/form-data" name="claim_form" id="claim_form" onsubmit="return validateForm()">
      <table width="700" border="0" align="center" cellpadding="0" cellspacing="0" bordercolor="#F0F0F0" id="form_table">

          <td height="50" align="right" bordercolor="#F0F0F0">Attach a File :&nbsp;&nbsp;</td>
          <td height="50" align="left" bordercolor="#F0F0F0">
          <input name="attached_file" type="file" size="20" />
          <td height="50" colspan="2" align="right" valign="bottom" bordercolor="#F0F0F0">

          <input name="Submit" type="submit" id="Submit" value="Send" /></td>
      <br />

Kind Regards

4 Years
Discussion Span
Last Post by urtrivedi

Dear Robert,
Thanks for your reply,

i have download library but right now its very complex for, i know i m not good programmer and now in my mind alots of Qs comes up.
1. how i will configure this library cause it contains the large number of files
2. if i add some more text fields in my form so what will be the next step to email that form in a proper way
3. and how i will upload sent one file on server
......... Qs and Qs, now i think i am in a trouble

Looking for your kind assistance.

Edited by ismael ahm@d: comments added


Hi Everyone,

Dear Robert, you have gave me the link for sending email but my Qs regarding to get the enquires from end users just like a contact form where i'll receive on my mail (abc@gmail.com), for this how i'll get the attached file.

Can some one resolve the above problem of uploading and email of file...


Edited by ismael ahm@d: added

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.