Hey guys.
I've been having some frustrating issues with my php + contact form recently. I'm quite the noob when it comes to php in general and have only really worked with contact stuff in the past.
I have my contact form calling a php send mail file in a php folder on my server. No idea why, but im not even getting validation. I click send, to no avail.
I have attached the code for your perusal. I appreciate any help in advance!! Thank you.
Form:
<form id="contact-form" class="fixed" action="javascript:void(0);">
<fieldset>
<p id="formstatus"></p>
<p>
<label for="name">Your name: <span class="required">*</span></label><br />
<input class="text" type="text" id="name" name="name" value="" />
</p>
<p>
<label for="email">Your Email Address: <span class="required">*</span></label><br />
<input class="text" type="text" id="email" name="email" value="" />
</p>
<p>
<label for="subject">Subject: <span class="required">*</span></label><br />
<input class="text" type="text" id="subject" name="subject" value="" />
</p>
<p>
<label for="message">Message: </label><br />
<textarea id="message" name="message" rows="3" cols="25"></textarea>
</p>
<p>
<input type="submit" name="submit" value="Send!" />
</p>
</fieldset>
</form>
PHP file (send.php):
I've hidden the send to email address for obvious reasons.
<?php[/font][/color]
[color=#282828][font=helvetica, arial, sans-serif]/////////// Add your own email below //////////////// [/font][/color]
[color=#282828][font=helvetica, arial, sans-serif]define("WEBMASTER_EMAIL", 'blah@blah.com');[/font][/color]
[color=#282828][font=helvetica, arial, sans-serif]error_reporting (E_ALL ^ E_NOTICE);[/font][/color]
[color=#282828][font=helvetica, arial, sans-serif]//////////////////////////////////////////////////////[/font][/color]
[color=#282828][font=helvetica, arial, sans-serif]function ValidateEmail($email)
{
$regex = '/([a-z0-9_.-]+)'. # name
'@'. # at
'([a-z0-9.-]+){2,255}'. # domain & possibly subdomains
'.'. # period
'([a-z]+){2,10}/i'; # domain extension
if($email == '')
return false;
else
$eregi = preg_replace($regex, '', $email);
return empty($eregi) ? true : false;
}[/font][/color]
[color=#282828][font=helvetica, arial, sans-serif]//////////////////////////////////////////////////////[/font][/color]
[color=#282828][font=helvetica, arial, sans-serif]$post = (!empty($_POST)) ? true : false;[/font][/color]
[color=#282828][font=helvetica, arial, sans-serif]if($post)
{
$name = stripslashes($_POST['name']);
$email = trim($_POST['email']);
$subject = trim($_POST['subject']);
$message = stripslashes($_POST['message']);[/font][/color]
[color=#282828][font=helvetica, arial, sans-serif] $error = '';[/font][/color]
[color=#282828][font=helvetica, arial, sans-serif] // Check name
if(!$name)
$error .= 'Name required! ';[/font][/color]
[color=#282828][font=helvetica, arial, sans-serif] // Check email
if(!$email)
$error .= 'E-mail required! ';[/font][/color]
[color=#282828][font=helvetica, arial, sans-serif] if($email && !ValidateEmail($email))
$error .= 'E-mail address is not valid! ';[/font][/color]
[color=#282828][font=helvetica, arial, sans-serif] // Check message
if(!$message)
$error .= "Please enter your message!";[/font][/color]
[color=#282828][font=helvetica, arial, sans-serif] if(!$error)
{
$mail = mail(WEBMASTER_EMAIL, $subject, $message,
"From: ".$name." <".$email.">\r\n"
."Reply-To: ".$email."\r\n"
."X-Mailer: PHP/" . phpversion());
if($mail)
echo 'OK';
}
else
echo '<div class="errormsg">'.$error.'</div>';
}[/font][/color]
[color=#282828][font=helvetica, arial, sans-serif]?>
and javascript:
// -------------------------------------------------------------------------------------------------------
// Form Validation script - used by the Contact Form script
// -------------------------------------------------------------------------------------------------------
function validateMyAjaxInputs() {
$.validity.start();
// Validator methods go here:
$("#name").require();
$("#email").require().match("email");
$("#subject").require();
// End the validation session:
var result = $.validity.end();
return result.valid;
}
// -------------------------------------------------------------------------------------------------------
// ClearForm
// -------------------------------------------------------------------------------------------------------
$.fn.clearForm = function() {
return this.each(function() {
var type = this.type, tag = this.tagName.toLowerCase();
if (tag == 'form')
return $(':input',this).clearForm();
if (type == 'text' || type == 'password' || tag == 'textarea')
this.value = '';
else if (type == 'checkbox' || type == 'radio')
this.checked = false;
else if (tag == 'select')
this.selectedIndex = -1;
});
};
$(document).ready(function(){
//////////////////////////////////////////////////////////////////////////////////////////////////////////////