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;

    }
  }

?>

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 [email]someone@email.com[/email], 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!! :D
but I'm new on it :-O
thank you very much for your help!

This works for me:

//File upload

// Where the file is going to be placed 
$target_path = "uploads/";

// Add the original filename to our target path.  
//Result is "uploads/filename.extension" 
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
    echo "The file ".  basename( $_FILES['uploadedfile']['name']). 
    " has been uploaded";
} else{
    echo "There was an error uploading the file, please try again!";
}	

//End of file upload

'uploadedfile' is the name of the 'file' input type element in the HTML form.

Hi levsh!! thanks!!, but is there any option available for only $allowed_filetypes?
thank you very much!

Hi levsh!! thanks!!, but is there any option available for only $allowed_filetypes?
thank you very much!

I'm sure there is. I just haven't gotten to that point myself.
I'm having trouble attaching an uploaded file to an email. When I get this to working, I'll worry about the allowed filetypes. :)

i changed you body code replace your 'body' code with this and let me knw results ->

<?php

if(isset($_POST)){
if($success==true&&count($errors)==0){
echo"&nbsp;&nbsp;&nbsp;&nbsp;<fontcolor='#FF0000'>YourSubmissionhasbeenCompleted.</font>";

}

if(count($errors)==0&&$success==false&&isset($_POST)){

echo'&nbsp;&nbsp;&nbsp;&nbsp;<fontcolor="#FF0000">Therewasaproblemwithourform.Pleaseemailusdirectlyvia<ahref="mailto:someone@email.com">someone@email.com</a>,thankyou.</font>';

}

if($success==false&&count($errors)>0&&isset($_POST)){

echo"<ul>";

//foreach($errorsas$e){

echo"<fontcolor='#FF0000'><li>$e</li></font>";

//}

echo"</ul>";

}

}

?>

thank you my frind .................

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.