|
<?php
/**
* send multipart emails (email with attachemnt file)
* @parameter from from email address
* @parameter to send to email
* @parameter subject email subject
* @parameter message email message body
* @fileName attachment filr name
* @return
*/
function send_multipart_email ($from , $to, $subject, $message, $fileName,$add_headers = ""){
$file_data = @file_get_contents($fileName);
if (($file_data == "") || ($file_data == FALSE)) { return FALSE;}
$file_data = chunk_split(base64_encode($file_data));
$separator = crypt(time());
$headers = "MIME-Version: 1.0\n";
$headers .= "From: $from\n";
$headers .= "To: $to\n";
$headers .= "Content-Type: multipart/mixed;\n" . " boundary=$separator\n";
$headers .= $add_headers;
// text message content part
$body .= "--$separator";
$body .= "\nContent-Type:text/plain; charset=\"iso-8859-1\"\n";
$body .= "Content-Transfer-Encoding: 7bit\n\n";
$body .= $message . "\n";
// file attachment content part
$body .= "--$separator";
$body .= "\nContent-Type: application/octet-stream;\n name=\"{$fileName}\"\n";
$body .= "Content-Transfer-Encoding: base64\n";
$body .= $file_data . "\n";
return @mail($to, $subject, $body, $headers);
}
?>
|