I'm putting together a form and I understand the basics of php and what I want to accomplish I'm just not sure about the syntax of merging the form processing, validation and than the include so that is show another page after its done. Forums are usually a last resort for me but my attempts at linking them together has been going no where. Any advice or input would very helpful to me learning this language.
This is the code I came up with for the processing
<?php
$folioNum = $_POST['folioNum'];
$propOwner = $_POST['propOwner'];
$addr = $_POST['addr'];
$city = $_POST['city'];
$county = $_POST['county'];
$zip = $_POST['zip'];
$state = $_POST['state'];
$legalDes = $_POST['legalDes'];
$instructions = $_POST['instructions'];
$compName = $_POST['compName'];
$requestBy = $_POST['requestBy'];
$fileNum= $_POST['fileNum'];
$needBy = $_POST['needBy'];
$phNum1 = $_POST['phNum1'];
$phNum2 = $_POST['phNum2'];
$phNum3 = $_POST['phNum3'];
$faxNum1 = $_POST['faxNum1'];
$faxNum2 = $_POST['faxNum2'];
$faxNum3 = $_POST['faxNum3'];
$email = $_POST['email'];
$emailSub = "Order Test!";
$emailBody =
"Folio Number: $folioNum \n
Property Owner: $propOwner\n
Address: $addr\n
City: $city\n
County: $county\n
Zipcode: $zip\n
State: $state\n
Legal Description: $legalDes\n
Instructions: $instructions\n
Comapany Name: $compName\n
Request By: $requestBy\n
File Number: $fileNum\n
Needed By: $needBy\n
Phone Number: $phNum1 $phNum2 $phNum3\n
Fax Number: $faxNum1 $faxNum2 $faxNum3\n
Email: $email\n";
$emailTo = "email@email.com";
$headers = "Reply to $email \r\n";
mail($emailTo,$emailSub,$emailBody);
?>
I read an article on proper email verification and that this was the way to go. The only field I am trying to require is the email. But should I put other verifications up on one's that aren't required to avoid spam or hacks?
/**
Validate an email address.
Provide email address (raw input)
Returns true if the email address has the email
address format and the domain exists.
*/
function validEmail($email)
{
$isValid = true;
$atIndex = strrpos($email, "@");
if (is_bool($atIndex) && !$atIndex)
{
$isValid = false;
}
else
{
$domain = substr($email, $atIndex+1);
$local = substr($email, 0, $atIndex);
$localLen = strlen($local);
$domainLen = strlen($domain);
if ($localLen < 1 || $localLen > 64)
{
// local part length exceeded
$isValid = false;
}
else if ($domainLen < 1 || $domainLen > 255)
{
// domain part length exceeded
$isValid = false;
}
else if ($local[0] == '.' || $local[$localLen-1] == '.')
{
// local part starts or ends with '.'
$isValid = false;
}
else if (preg_match('/\\.\\./', $local))
{
// local part has two consecutive dots
$isValid = false;
}
else if (!preg_match('/^[A-Za-z0-9\\-\\.]+$/', $domain))
{
// character not valid in domain part
$isValid = false;
}
else if (preg_match('/\\.\\./', $domain))
{
// domain part has two consecutive dots
$isValid = false;
}
else if
(!preg_match('/^(\\\\.|[A-Za-z0-9!#%&`_=\\/$\'*+?^{}|~.-])+$/',
str_replace("\\\\","",$local)))
{
// character not valid in local part unless
// local part is quoted
if (!preg_match('/^"(\\\\"|[^"])+"$/',
str_replace("\\\\","",$local)))
{
$isValid = false;
}
}
if ($isValid && !(checkdnsrr($domain,"MX") ||
↪checkdnsrr($domain,"A")))
{
// domain not found in DNS
$isValid = false;
}
}
return $isValid;
}
and finally ending in this with the information sent to email
include("submitsuccess.html");