NancyJ
01-29-2007, 07:15 PM
I'm trying to send an attachment with an email and the attachement is recieved but its not openable. I've tried sending to yahoo and to my domain email and both have the same problem.
function sendAttached($to, $subject, $msgtext, $from, $file, $type)
{
$fp = fopen($file,"rb");
echo $file;
$fcontent = fread($fp ,filesize($file));
echo $fcontent;
fclose($fp);
$content = chunk_split(base64_encode($fcontent));
$sep = strtoupper(md5(uniqid(time())));
$name = basename($file);
$header = "From: $from\nReply-To: $from\r\n";
$header .= "MIME-Version: 1.0\r\n";
$header .= "Content-Type: multipart/mixed; boundary=$sep
\r\n";
$body .= "--$sep\r\n";
$body .= "Content-Type: text/plain\r\n";
$body .= "Content-Transfer-Encoding: 8bit\r\n\r\n";
$body .= "$msgtext\n";
$body .= "--$sep\n";
$body .= "Content-Type: $type; name=\"$name\"\r\n";
$body .= "Content-Transfer-Encoding: base64\r\n";
$body .= "Content-Disposition: attachment; filename=\"$name\"\r\n";
$body .= "$content\r\n";
$body .= "--$sep--";
echo $body;
if (mail($to, $subject, $body, $header)) {
return true;
} else {
return false;
}
}
sendAttached('me@mydomain.com', 'Test', 'Please find attached... something ', $from, $path.$filename, "text/plain", $filename);
function sendAttached($to, $subject, $msgtext, $from, $file, $type)
{
$fp = fopen($file,"rb");
echo $file;
$fcontent = fread($fp ,filesize($file));
echo $fcontent;
fclose($fp);
$content = chunk_split(base64_encode($fcontent));
$sep = strtoupper(md5(uniqid(time())));
$name = basename($file);
$header = "From: $from\nReply-To: $from\r\n";
$header .= "MIME-Version: 1.0\r\n";
$header .= "Content-Type: multipart/mixed; boundary=$sep
\r\n";
$body .= "--$sep\r\n";
$body .= "Content-Type: text/plain\r\n";
$body .= "Content-Transfer-Encoding: 8bit\r\n\r\n";
$body .= "$msgtext\n";
$body .= "--$sep\n";
$body .= "Content-Type: $type; name=\"$name\"\r\n";
$body .= "Content-Transfer-Encoding: base64\r\n";
$body .= "Content-Disposition: attachment; filename=\"$name\"\r\n";
$body .= "$content\r\n";
$body .= "--$sep--";
echo $body;
if (mail($to, $subject, $body, $header)) {
return true;
} else {
return false;
}
}
sendAttached('me@mydomain.com', 'Test', 'Please find attached... something ', $from, $path.$filename, "text/plain", $filename);