I'm using the following code to send emails with multiple attachments, the code runs OK and the mail with attachments appears at the other end.
BUT, all the files have been truncated to 814 bytes????
Anyone have any ideas why?
Thanks,
Chris
<?
$ABORT = FALSE;
$to = "chrisg@cordell.com.au";
$from = "chrisg@cordell.com.au";
$subject = "test";
$boundary = "XXX-" . time() . "-XXX";
$message = "--$boundary\r\n";
$message .= "Content-Type: text/plain;charset=\"iso-8859-1\"\r\n\r\n\r\n";
$message .= "test message.123.\r\n";
//check that the attachment files exist and if so then encode
$attachments[1] = "c:\file1";
$attachments[2] = "c:\file2";
$attachments[3] = "c:\file3";
foreach ($attachments as $key => $full_path) {
if ($full_path !='') {
if (file_exists($full_path)){
//try to open
if ($fp = fopen($full_path,"rb")) {
$filename = array_pop(explode(chr(92),$full_path));
$file_extension = substr($filename,strpos($filename,".")+1);
//check to see if the file extension is in the list else sets the mime-type to 'text/plain'
in_array($file_extension,array_keys($mime_list))?$mime_type = $mime_list[$file_extension]:$mime_type = "text/plain";
//encode
$contents = fread($fp,filesize($full_path));
$encoded = base64_encode($contents);
fclose($fp);
$message .= "--$boundary\r\n";
$message .= "Content-Type: $mime_type;name=\"$filename\"\r\n";
$message .= "Content-Transfer-Encoding: base64\r\n";
$message .= "Content-Disposition: attachment\r\n\r\n\r\n";
$message .= "$encoded\r\n";
}
else {
echo "Cannot open file$key: $filename";
$ABORT = TRUE;
}
}
else {
echo "File$key does not exist: $filename";
$ABORT = TRUE;
}
}
}
$message .= "--$boundary--\r\n";
$headers = "From: <$from>\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: multipart/mixed;boundary=\"$boundary\"\r\n";
if (!$ABORT) die;
mail($to,$subject,$message,$headers);
//echo to page
echo "$to<br>";
echo "$subject<br>";
echo str_replace("\n","<br>",$message);
echo $headers;?>
<b>EMails Sent!</b>