i have created mail() function with attachment in php.the image or pdf are attached and send to like xyz@gmail.com ,the file attachment is received ,but i didn't open the file.please check my code and tell me...
html code:
<html>
<body>
<form action="send.php" enctype="multipart/form-data" method="POST">
<label>Email: </label>
<input type="text" name="to" placeholder="To" >
<br> <br>
<label>Message:</label>
<textarea name="msg" placeholder="Message"></textarea>
<br> <br>
<label>Upload:</label>
<input type="file" name="image" >
<br> <br>
<input type="submit" value="Submit" name="submit" >
</form>
</body>
</html>
php code:
$file_name=$_FILES['image']['name'];
$file_size=$_FILES['image']['size'];
$file_tmp=$_FILES['image']['tmp_name'];
$file_type = $_FILES['image']['type'];
$attachments='';
if(!empty($_FILES['image']['tmp_name']))
{
$path=$_FILES['image']['name'];
move_uploaded_file($file_tmp,$path);
$attachments=$path;
}
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "Content-Disposition: attachment; filename = \"" .$attachments. "\"\n\n";
$to=$_POST['to'];
$msg=$_POST['msg'];
$file=$_POST["image"];
$body="this msg auto generated";
if(mail ($to,$msg,$body,$headers,$file))
{
echo 'Email sent successfully!';
}
else
{
die('Failure: Email was not sent!');
}