function mail_attachment($filenames, $mailto, $from_mail, $from_name, $replyto, $subject, $bodyMessge) {
$uid = md5(uniqid(time()));
//$name = basename($file);
$eol = PHP_EOL;
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
// Basic headers
$header = "From: ".$from_name." <".$from_mail.">".$eol;
$header .= "Reply-To: ".$replyto.$eol;
$header .= "MIME-Version: 1.0\r\n";
$header .= "Content-Type: multipart/mixed; boundary=\"".$mime_boundary."\"";
// Put everything else in $message
$message = "This is a multi-part message in MIME format.".$eol.$eol.
"--{$mime_boundary}".$eol;
//$message = "--".$uid.$eol;
$message .= "Content-Type: text/html; charset=ISO-8859-1".$eol;
$message .= "Content-Transfer-Encoding: 8bit".$eol.$eol;
$message .= $bodyMessge.$eol;
//$message .= "--".$uid.$eol;
$message .= "--{$mime_boundary}".$eol;
foreach ($filenames as $filename) {
$file = UPLOAD_FILE_PATH.$filename;
$file_size = filesize($file);
$handle = fopen($file, "r");
$content = fread($handle, $file_size);
fclose($handle);
$content = chunk_split(base64_encode($content));
$message .= "Content-Type: application/octet-stream; name=\"".$filename."\"".$eol;
$message .= "Content-Transfer-Encoding: base64".$eol;
$message .= "Content-Disposition: attachment; filename=\"".$filename."\"".$eol;
$message .= $content.$eol;
//$message .= "--".$uid."--";
$message .= "--{$mime_boundary}".$eol;
}
if (mail($mailto, $subject, $message, $header)){
echo "success";
} else {
echo "error";
}
}