Needing help on getting a contact form processor and upload processor to work

Hi,

I’m new to php and am looking for some help with having both my upload script and contact form processor in 1 php file…if it’s even possible.

right now, I have this:

<?php

$name = $_POST["name"];
$location = $_POST["location"];
$make = $_POST["make"];
$model = $_POST["model"];
$referral= $_POST["referral"];

$address_to = "removed";
$address_from = "From: test@test.com";
$email_subject_line = $company . "'s form";

$email_text = "Name?" . $name . 
"\
Location? " . $location .
"\
Make? " . $make .
"\
Model? " . $model .
"\
Referral?" . $referral;

mail($address_to, $email_subject_line, $email_text, $address_from);

// Configuration - Your Options
      $allowed_filetypes = array('jpg','gif','bmp','png','jpeg','zip',); // These will be the types of file that will pass the validation.
      $max_filesize = 3145728; // Maximum filesize in BYTES (currently 0.5MB).
      $upload_path = './uploads'; // The place the files will be uploaded to (currently a 'files' directory).
 
   $filename = $_FILES['userfile']['name']; // Get the name of the file (including file extension).
    $ext = substr($filename, strpos($filename,'.'), strlen($filename)-1); // Get the extension from the filename.
 
   // Check if the filetype is allowed, if not DIE and inform the user.
   if(false === in_array(pathinfo($_FILES['userfile']['name'], PATHINFO_EXTENSION), $allowed_filetypes))
   die('The file you attempted to upload is not allowed.');
 
   // Now check the filesize, if it is too large then DIE and inform the user.
   if(filesize($_FILES['userfile']['tmp_name']) > $max_filesize)
      die('The file you attempted to upload is too large.');
 
   // Check if we can upload to the specified path, if not DIE and inform the user.
   if(!is_writable($upload_path))
      die('You cannot upload to the specified directory, please CHMOD it to 777.');
 
   // Upload the file to your specified path.
   if(move_uploaded_file($_FILES['userfile']['tmp_name'],$upload_path . $filename))
         echo 'Your file upload was successful, go back to the homepage by clicking <a href="removed" title="">here</a>'; // It worked.
      else
         echo 'There was an error during the file upload.  Please try again.'; // It failed :(.

?>

how can I make it so that when someone hits submit, it’ll upload the file they attach then send me the email with the rest of the form they filled out?

here’s the code for the form itself

<html>
<head>
</head>
<body>
<form name="contact" enctype="multipart/form-data" action="contact.php" method="post" onsubmit="return validate_fields(this)">
<div id="form">
<ul>
<li>Name:<br />
<input type="text" size="30" name="name" id="name" /></li>
<li><br /></li>
<li>Location:<br />
<input type="text" name="location" id="location" /></li>
<li><br /></li>
<li>Make:<br />
<input type="text" name="make" id="make" /></li>
<li><br /></li>
<li>Model:<br />
<input type="text" name="model" id="model" /></li>
<li><br /></li>
<li>Referral:<br />
<input type="text" name="referral" id="referral" /></li>
<li><br /></li>
<li><label for="file">Select a file:</label> <input type="file" name="userfile" id="file"> <br />
<button>Upload File</button></li>
<li><br /></li>
<li><input type="submit" name="submit" value="Submit" />
&nbsp;
<input type="reset" name="reset" value="Reset" /></li>
</ul>
</div>
<!-- End Contact Form -->
</form>
</body>
</html>

You may change the file name in form tag <form action=“test.php”> to say contact.php and save the file as contact.php it should work, I have tested it.

php file : test.php

<?php
if(isset($_POST['submit']) && !empty($_POST['submit'])) {

$name = $_POST["name"];
$location = $_POST["location"];
$make = $_POST["make"];
$model = $_POST["model"];
$referral= $_POST["referral"];

$address_to = "*****@******.***";
$address_from = "From: *****@******.***";
$email_subject_line = $company . "'s form";

$email_text = "Name?" . $name . 
"\
Location? " . $location .
"\
Make? " . $make .
"\
Model? " . $model .
"\
Referral?" . $referral;

mail($address_to, $email_subject_line, $email_text, $address_from);

// Configuration - Your Options
      $allowed_filetypes = array('jpg','gif','bmp','png','jpeg','zip',); // These will be the types of file that will pass the validation.
      $max_filesize = 3145728; // Maximum filesize in BYTES (currently 0.5MB).
      $upload_path = 'uploads/'; // The place the files will be uploaded to (currently a 'files' directory).
 
    $filename = $_FILES['userfile']['name']; // Get the name of the file (including file extension).
    $ext = substr($filename, strpos($filename,'.'), strlen($filename)-1); // Get the extension from the filename.
 
   // Check if the filetype is allowed, if not DIE and inform the user.
   if(false === in_array(pathinfo($_FILES['userfile']['name'], PATHINFO_EXTENSION), $allowed_filetypes))
   die('The file you attempted to upload is not allowed.');
 
   // Now check the filesize, if it is too large then DIE and inform the user.
   if(filesize($_FILES['userfile']['tmp_name']) > $max_filesize)
      die('The file you attempted to upload is too large.');
 
   // Check if we can upload to the specified path, if not DIE and inform the user.
   if(!is_writable($upload_path))
      die('You cannot upload to the specified directory, please CHMOD it to 777.');
 
   // Upload the file to your specified path.
   if(move_uploaded_file($_FILES['userfile']['tmp_name'],$upload_path . $filename))
         echo 'Your file upload was successful, go back to the homepage by clicking <a href="removed" title="">here</a>'; // It worked.
      else
         echo 'There was an error during the file upload.  Please try again.'; // It failed :(.
}
?>
<html>
<head>
</head>
<body>
<form name="contact" enctype="multipart/form-data" action="test.php" method="post" onsubmit="return validate_fields(this)">
<div id="form">
<ul>
<li>Name:<br/>
<input type="text" size="30" name="name" id="name" /></li>
<li><br /></li>
<li>Location:<br />
<input type="text" name="location" id="location" /></li>
<li><br /></li>
<li>Make:<br />
<input type="text" name="make" id="make"/></li>
<li><br /></li>
<li>Model:<br />
<input type="text" name="model" id="model" /></li>
<li><br /></li>
<li>Referral:<br/>
<input type="text" name="referral" id="referral" /></li>
<li><br /></li>
<li><label for="file">Select a file:</label> <input type="file" name="userfile" id="file"> <br />
<button>Upload File</button></li>
<li><br /></li>
<li><input type="submit" name="submit" value="Submit" />
&nbsp;
<input type="reset" name="reset" value="Reset" /></li>
</ul>
</div>
<!-- End Contact Form -->
</form>
</body>
</html>

thanks! it does work, but for some reason, I cannot get the form to email my domain which has a hyphen in it! if I send the form to an email address without a hyphen in the email address, it works 100%! I’m able to send/receive emails to my email account on the domain with the hyphen…any ideas?!