I want to add send mail in my website. user can attach some files with multiple types in email. So i wrote this code to send mail. the problem is file type is not correct. for example i attached a jpg file to send to email. but the attachment received in mail box is empty or is wrong type. this is my php mail file:
<?php
//Deal with the email
$sender = $_POST['email'];
$to = 'info@matinjewellery.com';
$subject = $_POST['name'];
$message = strip_tags($_POST['message']);
$attachment = chunk_split(base64_encode(file_get_contents($_FILES['file']['tmp_name'])));
$filename = $_FILES['file']['name'];
$boundary =md5(date('r', time()));
$headers = "From: ".$sender."\r\nReply-To: ".$to;
$headers .= "\r\nMIME-Version: 1.0\r\nContent-Type: multipart/mixed; boundary=\"_1_$boundary\"";
$message="This is a multi-part message in MIME format.
--_1_$boundary
Content-Type: multipart/alternative; boundary=\"_2_$boundary\"
--_2_$boundary
Content-Type: text/plain; charset=\"utf-8\"
Content-Transfer-Encoding: 7bit
$message
--_2_$boundary--
--_1_$boundary
Content-Type: application/zip; name=\"$filename\"
Content-Transfer-Encoding: base64
Content-Disposition: attachment
$attachment
--_1_$boundary--";
mail($to, $subject, $message, $headers);
?>