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 : </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