function send_mail($emailaddress, $fromaddress, $emailsubject, $body, $attachments=false,$fromfax=false) { $mime_boundary=md5(time()); $now = date("YMD"); $headers = ""; // Common Headers $headers .= 'From: Support<'.$fromaddress.'>'."\n"; // these two to set reply address $headers .= 'Reply-To: Support<'.$fromaddress.'>'."\n"; $headers .= 'Return-Path: Support<'.$fromaddress.'>'."\n"; // These two to help avoid spam-filters $headers .= "Message-ID: <".$now." support@pbx1.mhipriv.com>\n"; $headers .= "X-Mailer: PHP v5.1.1\n"; // Boundry for marking the split & Multitype Headers $headers .= 'MIME-Version: 1.0'."\n"; $headers .= "Content-Type: multipart/related; boundary=\"".$mime_boundary."\"\n"; $msg = ""; if ($attachments !== false) { //for($i=0; $i < count($attachments); $i++) { if (is_file($attachments["file"])) { //File for Attachment $file_name = substr($attachments["file"], (strrpos($attachments["file"], "/")+1)); $handle=fopen($attachments["file"], 'rb'); $f_contents=fread($handle, filesize($attachments["file"])); //Encode The Data For Transition using base64_encode(); $f_contents=chunk_split(base64_encode($f_contents)); fclose($handle); // Attachment $msg .= "--".$mime_boundary."\n"; $msg .= "Content-Type: ".$attachments["content_type"]."; name=\"".$file_name."\"\n"; $msg .= "Content-Transfer-Encoding: base64\n"; // !! This line needs TWO end of lines !! IMPORTANT !! $msg .= "Content-Disposition: attachment; filename=\"".$file_name."\"\n\n"; $msg .= $f_contents."\n\n"; } //} } // Setup for text OR html $msg .= "Content-Type: multipart/alternative\n"; // Text Version $msg .= "--".$mime_boundary."\n"; $msg .= "Content-Type: text/plain; charset=iso-8859-1\n"; $msg .= "Content-Transfer-Encoding: 8bit\n\n"; $msg .= $body."\n\n"; // finish with two eol's for better security. see Injection. $msg .= "--".$mime_boundary."--\n\n"; // SEND THE EMAIL // the INI lines are to force the From Address to be used ! ini_set('sendmail_from',$fromaddress); mail($emailaddress, $emailsubject, $msg, $headers); ini_restore('sendmail_from');}