This is php code for sending just attachment
$attachment = chunk_split(base64_encode(file_get_contents($_FILES['file_to_upload']['tmp_name'])));
$filename = $_FILES['file_to_upload']['name'];
$boundary =md5(date('r', time()));
$headers = "From: $from \r\nReply-To: $from ";
$headers .= "\r\nMIME-Version: 1.0\r\nContent-Type: multipart/mixed; boundary=\"_1_$boundary\"";
$body.="This is a multi-part message in MIME format.
--_1_$boundary
Content-Type: multipart/alternative; boundary=\"_2_$boundary\"
--_2_$boundary
Content-Type: text/html; charset=\"UTF-8\"
Content-Transfer-Encoding: 7bit
--_2_$boundary--
--_1_$boundary
Content-Type: application/octet-stream; name=\"$filename\"
Content-Transfer-Encoding: base64
Content-Disposition: attachment
$attachment
--_1_$boundary--";
It working when attachment is send but when user not wont to select any attachment it send some Part2.bin file in email. How to overcome this? Not send anything when file isn't selected