Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8413595
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T00:56:55+00:00 2026-06-10T00:56:55+00:00

I (finally) completed a php script where a user can upload a file and

  • 0

I (finally) completed a php script where a user can upload a file and send to me, but I cannot seem to use his/her already stored email account for the FROM field. The email is never sent to me…

Here’s what I have. I stored the user’s email as a Session when they login/register.

session_save_path('/home/users/web/...'); 
session_start();
$_SESSION['users'] = $email;

Then, I have a user page, which recalls the Session and displays the info as “logged in as {$_SESSION[‘users’]}”

Then I created a form for the user to upload a file and send me an email:

<form method="POST" action="testmail.php" enctype="multipart/form-data" class="form-vertical">
<input name="email" type="hidden" value="'.$_SESSION['users'].'" />

<span class="label label-info">Document Type</span><br>
<input type="text" name="project" class="input-medium"style="width: 350px; height: 30px;" /><br><br>

<span class="label label-info">Upload the Document</span><br><br>
<input type="file" name="attachment[]"><br><br>

<span class="label label-info">Brief Description of Document and Concern</span><br>
<textarea name="description" style="width: 550px; height: 200px;">...</textarea>

<input type="submit" class="btn btn-large btn-success">
</form>

However, this form only works when I omit the value of “‘.$_SESSION[‘users’].'” (value=”TEST”, for example).

Here’s the email php script:

 <?php
    if( $_POST || $_FILES )
    {
            // email fields: to, from, subject, and so on
            // Here 
            $from = $_POST['email'];
            $to = "support@lawcontractor.com";
            $subject = $_POST['project'];
            $message = "This is the message body and to it I will append the attachments.";
            $headers = "From: $from";

            // boundary
            $semi_rand = md5(time());
            $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";

            // headers for attachment
            $headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\"";

            // multipart boundary
            $message = "--{$mime_boundary}\n" . "Content-Type: text/plain; charset=\"iso-8859-1\"\n"."Content-Transfer-Encoding: 7bit\n\n" . $message . "\n\n";
            fixFilesArray($_FILES['attachment']);
            foreach ($_FILES['attachment'] as $position => $file) 
            {
                    // should output array with indices name, type, tmp_name, error, size
                    $message .= "--{$mime_boundary}\n";
                    $fp     = @fopen($file['tmp_name'],"rb");
                    $data   = @fread($fp,filesize($file['tmp_name']));
                    @fclose($fp);
                $data = chunk_split(base64_encode($data));
                $message .= "Content-Type: application/octet-stream; name=\"".$file['name']."\"\n"."Content-Description: ".$file['name']."\n" ."Content-Disposition: attachment;\n" . " filename=\"".$file['name']."\";size=".$file['size'].";\n"."Content-Transfer-Encoding: base64\n\n" . $data . "\n\n";
            }
            $message .= "--{$mime_boundary}--";
            $returnpath = "-f" . $from;
            $ok = @mail($to, $subject, $message, $headers, $returnpath);
            if($ok){ return 1; } else { return 0; }
    }
    //This function will correct file array from $_FILES[[file][position]] to $_FILES[[position][file]] .. Very important

    function fixFilesArray(&$files)
    {
            $names = array( 'name' => 1, 'type' => 1, 'tmp_name' => 1, 'error' => 1, 'size' => 1);

            foreach ($files as $key => $part) {
                    // only deal with valid keys and multiple files
                    $key = (string) $key;
                    if (isset($names[$key]) && is_array($part)) {
                            foreach ($part as $position => $value) {
                                    $files[$position][$key] = $value;
                            }
                            // remove old key reference
                            unset($files[$key]);
                    }
            }
    }
    ?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T00:56:55+00:00Added an answer on June 10, 2026 at 12:56 am

    Try this:

    <input name="email" type="hidden" value="<?php echo $_SESSION['users'] ?>" />
    

    In your code you are missing the <?php ?> tags while getting the value of $_SESSION['users']. HTML does not understand this so you need to put it within the <?php ?> tags and echo the value.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Finally deployed my ruby on rails 3.2 app but when trying to open it
Finally figured it out thanks to One Mad Monkey, but forgot quotes on my
I finally figured out how to implement pg_search's multisearch feature. But I'm having trouble
How can i get a series of reproducible pseudorandom numbers in PHP? In older
Folks, I am trying to use Team City. I completed the six steps out
I have a code that post to a php script that reads all files
I'm searching for a PHP syntax highlighting engine that can be customized (i.e. I
Finally completed the frontend of my website, I am now looking at coding the
I worked like two hours on this script, and finally I see almost the
Now I have finally managed to create a fullscreen window via http://cocoadevcentral.com/articles/000028.php Brilliant tutorial.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.