Hi,
I have a form that allows the uploading of an mp3 file to a directory on the server. Which works fine.
Then all the form contents are emailed, including the attached mp3.
Issue is the mp3 is opening in the body of the email (not attached) and is in text format.
I'm using the below code:
function mail_attachment ($from , $to, $subject, $message, $attachment,$direct){
$fileatt_type = "audio/mpeg"; // File Type (also tried "application/octet-stream")
$files=$attachment;
$email_from = $from; // from email address
$email_subject = $subject; // Subject of the email
$email_txt = $message; // Email Message
$email_to = $to; // to email address
$headers = "From: ".$email_from;
$msg_txt="\n\n";
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
$headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"";
$email_txt .= $msg_txt;
$email_message .= "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type:text/html; charset=\"utf-8\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$email_txt . "\n\n";
$email_message .= "--{$mime_boundary}\n";
for($x=0;$x<count($files);$x++)
{
#
$file = fopen($direct."/".$files[$x],"rb");
#
$data = fread($file,filesize($direct."/".$files[$x]));
#
fclose($file);
#
$data = chunk_split(base64_encode($data));
#
$email_message .= "--{$mime_boundary}\n";
$email_message .= "Content-Type: {$fileatt_type};\n" .
" name=\"{$files[$x]}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n" ;
#
}
$email_message .= "--{$mime_boundary}--\n";
$s=mail($email_to, $email_subject, $email_message, $headers);
return $s;
}
Would greatly appreciate any help.
Cheers