bruckerrlb Posted April 28, 2008 Share Posted April 28, 2008 Hello All, I am working on a script here. What happens is someone uploads their resume. This works fine, their resume gets uploaded. Now what I"m trying to do is, once it gets uploaded, it automatically gets emailed to someone. I am having problems with this, and I'm not sure if it's a flawed code, or where I have my code. //I have the code in the if statement that makes sure the file is uploaded if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) { echo "Your resume ". basename( $_FILES['uploadedfile']['name']). " has been uploaded! Thank you."; //start mail script $to = "me <my@email.com>"; $from = "Resume Submission <john.smith@domain.com>"; $subject = "Resume from US"; $fileatt = "basename( $_FILES['uploadedfile']['name'])"; $fileatttype = "application/msword"; $fileattname = "Resume"; $headers = "From: $from"; $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: {$fileatttype};\n" . " name=\"{$fileattname}\"\n" . "Content-Disposition: attachment;\n" . " filename=\"{$fileattname}\"\n" . "Content-Transfer-Encoding: base64\n\n" . $data . "\n\n" . "--{$mime_boundary}--\n"; if( mail( $to, $subject, $message, $headers ) ) { echo "<p>The email was sent.</p>"; } else { echo "<p>There was an error sending the mail.</p>"; } } //end send email } else { echo "Sorry, there was a problem uploading your resume."; } If anyone has any suggestions it would be much appreciated! Quote Link to comment Share on other sites More sharing options...
Rohan Shenoy Posted April 28, 2008 Share Posted April 28, 2008 To send as an attachment, you will need to use the content-disposition=attachment headers. Just google for sending email attachments with PHP Quote Link to comment Share on other sites More sharing options...
bruckerrlb Posted April 29, 2008 Author Share Posted April 29, 2008 Thanks for the tip, that's how I got my code in the first place, and I thought I was going in the right direction by using what you mentioned. 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.