title: send mail via php to microsoft exchange
body: <p>i have function to send mail with attachment to microsoft exchange server. My problem is that when I wanna to add attachment the whole message part is adding my text to attachment source. When I save attachment to body section of mail, my attachment source is wrote down in email body  instead of creating an attachment. Belowe is my source.</p>
  
  <pre><code>$eol = "\r\n";
  
  $boundary = md5(time());
  
      $mail = "explame@explame.com";  
  
  $headers  = "From: no-replay@explame.com".$eol;
  $headers .= "MIME-Version: 1.0".$eol; //utworzenie headera wiadomosci
  $headers .= "Content-type: multipart/alternative; charset=utf-8".$eol;
  $headers .= "Message-ID:&lt; TheSystem@".$_SERVER['SERVER_NAME']."&gt;".$eol; 
  $headers .= "X-Mailer: PHP v".phpversion().$eol;
  $headers .= 'MIME-Version: 1.0'.$eol;
  $headers .= "Content-Type: multipart/related; boundary=\"".$boundary."\"".$eol; 
  $headers .= "--$boundary".$eol;
  $headers .= "Content-Type: text/plain; charset=utf-8".$eol;
  $headers .= "Content-Transfer-Encoding: 8bit".$eol;
  $headers .= "--$boundary--".$eol.$eol;
  
  if ($file != ''){
      $handle = fopen($file['tmp_name'], 'rb');
      $f_content = fread($handle, $file['size']);
      $attachment =  chunk_split(base64_encode($f_content));
      fclose($handle);
  
      $content .= "--$boundary".$eol;
      $content .= "Content-type: ".$file['type'].'; '.'name="'.$file['name'].'"'.$eol;
      $content .= 'Content-Disposition: attachment; filename="'.$file['name'].'"'.$eol.$eol;
      $content .= "Content-Transfer-Encoding: base64".$eol;
      $content .= $attachment.$eol.$eol;
      $content .= "--$boundary--".$eol.$eol;
  
      }
  mail($mail, 'title', $content, $headers)
  </code></pre>
  
  <p>i think I tried everything but nothing works for me. :(</p>