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

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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