Jump to content

Why would a form only work sometimes?


Elle

Recommended Posts

Hi

 

I am only starting to learn PHP now and would appreciate some help. A while back I created a form and used a tool to create the PHP script for it. When I test the form online, it works most of the time but nevertheless it frequently does not submit the information. Often I go back and resubmit the same information and then it goes through.

 

I find that I'm more likely to get an error if I have not tested it for at least a few minutes, and also after I cleared my cache. I've searched for a solution but have not been successful and find it quite confusing.

 

Here is my PHP code:

<?php
// Receiving variables
@$pfw_ip= $_SERVER['REMOTE_ADDR'];
@$First_name = addslashes($_POST['FirstName']);
@$Surname = addslashes($_POST['Surname']);
@$Email = addslashes($_POST['Email']);
@$Telephone = addslashes($_POST['Telephone']);
@$Query = addslashes($_POST['Query']);
@$Discovery_status = addslashes($_POST['DiscoveryStatus']);

// Validation
if (strlen($First_name) == 0 )
{
header("Location: contact-error.html");
exit;
}

if (strlen($Surname) == 0 )
{
header("Location: contact-error.html");
exit;
}

if (! ereg('[A-Za-z0-9_-]+\@[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+', $Email))
{
header("Location: contact-error.html");
exit;
}

if (strlen($Email) == 0 )
{
header("Location: contact-error.html");
exit;
}

if (strlen($Telephone) == 0 )
{
header("Location: contact-error.html");
exit;
}

if (strlen($Query) == 0 )
{
header("Location: contact-error.html");
exit;
}

if (strlen($Discovery_status) == 0 )
{
header("Location: contact-error.html");
exit;
}

//Sending Email to form owner
$pfw_header = "From: $Email\n"
  . "Reply-To: $Email\n";
$pfw_subject = "Website Contact Enquiry";
$pfw_email_to = "[email protected]";
$pfw_message = "Visitor's IP: $pfw_ip\n"
. "First_name: $First_name\n"
. "Surname: $Surname\n"
. "Email: $Email\n"
. "Telephone: $Telephone\n"
. "Query: $Query\n"
. "Discovery_status: $Discovery_status\n";
@mail($pfw_email_to, $pfw_subject ,$pfw_message ,$pfw_header ) ;

header("Location: contact-thanks.html");

?>

 

Thanks!

 

EDIT: Please use [code][/code] tags when posting code on the forums!

Link to comment
https://forums.phpfreaks.com/topic/167174-why-would-a-form-only-work-sometimes/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.