Jump to content

Contact form problem


happypete

Recommended Posts

Hi,

 

I've been looking for a very simple contact form the validates server side - email and name field required.  I will only recieve about 20 emails a month so it doent need to be complicated.

 

I have compiled a script from diffrent code I have found online. 

 

The spam trap 'url' works, the validation works, but when it sends it say 'message sent' but the mail never arrives. It did arrive before I put the 'URL' field in.

 

When I took the 'echo "message sent' out and used the 'header("thanks.php");' it didnt redirect either.

 

Can anyone help?

 

Thanks in advance.

 

 

<?php
function validateName($name){
	//if it's NOT valid
	if(strlen($name) < 4)
		return false;
	//if it's valid
	else
		return true;
}
function validateEmail($email){
	return ereg("^[a-zA-Z0-9]+[a-zA-Z0-9_-]+@[a-zA-Z0-9]+[a-zA-Z0-9.-]+[a-zA-Z0-9]+.[a-z]{2,4}$", $email);
}

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>form</title>
<link rel="stylesheet" href="css/general.css" type="text/css" media="screen" />
</head>
<body>


<?php if( isset($_POST['send']) && (!validateName($_POST['name']) || !validateEmail($_POST['email']) ) ):?>
				<p>
					<?php if(!validateName($_POST['name'])): ?>
						<li><strong>Invalid Name:</strong>Names with more than 3 letters please</li>
					<?php endif ?>
					<?php if(!validateEmail($_POST['email'])): ?>
						<li><strong>Invalid E-mail:</strong>Invalid Email</li>
					<?php endif ?>
				</p>

                
<?php elseif(isset($_POST['send'])):

if(!empty($_POST['URL'])){ die('Have a nice day elsewhere we think you are SPAM - If please try again.'); } 		

else
{
// Configuration Settings
$SendFrom =    "NO REPLY <name@removed.com>";
$SendTo =      "name <name@removed.com>";
$SubjectLine = "subject";

// Build Message Body from Web Form Input
foreach ($_POST as $Field=>$Value)
   $MsgBody .= "$Field: $Value\n";
$MsgBody .= "\n" . @gethostbyaddr($_SERVER["REMOTE_ADDR"]) . "\n" .
   $_SERVER["HTTP_USER_AGENT"];
$MsgBody = htmlspecialchars($MsgBody, ENT_NOQUOTES);  //make content safe

// Send E-Mail and Direct Browser to Confirmation Page
mail($SendTo, $SubjectLine, $MsgBody, "From: $SendFrom");
echo "message sent";
//header("thanks.php");
exit;
} 
endif ?>
            
	<form method="post" id="customForm" action="">
            <div>
			<input id="URL" name="URL" type="text" value="<?php echo $_POST["URL"]; ?>" />
		</div>
            <div>
			<label for="name">Name</label>
			<input id="name" name="name" type="text" value="<?php echo $_POST["name"]; ?>" />
			<span id="nameInfo">What's your name?</span>
		</div>
		<div>
			<label for="email">E-mail</label>
			<input id="email" name="email" type="text" value="<?php echo $_POST["email"]; ?>" />
			<span id="emailInfo">Valid E-mail please, you will need it to log in!</span>
		</div>
		<div>
			<label for="subject">Phone</label>
			<input id="subject" name="subject" type="text" value="<?php echo $_POST["phone"]; ?>" />
			<span id="pass1Info">At least 5 characters: letters, numbers and '_'</span>
		</div>
		<div>
			<label for="check">Check</label>
			<input id="check" name="check" type="text" value="<?php echo $_POST["check"]; ?>"/>
			<span id="pass2Info">Confirm password</span>
		</div>
		<div>
			<label for="message">Message</label>
			<textarea id="message" name="message" cols="10" rows="4" value="<?php echo $_POST["message"]; ?>"></textarea>
		</div>
		<div>
			<input id="send" name="send" type="submit" value="send" />
		</div>
	</form>
</div>
</body>
</html>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.