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:

<?php

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

  $to = "abc@gmail.com";

  $subject= "New Enquiry ";         

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

$mime_boundary="==Multipart_Boundary_x".md5(mt_rand())."x";

$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);

}

      ?>
<html>
<body>
<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">

        <tr>
          <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>
        </tr>
        <tr>
          <td height="50" colspan="2" align="right" valign="bottom" bordercolor="#F0F0F0">

          <input name="Submit" type="submit" id="Submit" value="Send" /></td>
        </tr>
      </table>
      <br />
    </form>
</body>
</html>

--
Kind Regards

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.

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...

Thanks

I think following library is simple to manage mails with attachment
After uploading file to your server, you can add it path to attachment in email.

here is the link
http://phpmailer.worxware.com/