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

Jones H.W

New member
Hi, i'm new about this 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:

Code:
<?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 = "[email protected]";
         $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;

    }
  }

?>

And this in html tag "<body>"

Code:
<?php
  if(isset($_POST['submit'])) {
     if($success == true && count($errors) == 0) {
        echo "****<font color='#FF0000'>Your Submission has been Completed.</font>";
     }
     if(count($errors) == 0 && $success == false && isset($_POST['submit'])) {
        echo '****<font color="#FF0000">There was a problem with our form. Please email us directly via <a href="mailto:[email protected]">[email protected]</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>";
     }
 }

 ?>

I know the script above isn't clean!! ;)
but I'm new on it :D
thank you very much for your help!
 
Back
Top