mem0ri Posted December 21, 2006 Share Posted December 21, 2006 I've just finished updating the mass e-mailer for a members-only site with the ability to add attachments...and have followed a couple of tutorials to make sure I got it right......but apparently I've missed something...because the files that show up in my gmail box show as unknown files with an unkown file type and have a set "size" of 1k. (The subject/message/sender/etc are all fine) I'll post my code below...please help:Oh...another note...if I throw a die() in before the e-mail is sent out...the file IS recorded correctly in the $fileatt variables.[code=php:0] $from = $user['email']; $subject = $_POST['subject']; $body = stripchars($_POST['body']); $fileatt = $_FILES['file_attach']['tmp_name']; $fileatt_type = $_FILES['file_attach']['type']; $fileatt_name = $_FILES['file_attach']['name']; $headers = 'From:'.$from." \r\n".'Reply-To:'.$from. " \r\n"; $headers .= 'Date:'.date("r")."\n"; $headers .= 'Subject: '.$subject."\n"; if (is_uploaded_file($fileatt)) { $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" . " boundary=\"{$mime_boundary}\""; $message = "This is a multi-part message in MIME format.\n\n"."--{$mime_boundary}\n"."Content-Type: text/plain; charset=\"iso-8859-1\"\n"."Content-Transfer-Encoding: 7bit\n\n".$message."\n\n"; $data = chunk_split(base64_encode($data)); $message .= "--{$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".$data."\n\n"."--{$mime_boundary}--\n"; } else { $headers .= 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-Type:text/html; charset=\"iso-8859-1\" \r\n"'; } $sql = "SELECT id, email FROM user"; $query = mysql_query($sql); while($row = mysql_fetch_array($query)) { $id = $row['id']; if($_POST[$id] == 1) $email_list[] = $row['email']; } if(isset($subject) && isset($body) && $subject != "" && $body != "") { for($x = 0; $x < count($email_list); $x++) { $headers .= "Message-ID: <".($x + 100). "@".$_SERVER['SERVER_NAME'].">". "\r\n"; $headers .= "To: ".$row['email']." \r\n"; mail($email_list[$x], $subject, $body, $headers); if($x == 0 && count($email_list) > 1) echo("<span class=\"notification\">E-Mail sent to: ".$email_list[$x].", "); else if($x == 0 && count($email_list) == 1) echo("<span class=\"notification\">E-Mail sent to: ".$email_list[$x]."</span>"); else if($x == (count($email_list) - 1) && $x != 0) echo($email_list[$x]."</span>"); else echo($email_list[$x].", "); } }[/code] Link to comment https://forums.phpfreaks.com/topic/31432-solved-e-mailed-attachments-showing-as-quotunknownquot-type/ Share on other sites More sharing options...
mem0ri Posted December 21, 2006 Author Share Posted December 21, 2006 Any help available on this topic? I'm very stuck...and it's a rather important function...most of the e-mails we send out have attachments. Link to comment https://forums.phpfreaks.com/topic/31432-solved-e-mailed-attachments-showing-as-quotunknownquot-type/#findComment-146024 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.