<?php      
   function mail_attachment($file, $mailto, $from_name, $from_mail, $replyto, $subject, $message) {
      //$file = $path.$filename;
      $file_size = filesize($file);
      $handle = fopen($file, "r");
      $content = fread($handle, $file_size);
      fclose($handle);
      $content = chunk_split(base64_encode($content));
      $uid = md5(uniqid(time()));
      $name = basename($file);
      $header = "From: ".$from_name." <".$from_mail.">\r\n";
      //$header .= "Cc: ".$from_mail."\r\n";
      $header .= "Reply-To: ".$replyto."\r\n";
      $header .= "MIME-Version: 1.0\r\n";
      $header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n";
      $header .= "This is a multi-part message in MIME format.\r\n";
      $header .= "--".$uid."\r\n";
      $header .= "Content-type:text/plain; charset=iso-8859-1\r\n";
      $header .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
      $header .= $message."\r\n\r\n";
      $header .= "--".$uid."\r\n";
      $header .= "Content-Type: application/octet-stream; name=\"".$file."\"\r\n"; // use different content types here
      $header .= "Content-Transfer-Encoding: base64\r\n";
      $header .= "Content-Disposition: attachment; filename=\"".$file."\"\r\n\r\n";
      $header .= $content."\r\n\r\n";
      $header .= "--".$uid."--";
      if (mail($mailto, $subject, "", $header)) {
         echo "OK";
      } else {
         echo "ERROR";
      }
   }
   
   $projName=$_GET["proj"];
   //$to=$_GET["to"];
   $to=$_GET["from"];
   $from=$_GET["from"];
   $fromName=$_GET["exec"];
   $client=$_GET["client"];
   $dateStr=$_GET["d"];
   
   $nameParts=explode(" ",$projName);
   $fileName=implode("_",$nameParts).'_Progress_Report_'.$dateStr.'.xlsx';
   $subj=$projName.' progress report';
   $message='';
   $to.=','.$from;
   
   mail_attachment($fileName, $to, $fromName, $from, $client, $subj, $message);
   unlink($fileName);
?>