Code:
// Validation
if (strlen($name) == 0 )
{
header("Location: Fail.html");
exit;
}
if (strlen($organization) == 0 )
{
header("Location: Fail.html");
exit;
}
if (! ereg('[A-Za-z0-9_-]+\@[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+', $email))
{
header("Location: Fail.html");
exit;
}
if (strlen($email) == 0 )
{
header("Location: Fail.html");
exit;
}
if (strlen($phone) == 0 )
{
header("Location: Fail.html");
exit;
}
if (strlen($address) == 0 )
{
header("Location: Fail.html");
exit;
}
if (strlen($area) == 0 )
{
header("Location: Fail.html");
exit;
}
if (strlen($Sample_N) == 0 )
{
header("Location: Fail.html");
exit;
}
Firstly, you're relying on register_globals, which is a Bad Idea®. Secondly, this will throw a warning if the variables don't exist. Thirdly, redirecting using HTTP requires an absolute URI according to the specification. Fourthly, your email address regex rejects several perfectly valid address (like us@er@domain.com, for example), so let's drop it. Fifthly, this whole thing can be written like so:
Code:
// Validation
$required_fields = array('name', 'organization', 'email', 'phone', 'address', 'area', 'Sample_N');
for($i = 0; $i < count($required_fields); ++$i)
if(empty($_REQUEST[$required_fields[$i]]))
die(header('Location: http://www.yoursite.com/Fail.html'));
Code:
$pfw_message = "Visitor's IP: $pfw_ip\r\n"
. "name: $name\n"
. "organization: $organization\n"
. "email: $email\n"
. "phone: $phone\n"
. "fax: $fax\n"
. "address: $address\n"
. "payor: $payor\n"
. "payorganization: $payorganization\n"
. "payemail: $payemail\n"
. "payphone: $payphone\n"
. "payfax: $payfax\n"
. "payaddress: $payaddress\n"
. "area: $area\n"
. "comments: $comments\n"
. "requests: $requests\n"
. "Credit: $Credit\n"
. "Check: $Check\n"
. "Bill: $Bill\n"
. "urgency: $urgency\n"
. "Sample_N: $Sample_N\n"
. "sampleNumber1: $sampleNumber1\n"
. "Charcoal1: $Charcoal1\n"
. "Uncharred1: $Uncharred1\n"
. "Sort1: $Sort1\n"
. "Sediment1: $Sediment1\n"
. "seaShell1: $seaShell1\n"
. "ceramicResidue1: $ceramicResidue1\n"
. "bone1: $bone1\n"
. "Other1: $Other1\n"
. "sampleNumber2: $sampleNumber2\n"
. "Charcoal2: $Charcoal2\n"
. "Uncharred2: $Uncharred2\n"
. "Sort2: $Sort2\n"
. "Sediment2: $Sediment2\n"
. "seaShell2: $seaShell2\n"
. "ceramicResidue2: $ceramicResidue2\n"
. "bone2: $bone2\n"
. "Other2: $Other2\n"
. "sampleNumber3: $sampleNumber3\n"
. "Charcoal3: $Charcoal3\n"
. "Uncharred3: $Uncharred3\n"
. "Sort3: $Sort3\n"
. "Sediment3: $Sediment3\n"
. "seaShell3: $seaShell3\n"
. "ceramicResidue3: $ceramicResidue3\n"
. "bone3: $bone3\n"
. "Other3: $Other3\n"
. "sampleNumber4: $sampleNumber4\n"
. "Charcoal4: $Charcoal4\n"
. "Uncharred4: $Uncharred4\n"
. "Sort4: $Sort4\n"
. "Sediment4: $Sediment4\n"
. "seaShell4: $seaShell4\n"
. "ceramicResidue4: $ceramicResidue4\n"
. "bone4: $bone4\n"
. "Other4: $Other4\n"
. "sampleNumber5: $sampleNumber5\n"
. "Charcoal5: $Charcoal5\n"
. "Uncharred5: $Uncharred5\n"
. "Sort5: $Sort5\n"
. "Sediment5: $Sediment5\n"
. "seaShell5: $seaShell5\n"
. "ceramicResidue5: $ceramicResidue5\n"
. "bone5: $bone5\n"
. "Other5: $Other5\n"
. "sampleNumber6: $sampleNumber6\n"
. "Charcoal6: $Charcoal6\n"
. "Uncharred6: $Uncharred6\n"
. "Sort6: $Sort6\n"
. "Sediment6: $Sediment6\n"
. "seaShell6: $seaShell6\n"
. "ceramicResidue6: $ceramicResidue6\n"
. "bone6: $bone6\n"
. "Other6: $Other6\n"
. "sampleNumber7: $sampleNumber7\n"
. "Charcoal7: $Charcoal7\n"
. "Uncharred7: $Uncharred7\n"
. "Sort7: $Sort7\n"
. "Sediment7: $Sediment7\n"
. "seaShell7: $seaShell7\n"
. "ceramicResidue7: $ceramicResidue7\n"
. "bone7: $bone7\n"
. "Other7: $Other7\n"
. "sampleNumber8: $sampleNumber8\n"
. "Charcoal8: $Charcoal8\n"
. "Uncharred8: $Uncharred8\n"
. "Sort8: $Sort8\n"
. "Sediment8: $Sediment8\n"
. "seaShell8: $seaShell8\n"
. "ceramicResidue8: $ceramicResidue8\n"
. "bone8: $bone8\n"
. "Other8: $Other8\n"
. "sampleNumber9: $sampleNumber9\n"
. "Charcoal9: $Charcoal9\n"
. "Uncharred9: $Uncharred9\n"
. "Sort9: $Sort9\n"
. "Sediment9: $Sediment9\n"
. "seaShell9: $seaShell9\n"
. "ceramicResidue9: $ceramicResidue9\n"
. "bone9: $bone9\n"
. "Other9: $Other9\n"
. "sampleNumber10: $sampleNumber10\n"
. "Charcoal10: $Charcoal10\n"
. "Uncharred10: $Uncharred10\n"
. "Sort10: $Sort10\n"
. "Sediment10: $Sediment10\n"
. "seaShell10: $seaShell10\n"
. "ceramicResidue10: $ceramicResidue10\n"
. "bone10: $bone10\n"
. "Other10: $Other10\n";
Again, owch! Not only is this much longer than it needs to be, again, but you're mixing Windows and UNIX linebreaks. Make up your mind. Using Windows linebreaks is probably safest, since almost all UNIX programs are smart enough to recognise and deal with Windows linebreaks, while the reverse is far from true. Try:
Code:
$pfw_message = "Visitor's IP: $pfw_ip\r\n";
foreach($_POST as $k => $v)
$pfw_message .= "$k: $v\r\n";
Code:
@mail($pfw_email_to, $pfw_subject ,$pfw_message ,$pfw_header) ;
Rather than suppressing errors with @ (which is a bad idea, by the way: if there's an error you should deal with it, and if you don't want to deal with errors you should suppress them globally using error_handling(E_NONE)), try actually checking that the email has been sent. So, finally, the script becomes:
Code:
<?php
// Validation
$required_fields = array('name', 'organization', 'email', 'phone', 'address', 'area', 'Sample_N');
for($i = 0; $i < count($required_fields); ++$i)
if(empty($_REQUEST[$required_fields[$i]]))
die(header('Location: http://www.yoursite.com/Fail.html'));
$pfw_message = "Visitor's IP: $pfw_ip\r\n";
foreach($_POST as $k => $v)
$pfw_message .= "$k: $v\r\n";
if(!mail($pfw_email_to, $pfw_subject, $pfw_message, $pfw_header))
die(header('Location: http://www.yoursite.com/Fail.html'));
//Sending auto respond Email to visitor
$pfw_header = "From: ams@paleoresearch.com\r\n" .
"Reply-To: ams@paleoresearch.com\r\n\r\n";
$pfw_subject = 'AMS info sent';
$pfw_email_to = $email;
$pfw_message = <<< END
Your AMS sample information was sent. We will be contacting you at the phone number provided within the next two business days.
Thank You
PaleoResearch Institute
END;
if(!mail($pfw_email_to, $pfw_subject, $pfw_message, $pfw_header))
die(header('Location: http://www.yoursite.com/success.html'));
else
die(header('Location: http://www.yoursite.com/success.html'));
Bookmarks