Solved

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

Posted on 2011-09-29
4
291 Views
Last Modified: 2012-08-13
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
Comment
Question by:TJOP
  • 2
4 Comments
 
LVL 15

Expert Comment

by:ncoo
ID: 36841796
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
 
LVL 16

Expert Comment

by:sjklein42
ID: 36841815
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
 
LVL 16

Accepted Solution

by:
sjklein42 earned 500 total points
ID: 36844592
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
 

Author Closing Comment

by:TJOP
ID: 36890054
THANK YOU!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now