• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 305
  • Last Modified:

How can I make this script not require a file to be uploaded for the contact to be made?

I found some code free of charge online and have been tweaking it for the past few hours to work for my needs. This is a contact form on a site for a t-shirt printer. We'd like to allow a file to be uploaded as an example if the client wants, but not required to do so.

Everything seems functional, except I do not want the file upload field to be required. Even though it isn't necessarily currently required, there seems to be an issue with the fact that the script verifies that the file potentially being uploaded has one of the allowed file extension types (.jpg, .gif, etc). How can I keep the file extension check present but make it not check if no file is being uploaded?

Sorry if this is unclear. Doing my best to explain haha.
<?php 
// Pear library includes
// You should have the pear lib installed
include_once('PEAR/Mail.php');
include_once('PEAR/Mail/mime.php');

//Settings 
$max_allowed_file_size = 20480; // size in KB 
$allowed_extensions = array("jpg", "jpeg", "gif", "bmp", "png");
$upload_folder = './uploads/'; //<-- this folder must be writeable by the script
$your_email = 'editedoutforprivacy';//<<--  update this to your email address

$errors ='';

if(isset($_POST['submit']))
{
	//Get the uploaded file information
	$name_of_uploaded_file =  basename($_FILES['uploaded_file']['name']);
	
	//get the file extension of the file
	$type_of_uploaded_file = substr($name_of_uploaded_file, 
							strrpos($name_of_uploaded_file, '.') + 1);
	
	$size_of_uploaded_file = $_FILES["uploaded_file"]["size"]/1024;
	
	///------------Do Validations-------------
	if(empty($_POST['name'])||empty($_POST['email']))
	{
		$errors .= "\n Name and Email are required fields. ";	
	}
	if(IsInjected($visitor_email))
	{
		$errors .= "\n Bad email value!";
	}
	
	if($size_of_uploaded_file > $max_allowed_file_size ) 
	{
		$errors .= "\n Size of file should be less than $max_allowed_file_size";
	}
	
	//------ Validate the file extension -----
	$allowed_ext = false;
	for($i=0; $i<sizeof($allowed_extensions); $i++) 
	{ 
		if(strcasecmp($allowed_extensions[$i],$type_of_uploaded_file) == 0)
		{
			$allowed_ext = true;		
		}
	}
	
	if(!$allowed_ext)
	{
		$errors .= "\n The uploaded file is not supported file type. ".
		" Only the following file types are supported: ".implode(',',$allowed_extensions);
	}
	
	//send the email 
	if(empty($errors))
	{
		//copy the temp. uploaded file to uploads folder
		$path_of_uploaded_file = $upload_folder . $name_of_uploaded_file;
		$tmp_path = $_FILES["uploaded_file"]["tmp_name"];
		
		if(is_uploaded_file($tmp_path))
		{
		    if(!copy($tmp_path,$path_of_uploaded_file))
		    {
		    	$errors .= '\n error while copying the uploaded file';
		    }
		}
		
		//send the email
		$shirttype = $_POST['shirttype'];
		$quantity = $_POST['quantity'];
		$instructions = $_POST['instructions'];
		$colors = $_POST['colors'];
		$band = $_POST['band'];
		$phone = $_POST['phone'];
		$name = $_POST['name'];
		$email = $_POST['email'];
		$to = $your_email;
		$subject="Price Quote Request";
		$from = $your_email;
		$text = "$name has requested a printing quote. Information below:
		
		\nContact Name: $name
		\nBand Name: $band
		\nEmail Address: $email
		\nPhone Number: $phone
		\nType of Shirt: $shirttype
		\nQuantity: $quantity
		\nNumber of Colors: $colors
		
		\nSpecial Instructions:
		\n$instructions";
		
		$message = new Mail_mime(); 
		$message->setTXTBody($text); 
		$message->addAttachment($path_of_uploaded_file);
		$body = $message->get();
		$extraheaders = array("From"=>$from, "Subject"=>$subject,"Reply-To"=>$email);
		$headers = $message->headers($extraheaders);
		$mail = Mail::factory("mail");
		$mail->send($to, $headers, $body);
		//redirect to 'thank-you page
		header('Location: thank-you.html');
	}
}
///////////////////////////Functions/////////////////
// Function to validate against any email injection attempts
function IsInjected($str)
{
  $injections = array('(\n+)',
              '(\r+)',
              '(\t+)',
              '(%0A+)',
              '(%0D+)',
              '(%08+)',
              '(%09+)'
              );
  $inject = join('|', $injections);
  $inject = "/$inject/i";
  if(preg_match($inject,$str))
    {
    return true;
  }
  else
    {
    return false;
  }
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
<html>
<head>
	<title>File upload form</title>
<!-- define some style elements-->
<style>
label,a, body 
{
	font-family : Arial, Helvetica, sans-serif;
	font-size : 12px; 
}

</style>	
<!-- a helper script for vaidating the form-->
<script language="JavaScript" src="scripts/gen_validatorv31.js" type="text/javascript"></script>	
</head>

<body>
<?php
if(!empty($errors))
{
	echo nl2br($errors);
}
?>
<form method="POST" name="email_form_with_php" 
action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" enctype="multipart/form-data"> 
<p>
<table width="500" border="0" align="center" cellpadding="0" cellspacing="25">
  <tr>
    <td>PICK A SHIRT<br />
    <select name="shirttype" id="select">
      <option value="Standard">Standard</option>
<option value="Soft fit shirt">Soft fit shirt</option>
<option value="American Apparel">American Apparel</option>
    </select></td>
    <td>QUANTITY<br />
    <input name="quantity" type="text"></td>
  </tr>
  <tr>
  <td>NUMBER OF COLORS<br />
    <select name="colors" id="select">
      <option value="1">1</option>
      <option value="2">2</option>
      <option value="3">3</option>
      <option value="4">4</option>
      <option value="5">5</option>
      <option value="6">6</option>
      <option value="CMKY">CMKY</option>
    </select></td>
    <td colspan="2">ATTACH ARTWORK<br />
    <div style="font-size: 12px;">20MB Limit - Low-resolution artwork only.</div>
    <input type="file" name="uploaded_file"></td>
  </tr>
  <tr>
    <td colspan="2">SPECIAL INSTRUCTIONS<br />
    <textarea name="instructions" cols="" rows=""></textarea></td>
  </tr>
  <tr>
    <td>BAND NAME<br />
    <input name="band" type="text"></td>
    <td>CONTACT NAME<br />
    <input name="name" type="text"></td>
  </tr>
  <tr>
    <td>EMAIL ADDRESS<br />
    <input name="email" type="text"></td>
    <td>PHONE NUMBER<br />
    <input name="phone" type="text"></td>
  </tr>
  <tr>
    <td colspan="2"><input type="submit" value="Submit" name='submit'></td>
  </tr>
  <tr>
    <td colspan="2">* Indicates a required field.</td>
  </tr>
</table>
</form>
<script language="JavaScript">
// Code for validating the form
// Visit http://www.javascript-coder.com/html-form/javascript-form-validation.phtml
// for details
var frmvalidator  = new Validator("email_form_with_php");
frmvalidator.addValidation("name","req","Please provide your name"); 
frmvalidator.addValidation("quantity","req","Please provide number of shirts to be printed"); 
frmvalidator.addValidation("band","req","Please provide your band name"); 
frmvalidator.addValidation("colors","req","Please provide the number of colors"); 
frmvalidator.addValidation("shirttype","req","Please provide the type of shirts"); 
frmvalidator.addValidation("email","email","Please enter a valid email address"); 
</script>

</body>
</html>

Open in new window

0
TJOP
Asked:
TJOP
  • 2
1 Solution
 
ncooCommented:
You need to just put an if round each file check, see the following
<?php 
// Pear library includes
// You should have the pear lib installed
include_once('PEAR/Mail.php');
include_once('PEAR/Mail/mime.php');

//Settings 
$max_allowed_file_size = 20480; // size in KB 
$allowed_extensions = array("jpg", "jpeg", "gif", "bmp", "png");
$upload_folder = './uploads/'; //<-- this folder must be writeable by the script
$your_email = 'editedoutforprivacy';//<<--  update this to your email address

$errors ='';

if(isset($_POST['submit']))
{
	//Get the uploaded file information
	$name_of_uploaded_file =  basename($_FILES['uploaded_file']['name']);
	
	//get the file extension of the file
	$type_of_uploaded_file = substr($name_of_uploaded_file, 
							strrpos($name_of_uploaded_file, '.') + 1);
	
	$size_of_uploaded_file = $_FILES["uploaded_file"]["size"]/1024;
	
	///------------Do Validations-------------
	if(empty($_POST['name'])||empty($_POST['email']))
	{
		$errors .= "\n Name and Email are required fields. ";	
	}
	if(IsInjected($visitor_email))
	{
		$errors .= "\n Bad email value!";
	}
	
	//Are they uploading a file
	if ($name_of_uploaded_file) {
		if($size_of_uploaded_file > $max_allowed_file_size ) 
		{
			$errors .= "\n Size of file should be less than $max_allowed_file_size";
		}

		//------ Validate the file extension -----
		$allowed_ext = false;
		for($i=0; $i<sizeof($allowed_extensions); $i++) 
		{ 
			if(strcasecmp($allowed_extensions[$i],$type_of_uploaded_file) == 0)
			{
				$allowed_ext = true;		
			}
		}

		if(!$allowed_ext)
		{
			$errors .= "\n The uploaded file is not supported file type. ".
			" Only the following file types are supported: ".implode(',',$allowed_extensions);
		}
	}
	
	//send the email 
	if(empty($errors))
	{
		//Are they uploading a file
		if ($name_of_uploaded_file) {
			//copy the temp. uploaded file to uploads folder
			$path_of_uploaded_file = $upload_folder . $name_of_uploaded_file;
			$tmp_path = $_FILES["uploaded_file"]["tmp_name"];

			if(is_uploaded_file($tmp_path))
			{
			    if(!copy($tmp_path,$path_of_uploaded_file))
			    {
				$errors .= '\n error while copying the uploaded file';
			    }
			}
		}
		
		//send the email
		$shirttype = $_POST['shirttype'];
		$quantity = $_POST['quantity'];
		$instructions = $_POST['instructions'];
		$colors = $_POST['colors'];
		$band = $_POST['band'];
		$phone = $_POST['phone'];
		$name = $_POST['name'];
		$email = $_POST['email'];
		$to = $your_email;
		$subject="Price Quote Request";
		$from = $your_email;
		$text = "$name has requested a printing quote. Information below:
		
		\nContact Name: $name
		\nBand Name: $band
		\nEmail Address: $email
		\nPhone Number: $phone
		\nType of Shirt: $shirttype
		\nQuantity: $quantity
		\nNumber of Colors: $colors
		
		\nSpecial Instructions:
		\n$instructions";
		
		$message = new Mail_mime(); 
		$message->setTXTBody($text); 
		//Are they uploading a file
		if ($name_of_uploaded_file) {
			$message->addAttachment($path_of_uploaded_file);
		}
		$body = $message->get();
		$extraheaders = array("From"=>$from, "Subject"=>$subject,"Reply-To"=>$email);
		$headers = $message->headers($extraheaders);
		$mail = Mail::factory("mail");
		$mail->send($to, $headers, $body);
		//redirect to 'thank-you page
		header('Location: thank-you.html');
	}
}
///////////////////////////Functions/////////////////
// Function to validate against any email injection attempts
function IsInjected($str)
{
  $injections = array('(\n+)',
              '(\r+)',
              '(\t+)',
              '(%0A+)',
              '(%0D+)',
              '(%08+)',
              '(%09+)'
              );
  $inject = join('|', $injections);
  $inject = "/$inject/i";
  if(preg_match($inject,$str))
    {
    return true;
  }
  else
    {
    return false;
  }
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
<html>
<head>
	<title>File upload form</title>
<!-- define some style elements-->
<style>
label,a, body 
{
	font-family : Arial, Helvetica, sans-serif;
	font-size : 12px; 
}

</style>	
<!-- a helper script for vaidating the form-->
<script language="JavaScript" src="scripts/gen_validatorv31.js" type="text/javascript"></script>	
</head>

<body>
<?php
if(!empty($errors))
{
	echo nl2br($errors);
}
?>
<form method="POST" name="email_form_with_php" 
action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" enctype="multipart/form-data"> 
<p>
<table width="500" border="0" align="center" cellpadding="0" cellspacing="25">
  <tr>
    <td>PICK A SHIRT<br />
    <select name="shirttype" id="select">
      <option value="Standard">Standard</option>
<option value="Soft fit shirt">Soft fit shirt</option>
<option value="American Apparel">American Apparel</option>
    </select></td>
    <td>QUANTITY<br />
    <input name="quantity" type="text"></td>
  </tr>
  <tr>
  <td>NUMBER OF COLORS<br />
    <select name="colors" id="select">
      <option value="1">1</option>
      <option value="2">2</option>
      <option value="3">3</option>
      <option value="4">4</option>
      <option value="5">5</option>
      <option value="6">6</option>
      <option value="CMKY">CMKY</option>
    </select></td>
    <td colspan="2">ATTACH ARTWORK<br />
    <div style="font-size: 12px;">20MB Limit - Low-resolution artwork only.</div>
    <input type="file" name="uploaded_file"></td>
  </tr>
  <tr>
    <td colspan="2">SPECIAL INSTRUCTIONS<br />
    <textarea name="instructions" cols="" rows=""></textarea></td>
  </tr>
  <tr>
    <td>BAND NAME<br />
    <input name="band" type="text"></td>
    <td>CONTACT NAME<br />
    <input name="name" type="text"></td>
  </tr>
  <tr>
    <td>EMAIL ADDRESS<br />
    <input name="email" type="text"></td>
    <td>PHONE NUMBER<br />
    <input name="phone" type="text"></td>
  </tr>
  <tr>
    <td colspan="2"><input type="submit" value="Submit" name='submit'></td>
  </tr>
  <tr>
    <td colspan="2">* Indicates a required field.</td>
  </tr>
</table>
</form>
<script language="JavaScript">
// Code for validating the form
// Visit http://www.javascript-coder.com/html-form/javascript-form-validation.phtml
// for details
var frmvalidator  = new Validator("email_form_with_php");
frmvalidator.addValidation("name","req","Please provide your name"); 
frmvalidator.addValidation("quantity","req","Please provide number of shirts to be printed"); 
frmvalidator.addValidation("band","req","Please provide your band name"); 
frmvalidator.addValidation("colors","req","Please provide the number of colors"); 
frmvalidator.addValidation("shirttype","req","Please provide the type of shirts"); 
frmvalidator.addValidation("email","email","Please enter a valid email address"); 
</script>

</body>
</html>

Open in new window

0
 
sjklein42Commented:
Try this:

<?php 
// Pear library includes
// You should have the pear lib installed
include_once('PEAR/Mail.php');
include_once('PEAR/Mail/mime.php');

//Settings 
$max_allowed_file_size = 20480; // size in KB 
$allowed_extensions = array("jpg", "jpeg", "gif", "bmp", "png");
$upload_folder = './uploads/'; //<-- this folder must be writeable by the script
$your_email = 'editedoutforprivacy';//<<--  update this to your email address

$errors ='';

if(isset($_POST['submit']))
{
	//Get the uploaded file information
	$name_of_uploaded_file =  basename($_FILES['uploaded_file']['name']);
	if ($name_of_uploaded_file != '')
	{
		//get the file extension of the file
		$type_of_uploaded_file = substr($name_of_uploaded_file, 
								strrpos($name_of_uploaded_file, '.') + 1);
		
		$size_of_uploaded_file = $_FILES["uploaded_file"]["size"]/1024;
		
		///------------Do Validations-------------
		if(empty($_POST['name'])||empty($_POST['email']))
		{
			$errors .= "\n Name and Email are required fields. ";	
		}
		if(IsInjected($visitor_email))
		{
			$errors .= "\n Bad email value!";
		}
		
		if($size_of_uploaded_file > $max_allowed_file_size ) 
		{
			$errors .= "\n Size of file should be less than $max_allowed_file_size";
		}
		
		//------ Validate the file extension -----
		$allowed_ext = false;
		for($i=0; $i<sizeof($allowed_extensions); $i++) 
		{ 
			if(strcasecmp($allowed_extensions[$i],$type_of_uploaded_file) == 0)
			{
				$allowed_ext = true;		
			}
		}
		
		if(!$allowed_ext)
		{
			$errors .= "\n The uploaded file is not supported file type. ".
			" Only the following file types are supported: ".implode(',',$allowed_extensions);
		}
	}
	
	//send the email 
	if(empty($errors))
	{
		if ($name_of_uploaded_file != '')
		{
			//copy the temp. uploaded file to uploads folder
			$path_of_uploaded_file = $upload_folder . $name_of_uploaded_file;
			$tmp_path = $_FILES["uploaded_file"]["tmp_name"];
			
			if(is_uploaded_file($tmp_path))
			{
			    if(!copy($tmp_path,$path_of_uploaded_file))
			    {
				$errors .= '\n error while copying the uploaded file';
			    }
			}
		}
		
		//send the email
		$shirttype = $_POST['shirttype'];
		$quantity = $_POST['quantity'];
		$instructions = $_POST['instructions'];
		$colors = $_POST['colors'];
		$band = $_POST['band'];
		$phone = $_POST['phone'];
		$name = $_POST['name'];
		$email = $_POST['email'];
		$to = $your_email;
		$subject="Price Quote Request";
		$from = $your_email;
		$text = "$name has requested a printing quote. Information below:
		
		\nContact Name: $name
		\nBand Name: $band
		\nEmail Address: $email
		\nPhone Number: $phone
		\nType of Shirt: $shirttype
		\nQuantity: $quantity
		\nNumber of Colors: $colors
		
		\nSpecial Instructions:
		\n$instructions";
		
		$message = new Mail_mime(); 
		$message->setTXTBody($text); 
		
		if ($name_of_uploaded_file != '')
		{
			$message->addAttachment($path_of_uploaded_file);
		}
		$body = $message->get();
		$extraheaders = array("From"=>$from, "Subject"=>$subject,"Reply-To"=>$email);
		$headers = $message->headers($extraheaders);
		$mail = Mail::factory("mail");
		$mail->send($to, $headers, $body);
		//redirect to 'thank-you page
		header('Location: thank-you.html');
	}
}
///////////////////////////Functions/////////////////
// Function to validate against any email injection attempts
function IsInjected($str)
{
  $injections = array('(\n+)',
              '(\r+)',
              '(\t+)',
              '(%0A+)',
              '(%0D+)',
              '(%08+)',
              '(%09+)'
              );
  $inject = join('|', $injections);
  $inject = "/$inject/i";
  if(preg_match($inject,$str))
    {
    return true;
  }
  else
    {
    return false;
  }
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
<html>
<head>
	<title>File upload form</title>
<!-- define some style elements-->
<style>
label,a, body 
{
	font-family : Arial, Helvetica, sans-serif;
	font-size : 12px; 
}

</style>	
<!-- a helper script for vaidating the form-->
<script language="JavaScript" src="scripts/gen_validatorv31.js" type="text/javascript"></script>	
</head>

<body>
<?php
if(!empty($errors))
{
	echo nl2br($errors);
}
?>
<form method="POST" name="email_form_with_php" 
action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" enctype="multipart/form-data"> 
<p>
<table width="500" border="0" align="center" cellpadding="0" cellspacing="25">
  <tr>
    <td>PICK A SHIRT<br />
    <select name="shirttype" id="select">
      <option value="Standard">Standard</option>
<option value="Soft fit shirt">Soft fit shirt</option>
<option value="American Apparel">American Apparel</option>
    </select></td>
    <td>QUANTITY<br />
    <input name="quantity" type="text"></td>
  </tr>
  <tr>
  <td>NUMBER OF COLORS<br />
    <select name="colors" id="select">
      <option value="1">1</option>
      <option value="2">2</option>
      <option value="3">3</option>
      <option value="4">4</option>
      <option value="5">5</option>
      <option value="6">6</option>
      <option value="CMKY">CMKY</option>
    </select></td>
    <td colspan="2">ATTACH ARTWORK<br />
    <div style="font-size: 12px;">20MB Limit - Low-resolution artwork only.</div>
    <input type="file" name="uploaded_file"></td>
  </tr>
  <tr>
    <td colspan="2">SPECIAL INSTRUCTIONS<br />
    <textarea name="instructions" cols="" rows=""></textarea></td>
  </tr>
  <tr>
    <td>BAND NAME<br />
    <input name="band" type="text"></td>
    <td>CONTACT NAME<br />
    <input name="name" type="text"></td>
  </tr>
  <tr>
    <td>EMAIL ADDRESS<br />
    <input name="email" type="text"></td>
    <td>PHONE NUMBER<br />
    <input name="phone" type="text"></td>
  </tr>
  <tr>
    <td colspan="2"><input type="submit" value="Submit" name='submit'></td>
  </tr>
  <tr>
    <td colspan="2">* Indicates a required field.</td>
  </tr>
</table>
</form>
<script language="JavaScript">
// Code for validating the form
// Visit http://www.javascript-coder.com/html-form/javascript-form-validation.phtml
// for details
var frmvalidator  = new Validator("email_form_with_php");
frmvalidator.addValidation("name","req","Please provide your name"); 
frmvalidator.addValidation("quantity","req","Please provide number of shirts to be printed"); 
frmvalidator.addValidation("band","req","Please provide your band name"); 
frmvalidator.addValidation("colors","req","Please provide the number of colors"); 
frmvalidator.addValidation("shirttype","req","Please provide the type of shirts"); 
frmvalidator.addValidation("email","email","Please enter a valid email address"); 
</script>

</body>
</html>

Open in new window

0
 
sjklein42Commented:
Corrected version:

<?php 
// Pear library includes
// You should have the pear lib installed
include_once('PEAR/Mail.php');
include_once('PEAR/Mail/mime.php');

//Settings 
$max_allowed_file_size = 20480; // size in KB 
$allowed_extensions = array("jpg", "jpeg", "gif", "bmp", "png");
$upload_folder = './uploads/'; //<-- this folder must be writeable by the script
$your_email = 'editedoutforprivacy';//<<--  update this to your email address

$errors ='';

if(isset($_POST['submit']))
{

	///------------Do Validations-------------
	if(empty($_POST['name'])||empty($_POST['email']))
	{
		$errors .= "\n Name and Email are required fields. ";	
	}
	if(IsInjected($visitor_email))
	{
		$errors .= "\n Bad email value!";
	}
		
	//Get the uploaded file information
	$name_of_uploaded_file =  basename($_FILES['uploaded_file']['name']);
	if ($name_of_uploaded_file != '')
	{
		//get the file extension of the file
		$type_of_uploaded_file = substr($name_of_uploaded_file, 
								strrpos($name_of_uploaded_file, '.') + 1);
		
		$size_of_uploaded_file = $_FILES["uploaded_file"]["size"]/1024;

		if($size_of_uploaded_file > $max_allowed_file_size ) 
		{
			$errors .= "\n Size of file should be less than $max_allowed_file_size";
		}
		
		//------ Validate the file extension -----
		$allowed_ext = false;
		for($i=0; $i<sizeof($allowed_extensions); $i++) 
		{ 
			if(strcasecmp($allowed_extensions[$i],$type_of_uploaded_file) == 0)
			{
				$allowed_ext = true;		
			}
		}
		
		if(!$allowed_ext)
		{
			$errors .= "\n The uploaded file is not supported file type. ".
			" Only the following file types are supported: ".implode(',',$allowed_extensions);
		}
	}
	
	//send the email 
	if(empty($errors))
	{
		if ($name_of_uploaded_file != '')
		{
			//copy the temp. uploaded file to uploads folder
			$path_of_uploaded_file = $upload_folder . $name_of_uploaded_file;
			$tmp_path = $_FILES["uploaded_file"]["tmp_name"];
			
			if(is_uploaded_file($tmp_path))
			{
			    if(!copy($tmp_path,$path_of_uploaded_file))
			    {
				$errors .= '\n error while copying the uploaded file';
			    }
			}
		}
		
		//send the email
		$shirttype = $_POST['shirttype'];
		$quantity = $_POST['quantity'];
		$instructions = $_POST['instructions'];
		$colors = $_POST['colors'];
		$band = $_POST['band'];
		$phone = $_POST['phone'];
		$name = $_POST['name'];
		$email = $_POST['email'];
		$to = $your_email;
		$subject="Price Quote Request";
		$from = $your_email;
		$text = "$name has requested a printing quote. Information below:
		
		\nContact Name: $name
		\nBand Name: $band
		\nEmail Address: $email
		\nPhone Number: $phone
		\nType of Shirt: $shirttype
		\nQuantity: $quantity
		\nNumber of Colors: $colors
		
		\nSpecial Instructions:
		\n$instructions";
		
		$message = new Mail_mime(); 
		$message->setTXTBody($text); 
		
		if ($name_of_uploaded_file != '')
		{
			$message->addAttachment($path_of_uploaded_file);
		}
		$body = $message->get();
		$extraheaders = array("From"=>$from, "Subject"=>$subject,"Reply-To"=>$email);
		$headers = $message->headers($extraheaders);
		$mail = Mail::factory("mail");
		$mail->send($to, $headers, $body);
		//redirect to 'thank-you page
		header('Location: thank-you.html');
	}
}
///////////////////////////Functions/////////////////
// Function to validate against any email injection attempts
function IsInjected($str)
{
  $injections = array('(\n+)',
              '(\r+)',
              '(\t+)',
              '(%0A+)',
              '(%0D+)',
              '(%08+)',
              '(%09+)'
              );
  $inject = join('|', $injections);
  $inject = "/$inject/i";
  if(preg_match($inject,$str))
    {
    return true;
  }
  else
    {
    return false;
  }
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
<html>
<head>
	<title>File upload form</title>
<!-- define some style elements-->
<style>
label,a, body 
{
	font-family : Arial, Helvetica, sans-serif;
	font-size : 12px; 
}

</style>	
<!-- a helper script for vaidating the form-->
<script language="JavaScript" src="scripts/gen_validatorv31.js" type="text/javascript"></script>	
</head>

<body>
<?php
if(!empty($errors))
{
	echo nl2br($errors);
}
?>
<form method="POST" name="email_form_with_php" 
action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" enctype="multipart/form-data"> 
<p>
<table width="500" border="0" align="center" cellpadding="0" cellspacing="25">
  <tr>
    <td>PICK A SHIRT<br />
    <select name="shirttype" id="select">
      <option value="Standard">Standard</option>
<option value="Soft fit shirt">Soft fit shirt</option>
<option value="American Apparel">American Apparel</option>
    </select></td>
    <td>QUANTITY<br />
    <input name="quantity" type="text"></td>
  </tr>
  <tr>
  <td>NUMBER OF COLORS<br />
    <select name="colors" id="select">
      <option value="1">1</option>
      <option value="2">2</option>
      <option value="3">3</option>
      <option value="4">4</option>
      <option value="5">5</option>
      <option value="6">6</option>
      <option value="CMKY">CMKY</option>
    </select></td>
    <td colspan="2">ATTACH ARTWORK<br />
    <div style="font-size: 12px;">20MB Limit - Low-resolution artwork only.</div>
    <input type="file" name="uploaded_file"></td>
  </tr>
  <tr>
    <td colspan="2">SPECIAL INSTRUCTIONS<br />
    <textarea name="instructions" cols="" rows=""></textarea></td>
  </tr>
  <tr>
    <td>BAND NAME<br />
    <input name="band" type="text"></td>
    <td>CONTACT NAME<br />
    <input name="name" type="text"></td>
  </tr>
  <tr>
    <td>EMAIL ADDRESS<br />
    <input name="email" type="text"></td>
    <td>PHONE NUMBER<br />
    <input name="phone" type="text"></td>
  </tr>
  <tr>
    <td colspan="2"><input type="submit" value="Submit" name='submit'></td>
  </tr>
  <tr>
    <td colspan="2">* Indicates a required field.</td>
  </tr>
</table>
</form>
<script language="JavaScript">
// Code for validating the form
// Visit http://www.javascript-coder.com/html-form/javascript-form-validation.phtml
// for details
var frmvalidator  = new Validator("email_form_with_php");
frmvalidator.addValidation("name","req","Please provide your name"); 
frmvalidator.addValidation("quantity","req","Please provide number of shirts to be printed"); 
frmvalidator.addValidation("band","req","Please provide your band name"); 
frmvalidator.addValidation("colors","req","Please provide the number of colors"); 
frmvalidator.addValidation("shirttype","req","Please provide the type of shirts"); 
frmvalidator.addValidation("email","email","Please enter a valid email address"); 
</script>

</body>
</html>

Open in new window

0
 
TJOPAuthor Commented:
THANK YOU!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now