Jump to content

[SOLVED] E-mailed Attachments showing as "unknown" type...


mem0ri

Recommended Posts

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.