I have a e-mail file script but it is not working. I get my e-mail, it displays the comments, but when i click on the attachment link it downloads a .zip file (in the e-mail form i only allow .zips) of... nothing. 0.0kb.
Originally my script was meant for files, not compressed folders/files.
here is my script:
first a HTML form, with attachment as $att (i setup the form right - i know that) and in the <form> tag i put enctype="multipart/form-data" and a $from for the user's e-mail, and $comments for a textarea.
Here is the PHP:
$to = "myemail@myserver.com";
$re = "Submitted File";
$msg = $comments;
#open the file
$fp = fopen( $att_name, "r");
#read the file into variables
$file = fread( $fp, $att_size );
#encode the data for safer transit - here is where the problem is i think - i dont think this was ment for .zips:
#insert \r\n every 76-characters
$file = chunk_split(base64_encode($file));
#get a random 32-character hexadecimal number
$num = md5( time() );
#define the main headers
$hdr = "From:$from\r\n";
$hdr .= "MIME-Version: 1.0\r\n";
$hdr .= "Content-Type: multipart/mixed; ";
$hdr .= "boundary=$num\r\n";
$hdr .= "--$num\r\n";
#define the message body
$hdr .= "Content-Type: text/html\r\n";
$hdr .= "Content-Transfer-Encoding: 8bit\r\n\n";
$hdr .= "$msg\r\n";
$hdr .= "--$num\n";
#define the attachment section
$hdr .= "Content-Type: $att_type; ";
$hdr .= "name=\"$att_name\"\r\n\n";
// $hdr .= "Content-Transfer-Encoding: base64\r\n"; //tried with and without, think i need without
// $hdr .= "Content-Disposition: attachment; "; //tried with and without think i need without
// $hdr .= "filename=\"$att_name\"\r\n\n"; //tried with and without, think i need without
$hdr .= "$file\r\n";
$hdr .= "--$num--";
#send the e-mail now...
mail( $to, $re, "", $hdr);
#close the file
fclose($file);
echo("<h2>Thank You</h2>");
echo("Your file has been submitted. A reply will be sent to '$from' when the file has been uploaded.");