misslilbit02 Posted July 13, 2007 Share Posted July 13, 2007 Hi, I'm trying to send an email from a form with an attachment but now I'm stuck because I'm getting this error: PHP Warning: filesize() [function.filesize]: stat failed for C:\WINNT\TEMP\phpF53.tmp in D:\www\edu\Keiser Writes\submittal.php on line 54 PHP Warning: fread() [function.fread]: Length parameter must be greater than 0 in D:\www\edu\Keiser Writes\submittal.php on line 54 This is my code: // Obtain file upload vars $fileatt = $_FILES['upfile']['tmp_name']; $fileatt_type = $_FILES['upfile']['type']; $fileatt_name = $_FILES['upfile']['name']; $headers = "From: $email"; if (is_uploaded_file($fileatt)) { // Read the file to be attached ('rb' = read binary) $file = fopen($fileatt,'rb'); //$data = file_get_contents($fileatt); $data = fread($file, filesize($fileatt)); fclose($file); Can someone help me with this matter? I don't know where to start with this. This code does work. I have a resellers hosting account I tested it on they are on the Lunix platform but at work I'm on the Windows platform and this does not work. Quote Link to comment Share on other sites More sharing options...
MadTechie Posted July 13, 2007 Share Posted July 13, 2007 looks like the tmp file isn't being created! access right ? Quote Link to comment Share on other sites More sharing options...
misslilbit02 Posted July 13, 2007 Author Share Posted July 13, 2007 I'm not sure I know what you mean by access? Are you speaking of my access to the server or access the database? Quote Link to comment Share on other sites More sharing options...
misslilbit02 Posted July 13, 2007 Author Share Posted July 13, 2007 I just put the location of the temp directory in the php.ini file so that got rid of the error but now it's not emailing a thing. SUCKS! Thanks for your help though. Quote Link to comment Share on other sites More sharing options...
misslilbit02 Posted July 13, 2007 Author Share Posted July 13, 2007 I no longer have the error. The temp directory wasn't defined in the php.ini file. The issue now is the email isn't sending. I did checks to see if the file uploaded and things of that nature and all seem well. It looks like things are getting stucks are the sending of the mail part. // 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/plain; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $message . "\n\n"; echo $message; // Base64 encode the file data $data = chunk_split(base64_encode($data)); //echo $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"; } // Send the message $ok = @mail($to, $subject, $message, $headers); if ($ok) { echo "<p>Mail sent! Yay PHP!</p>"; } else { echo "<p>Mail could not be sent. Sorry!</p>"; ?> That is how the mailing portion looks courtesy of sitepoint but everytime it I submit the form it says mail could not be sent. Quote Link to comment Share on other sites More sharing options...
MadTechie Posted July 13, 2007 Share Posted July 13, 2007 SMTP etc setup correctly in the php.ini Quote Link to comment Share on other sites More sharing options...
misslilbit02 Posted July 13, 2007 Author Share Posted July 13, 2007 Yeah that's fine. I can send simple emails but when I have to deal with the mime type things get a lil weird. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.