|
Sending Attachments through PHP Script
I am trying to send an email using PHP script but it seems that the attachments wants to convert to text and embed into the email.
this is the code, not sure why its embedding.
$fileatt = $_FILES['attach']['tmp_name'];
$fileatt_name = basename($_FILES['attach']['name']);
$fileatt_type = substr($fileatt_name, strrpos($fileatt_name, '.') + 1);
$file = fopen($fileatt,'rb');
$data = fread($file,filesize($fileatt));
fclose($file);
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
$headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
$body .= "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type:text/html; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$body .= "\n\n";
$data = chunk_split(base64_encode($data));
$body .= "-{$mime_boundary}\n" .
"Content-Type: {$fileatt_type};\n" .
" name=\"{$fileatt_name}\"\n" .
"Content-Disposition: attachment;\n" .
" filename=\"{$fileatt_name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$body .= "\n\n" .
"-{$mime_boundary}-\n";
mail($email_to, $subject, $body, $headers);
|