<html>
<head>
<title>
<? print "Shipping information for ". $_POST[fullname];  ?>
</title.
</head>
<body>
<?php
// Create message. use the period to concatenate strings
$htmlmessage =  "Shipping information from ". $_POST[fullname]. "<br />\n"
				 . "This is the shipping information submitted \n"
				 .  "<p>\n"
				 . "From: ". $_POST[fullname]. "<br /> \n"
				 . "Address: ". $_POST[address1] ."<br />\n"
				 . "         " . $_POST[address2]."<br />\n"
				 . "City   : " . $_POST[city]. " <br />\n"
				 . "State  : " . $_POST[state]. "     Zip  :" . $_POST[zip]."<br />\n"
				 . "Phone  : ". $_POST[phone1]. "-".$_POST[phone2]."-"
				 . $_POST[phone3]. "</p>\n";
//Before proceeding, validate the keyed in e-mail address for
// evil characters
if (isset($_POST[email]))
{
 //see http://www.sitepoint.com/article/974 
 // for information about the regular expression
 	 $validemail = 
	  eregi('^[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.([a-zA-Z]{2,4})$',$_POST['email']);
}

if ($validemail)
	 $htmlmessage .= "EMAIL    : ".  $_POST[email]. "<br />\n";
else
 		print "<p>Valid Email address not provided</p>\n";
// print message
print $htmlmessage;

// Create message. use the period to concatenate strings
$textmessage =  "Shipping information from ". $_POST[fullname]. "\n"
				 . "This is the shipping information submitted \n"
				 . "From: ". $_POST[fullname]. "\n"
				 . "Address: ". $_POST[address1] ."\n"
				 . "         " . $_POST[address2]."\n"
				 . "City   : " . $_POST[city]. " \n"
				 . "State  : " . $_POST[state]. "     Zip  :" . $_POST[zip]."\n"
				 . "Phone  : ". $_POST[phone1]. "-".$_POST[phone2]."-"
				 . $_POST[phone3]. "\n";
if ($validemail)
	 $textmessage .= "EMAIL    : ".  $_POST[email]. "\n";

// set file name for writing
$fname = "../shippingInformation";
if ( is_writable($fname) ) {
	 //we can write to the file
	 // open the file in append mode
	 if (!$handle = fopen($fname, 'w')) {
         print "Cannot open file ($fname)";
         exit;
   }
	 fwrite($handle, $textmessage);
	 fclose($handle);
	 
}
else
	 print "Could not write to the file\n";
// Send email	
 
if ($validemail)
{
 	 $dest = $_POST['email'];
	 $subj = "Shipping Information for purchase from Trierra.org";
	 mail ($dest, $subj, $textmessage, "From: info@trierra.org \r\n".
     "Reply-To: info@trierra.org\r\n" .
     "X-Mailer: PHP/" . phpversion());
}
?>
</body>
</html>