Jump to content

Uploaded followed by emailed as an attachment


bruckerrlb

Recommended Posts

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 <[email protected]>"; 

        $from = "Resume Submission <[email protected]>"; 

        $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!

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.