function sendMail($to,$from,$subject,$message,$file=null) { $headers = "From: $from\n"; $headers .= "Reply-To: $from\n"; //$headers .= "Content-type: text/html; charset=iso-8859-1\n"; if (!empty($file)) { if (!file_exists(realpath($file))) { die("Caminho de arquivo inválido."); exit; } $fopen = fopen(realpath($file),"r"); $fread = fread($fopen,filesize(realpath($file))); $encode = chunk_split(base64_encode($fread)); fclose($fopen); $headers .= "MIME-version: 1.0\n"; $headers .= "Content-type: multipart/mixed; "; $headers .= "boundary=\"Message-Boundary\"\n"; $headers .= "Content-transfer-encoding: 7BIT\n"; $headers .= "X-attachments: $file"; $boundary = "--Message-Boundary\n"; $boundary .= "Content-Type: text/html; charset=\"iso-8859-1\"\n"; $boundary .= "Content-Transfer-Encoding: 7BIT\n"; $boundary .= "Content-description: Mail message body\n\n"; $message = $boundary . $message; $message .= "\n\n--Message-Boundary\n"; $message .= "Content-type: $attach_type; name=\"".basename($file)."\"\n"; $message .= "Content-Transfer-Encoding: BASE64\n"; $message .= "Content-disposition: attachment; filename=\"".basename($file)."\"\n\n"; $message .= "$encode\n"; $message .= "--Message-Boundary--\n"; } if (!mail($to,$subject,$message,$headers)) return false; else return true; } ?>