I have searched for a resolution to this and cannot find one. File gets uploaded and is to be attached to the email... mail client will not get it as an attachment but as garbage text in the body of the email. Anyone know why this is happening?
$file_dir = "/boatpicts/";
$AddCount = 0;
for ($i=1; $i < 13 ;$i++)
{
if(strlen($_FILES['myfiles_'.$i]['name']) > 0)
{
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
$filedesc = $_POST['picname_'.$i];
$fileatt_type = $_FILES['myfiles_'.$i]['type'];
$fileatt = $_FILES['myfiles_'.$i]['tmp_name'];
$fileatt_name = $_FILES['myfiles_'.$i]['name'];
$CreateFileName = $filedesc.'_'.$i.'.jpg';
$newfile = $file_dir.$boatid.'_'.$i.'.jpg';
$file = fopen($newfile,'rb');
$data = fread($file,filesize($newfile));
fclose($file);
if($AddCount == 0)
{
$AddCount = 1;
}
//Then you've got to specify the type of content you're dealing with. This is also put into the $headers string.
// In this case, it will be mixed between text, and some kind of attachment, hence the Content-Type bit.
// The boundary bit uses the boundary variable you made earlier:
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: multipart/mixed;\r\n";
$headers .= " boundary=\"".$mime_boundary."\"";
//Next, get on with piling the message into a $message string. You need quite a bit of header looking stuff in here. The first bit is what is
//displayed if the client receiveing the email doesn't support MIME, followed by the boundary string (preceded by "--", not sure why).
$msg .= "This is a multi-part message in MIME format.\r\n";
$msg .= "\r\n";
$msg .= "--".$mime_boundary."\r\n";
// Base64 encode the file data
$data = chunk_split(base64_encode($data));
//Finally, a plaintext attachment. In this case I already put your contents into $data.
$msg .= "Content-Type: {$fileatt_type};\r\n";
$msg .= " name=\"{$fileatt_name}\"\r\n";
$msg .= "Content-Transfer-Encoding: base64\r\n";
$msg .= "Content-Disposition: attachment;\r\n";
$msg .= " filename=\"{$CreateFileName}\"\r\n";
$msg .= "\r\n";
$msg .= $data;
$msg .= "\r\n";
$msg .= "--".$mime_boundary."\r\n";
}
}
//Next comes the actual content of the email, each part needs it's own mini header describing what it is.
$msg .= "Content-Type: text/plain; charset=\"iso-8859-1\"\r\n";
$msg .= "Content-Transfer-Encoding: 7bit\r\n";
$msg .= "\r\n";
$msg .= $AddMsg;
$msg .= "--".$mime_boundary."\r\n";
//test recipient
//$recipient = "$testemail";
$recipient = $brokeremail";
$subject = "Update: $lastName - $boatlength $boatyear $thisman ".$row['price'];
/* To send HTML mail, you can set the Content-type header. */
$mailheaders = "MIME-Version: 1.0\r\n";
$mailheaders .= "Content-type: text/plain; charset=iso-8859-1\r\n";
$mailheaders .= "From: $brokeremail \n";
$mailheaders .= "Reply-To: $brokeremail\n\n";
mail($recipient, $subject, $msg, $mailheaders);