Hey Guys,
I’m trying to get this contact form to work but it doesnt seem to want too. It will send the user an email but I never see the contact form email. I have checked for spelling errors and everything is correct. I got the code from a site I got working a while ago that still works I just swapped out the fields.
HTML:
[php]
<div class="col grid3">
<label for="firstname">First Name:</label>
<input type="text" name="firstname" id="firstname" class="full-width" required />
</div>
<div class="col grid3">
<label for="lastname">Last Name:</label>
<input type="text" name="lastname" id="lastname" class="full-width" required />
</div>
<div class="col grid3">
<label for="phone">Phone:</label>
<input type="text" name="phone" id="phone" class="full-width" required />
</div>
<div class="col grid3">
<label for="email">Email:</label>
<input type="text" name="email" id="email" class="full-width" required />
</div>
<div class="col grid6">
<label for="bid">Bid Amout:</label>
<input type="text" name="bid" id="bid" class="full-width" required />
</div>
I agree to the terms and conditions.
<input type="submit" value="Submit Bid" align="right"/>
<div class="clear"></div>
</form>[/php]
PHP:
[php]<?php
// first clean up the input values
foreach($_POST as $key => $value) {
if(ini_get(‘magic_quotes_gpc’))
$_POST[$key] = stripslashes($_POST[$key]);
$_POST[$key] = htmlspecialchars(strip_tags($_POST[$key]));
}
$ip=$_SERVER[‘REMOTE_ADDR’];
$email_to = "[email protected]";
$email_subject = “Painting Bid | TEST”;
$email_message .= “First Name: “.$_POST[“firstname”].”\n”;
$email_message .= “Last Name: “.$_POST[“lastname”].”\n”;
$email_message .= “Email: “.$_POST[“email”].”\n”;
$email_message .= “Phone: “.$_POST[“phone”].”\n”;
$email_message .= “Bid: “.$_POST[“bid”].”\n”;
$userEmail = filter_var( $_POST[‘email’],FILTER_VALIDATE_EMAIL );
if( ! $userEmail ){
exit;
}
//email headers
$headers = 'From: '.$_POST[“email”]."\r\n".
'Reply-To: '.$_POST[“email”]."\r\n" .
‘X-Mailer: PHP/’ . phpversion();
echo (mail($email_to, $email_subject, $email_message, $headers) ? " TEST ");
$ip=$_SERVER[‘REMOTE_ADDR’];
$email_to = $_POST[“email”];
$email_subject = “TEST”;
$email_message1 = " TEST
";
//email headers
$headers = 'From: '.$_POST[“email”]."\r\n".
'Reply-To: '.$_POST[“email”]."\r\n" .
‘X-Mailer: PHP/’ . phpversion();
echo (mail($email_to, $email_subject, $email_message1, $headers) ? “”:"");
exit();
// test input values for errors
$errors = array();
if(strlen($fname) < 2) {
if(!$fname) { $errors[] = “You must enter a name.”; }
else { $errors[] = “Name must be at least 2 characters.”; }
}
if(!$email) { $errors[] = “You must enter an email.”; }
else if (!validEmail($email)) { $errors[] = “You must enter a valid email.”; }
if($errors) {
// output errors to browser and die with a failure message
$errortext = “”;
foreach($errors as $error) {
$errortext .= “
}
die(“The following errors occured:
- ”. $errortext ."
}
// check to see if email is valid
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) { $isValid = false; } // local part length exceeded
else if ($domainLen < 1 || $domainLen > 255) { $isValid = false; } // domain part length exceeded
else if ($local[0] == ‘.’ || $local[$localLen-1] == ‘.’) { $isValid = false; } // local part starts or ends with ‘.’
else if (preg_match(’/\.\./’, $local)) { $isValid = false; } // local part has two consecutive dots
else if (!preg_match(’/^[A-Za-z0-9\-\.]+$/’, $domain)) { $isValid = false; } // character not valid in domain part
else if (preg_match(’/\.\./’, $domain)) { $isValid = false; } // domain part has two consecutive dots
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”))) { $isValid = false; } // domain not found in DNS
}
return $isValid;
}
?>
[/php]
Thanks again!