PHP form Mail & File Upload <?php if(isset($_POST['submit'])) problem?

Discussion in 'PHP' started by Charles1718, Jul 20, 2010.

  1. #1
    Hi, i'm new about PHP, and i try to insert the PHP Upload script in the php mail, but somehow i don't get it to work!

    this actually goes to header:
    <?php
      if(isset($_POST['submit'])) {
    	  
          $errors = array();
    
          $allowed_filetypes = array('.pdf','.zip','.rar'); 
          $max_filesize = 52428800; 
          $upload_path = './uploads_SS/'; 
     
       $filename = $_FILES['userfile']['name']; 
       $ext = substr($filename, strpos($filename,'.'), strlen($filename)-1); 
     
       if(!in_array($ext,$allowed_filetypes))
          $errors[] = "The file you attempted to upload is not allowed.";
     
       if(filesize($_FILES['userfile']['tmp_name']) > $max_filesize)
          $errors[] = "The file you attempted to upload is too large.";
     
       if(!is_writable($upload_path))
          $errors[] = "You cannot upload to the specified directory, please CHMOD it to 777.";
     
       if(move_uploaded_file($_FILES['userfile']['tmp_name'],$upload_path . $filename))
             echo 'Your file upload was successful, view the file <a href="' . $upload_path . $filename . '" title="Your File">here</a>'; 
          else
             echo 'There was an error during the file upload.  Please try again.'; 
     
          if($_POST['fname'] == "") {
             $errors[] = "The First Name field is empty";
          }
     
          if(count($errors) == 0) {
             $sendto = "someone@email.com";
             $title = "Application Form Submit";
             $fname = $_POST['fname'];
             $lname = $_POST['lname'];
             $Email = $_POST['Email'];
             $title_s = $_POST['title_s'];
    		 $dob = $_POST['dob'];
             $mob = $_POST['mob'];
    		 $yob = $_POST['yob'];
    		 $country = $_POST['country'];
    		 $saddress = $_POST['saddress'];
    		 $city = $_POST['city'];
    		 $zip = $_POST['zip'];
    		 $phone = $_POST['phone'];
    		 $fax = $_POST['fax'];
    		 $userfile = $_POST['userfile'];
    		 $adinfo = $_POST['adinfo'];
    $message = <<<DATA
    Name: $title_s $fname $lname
    Email: $Email
    Date of Birth: $dob, $mob, $yob
    Country Territory: $country
    Street Address: $saddress
    City/Town: $city
    Postal Code: $zip
    Phone Number: $phone
    Fax Number: $fax 
    Attachments: $userfile
    Additional information: $userfile
    DATA;
             if(mail($sendto, $title, $message)) {
                 $success = true;
             } else {
                $success = false;
             }
        } else {
           $success = false;
    
        }
      }
    
    ?>
    Code (markup):
    and this in <body>
    <?php
      if(isset($_POST['submit'])) {
         if($success == true && count($errors) == 0) {
            echo "&nbsp;&nbsp;&nbsp;&nbsp;<font color='#FF0000'>Your Submission has been Completed.</font>";
         }
         if(count($errors) == 0 && $success == false && isset($_POST['submit'])) {
            echo '&nbsp;&nbsp;&nbsp;&nbsp;<font color="#FF0000">There was a problem with our form. Please email us directly via <a href="mailto:someone@email.com">someone@email.com</a>, thank you.</font>';
         }
    
         if($success == false && count($errors) > 0 && isset($_POST['submit'])) {
            echo "<ul>";
            foreach($errors as $e) {
               echo "<font color='#FF0000'><li>$e</li></font>";
            }
            echo "</ul>";
         }
     }
    
     ?>
    Code (markup):
    I know the script above isn't clean!! ;)
    but I'm new on it :D
    thank you very much for your help!
     
    Charles1718, Jul 20, 2010 IP
  2. bencummins

    bencummins Peon

    Messages:
    55
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Have you got enctype="multipart/form-data" in the form tag on the submitting page?
     
    bencummins, Jul 21, 2010 IP