Hi.
I'm having a problem submitting a form with this code:
PHP
Code:
<?php session_start() ?>
<?php
$to = 'you@example.com';
$subject = 'Subject';
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/plain; charset=iso-8859-1' . "\r\n";
$headers .= 'From: Me' . "\r\n";
$response = null;
define('EMAIL_PATTERN', '/^[\w\.-]{1,}\@([\da-zA-Z-]{1,}\.){1,}[\da-zA-Z-]+$/');
define('EMAIL_LENGTH', 200);
if (isset($_POST['submit'])) {
// check all required fields
if (!empty($_POST['firstname']) &&
!empty($_POST['email']) &&
!empty($_POST['contact']) &&
!empty($_POST['organization']) &&
!empty($_POST['website'])){
// escape all inputs
$firstname = escape($_POST['firstname']);
$email = escape($_POST['email']);
$contact = escape($_POST['contact']);
$organization = escape($_POST['organization']);
$website = escape($_POST['website']);
// sanitize the prospect e-mail address
if (sanitize($email, EMAIL_PATTERN, EMAIL_LENGTH)) {
// send mail to prospect and clayant
$sentmail = mail($to, $subject, 'Name: ' . $firstname . "\n\n" . "Email: " . $email . "\n\n" . "Contact Number: " . $contact . "\n\n" . "Organization: " . $organization . "\n\n" . "Website: " . $website, $headers);
header('location: thanks.php');
} else {
// bail
$response = 'Please check your e-mail address again.';
}
} else {
// bail
$response = 'Please enter all required fields marked with an asterisk (*).';
}
}
function escape($string) {
return (!empty($string)) ? strip_tags(trim($string)) : null;
}
function sanitize($string, $pattern, $length) {
if (strlen($string) <= $length) {
if (preg_match($pattern, $string)) {
return true;
}
}
return false;
}
function get_post($value) {
echo (@!empty($_POST[$value])) ? trim($_POST[$value]) : null;
}
?>
and HTML
Code:
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" class="form" name="form" >
<?php
if (!empty($response)) {
echo '<p class="error">' . $response . '</p>' . "\n";
}
?>
<label for="firstname">Your first name *</label>
<input type="text" name="firstname" id="firstname" value="<?php get_post('firstname'); ?>" />
<label for="email">Your Email Address *</label>
<input type="text" name="email" id="email" value="<?php get_post('email'); ?>" />
<label for="contact">Contact number *</label>
<input type="text" name="contact" id="contact" value="<?php get_post('contact'); ?>" />
<label for="organization">Organization *</label>
<input type="text" name="organization" id="organization" value="<?php get_post('organization'); ?>" />
<label for="website">Website *</label>
<input type="text" name="website" id="website" value="<?php get_post('website'); ?>" />
<input type="image" name="submit" id="submit" alt="submit" src="images/submit-btn.png" width="280" height="60" class="submit-btn" />
</form>
It just refreshes the page in FF and IE but redirects to the thank you page and sends me an email in chrome