Hi,
I am sending a file from the server as an email attachment. The file
is being attached no problem and sending the email, but I get an error
when I try to open it saying it is corrupt. Obviuosly, the file is
fine on the server, so the attachment code I am using must be
corrupting it, but I dont know what it is:
// send email with attachment
function emailAttachment($to, $subject, $message, $name, $email,
$file) {
$fp = fopen($file, "rb");
$fcontent = fread($fp, filesize($file));
fclose($fp);
$data = chunk_split(base64_encode($fcontent));
$mime_boundary = md5(uniqid(time()));
$file_name = basename($file);
$header = "From: " . $name . "<" . $email . ">\r\n";
$header .= "MIME-Version: 1.0\r\n";
$header .= "Content-Type: multipart/mixed;\r\n";
$header .= " boundary=\"" . $mime_boundary . "\"\r\n";
$content = "This is a multi-part message in MIME format.\r\n\r\n";
$content .= "--" . $mime_boundary . "\r\n";
$content .= "Content-Type: text/plain; charset=\"iso-8859-1\"\r\n";
$content .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
$content .= $message . "\r\n\r\n";
$content .= "--" . $mime_boundary . "\r\n";
$content .= "Content-Type: image/jpeg; name=\"" . $file_name .
"\"\r\n";
$content .= "Content-Transfer-Encoding: base64\r\n";
$content .= "Content-Disposition: attachment; filename=\"" .
$file_name . "\"\r\n\r\n";
$content .= $data . "\r\n";
$content .= "--" . $mime_boundary . "--";
if (mail($to, $subject, $content, $header)) {
return true;
} else {
return false;
}
}
I am receiving the email on a Mac, will this cause any errors?
I look forward to any help.
Paul