<?php
Error_Reporting(3);
$files_path="C:/";
$attachment_file="test.exe";
$subject = "test";
$toWhom = "andrey@mirny.ru";
$body = "my letter\n";
$bound = "----=_".uniqid("MailRobot")."=";
$header = "MIME-Version: 1.0\n".
"Content-Type: multipart/mixed; boundary=\"$bound\"\n".
"From: Andrey <andrey@mirny.ru>\n".
"Status: \n".
"X-Mailer: Mail Robot\n";
$content = "--".$bound."\n".
"Content-Type: text/plain; charset=\"koi8-r\"\n".
"Content-Transfer-Encoding: 8bit\n\n".
$body."\n";
$end = "\n"."--".$bound."--\n";
$attachment_header = "--".$bound."\n".
"Content-Type: application/octet-stream; name=\"$attachment_file\"\n".
"Content-Transfer-Encoding: base64\n".
"Content-Disposition: attachment; filename=\"$attachment_file\"\n\n";
$attachment_body = "";
$openfile = $files_path.$attachment_file;
$fp = fopen ("$openfile", "r");
if ($fp)
{
$binary = fread($fp, filesize($openfile));
$datalen = strlen($data =base64_encode($binary));
for ($posted = 0, $cutlen = 64; $posted <$datalen; $posted+=$cutlen)
{
if ($posted + $cutlen > $datalen) $cutlen = $datalen - $posted;
$attachment_body .=substr($data, $posted, $cutlen)."\n";
}
fclose ($fp);
}
$message= $content . $attachment_header . $attachment_body . $end;
$success = mail($toWhom, $subject, $message, $header);
if (success) {echo "OK";} else {echo "Something wrong";}
?>