After reading the file_upload section on PHP.net i got the following script working on the server..it sends an attachment from a form now but it's just of size 0 and always a txt file. I know it must be some little thing wrong then this will work, maybe you can eye it for me and let me know if you think i should change anything..
thanks, Mike -----form code------- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Form Test</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <form action="upload.php" method="post" enctype="multipart/form-data"> <strong>File to upload:</strong> <input type="hidden" name="MAX_FILE_SIZE" value="200000"> <input type="file" name="fileatt"> <INPUT TYPE=SUBMIT NAME="submit" VALUE="Upload File"> </form> </body> </html> --------end form code---------- ---------begin upload.php code---------- <?php $to = "[EMAIL PROTECTED]"; $from = "[EMAIL PROTECTED]"; $subject = "Attachment Test"; $message = "Dear mike,<br> Thank you for taking the time to subscribe for our free document.<br> Please find the document attached to this email."; if ($fileatt != "") { $uploaddir = '/home/sites/webserver.agraservices.net/web/mike/'; echo "it found the attachment"; move_uploaded_file($_FILES['fileatt']['tmp_name'], uploaddir . $_FILES['fileatt']['name']); } // Obtain file upload vars $fileatt = "/home/sites/webserver.agraservices.net/web/mike/"; // Location of file on server $fileatt_type = $_FILES['fileatt']['type'];// Type of file being sent $fileatt_name = $_FILES['fileatt']['name'];// Name of file $headers = "From: $from"; if (file_exists($fileatt)) { // Read the file to be attached ('rb' = read binary) $file = fopen($fileatt,'rb'); $data = fread($file,filesize($fileatt)); fclose($file); // Generate a boundary string $semi_rand = md5(time()); $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x"; // Add the headers for a file attachment $headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\""; // Add a multipart boundary above the plain message $message = "This is a multi-part message in MIME format.\n\n" . "--{$mime_boundary}\n" . "Content-Type: text/html; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $message . "\n\n"; // Base64 encode the file data $data = chunk_split(base64_encode($data)); // Add file attachment to the message $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"; } mail($to, $subject, $message, $headers); echo "Thanks for sending mail"; ?> ---------end upload.php code------------ thanks again for your help, Mike ----- Original Message ----- From: "Jason Wong" <[EMAIL PROTECTED]> Newsgroups: php.general To: <[EMAIL PROTECTED]> Sent: Friday, April 04, 2003 1:36 AM Subject: Re: [PHP] PHP Email Attachment problem > On Friday 04 April 2003 06:10, Michael Arena wrote: > > Made some progress today. Found an attachment script in the archives. I > > was able to send an email attachment if it was already on the server. now i > > just need the file to come from a form instead of already being on the > > server but that's not working yet. > > It sounds to me you've definitely got an upload problem. > > Try the upload example in the manual and let us know if you can get that > working. > > -- > Jason Wong -> Gremlins Associates -> www.gremlins.biz > Open Source Software Systems Integrators > * Web Design & Hosting * Internet & Intranet Applications Development * > ------------------------------------------ > Search the list archives before you post > http://marc.theaimsgroup.com/?l=php-general > ------------------------------------------ > /* > Rainy days and automatic weapons always get me down. > */ > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php