I have a ajax driven contact form on my site linked here
I'm having 2 issues with it.
First being, I'm not sure why the error checking for the name field isn't working, my code seems to be correct (logic wise) but it still doesn't fire off.
Second, I have no idea how I can add more fields into the form. For example, adding Company Name
for users to enter and send in the email. I tried adding the values like $company
and the following code but I get this error that I can't pass that many variables into $mail
:/ Trying to learn via trial and error, any help is appreciated!
here is my code:
<?php
include dirname(dirname(__FILE__)).'/mail.php';
error_reporting (E_ALL ^ E_NOTICE);
$post = (!empty($_POST)) ? true : false;
if($post)
{
include 'email_validation.php';
$name = stripslashes($_POST['name']);
$email = trim($_POST['email']);
$subject = 'Contact Form: Inquiry from corporate website';
$message = stripslashes($_POST['message']);
$error = '';
// Check name
if(!$name || strlen($name) < 1)
{
$error .= 'Please enter your name.<br />';
}
// Check email
if(!$email)
{
$error .= 'Please enter an e-mail address.<br />';
}
if($email && !ValidateEmail($email))
{
$error .= 'Please enter a valid e-mail address.<br />';
}
// Check message (length)
if(!$message || strlen($message) < 10)
{
$error .= "Please enter your message. It should have at least 10 characters.<br />";
}
if(!$error)
{
$mail = mail(CONTACT_FORM, $subject, $message,
"From: ".$name." <".$email.">\r\n"
."Reply-To: ".$email."\r\n"
."X-Mailer: PHP/" . phpversion());
if($mail)
{
echo 'OK';
}
}
else
{
echo '<div class="notification_error">'.$error.'</div>';
}
}
?>
Here is my html form connecting to the php:
<form id="contactForm" action="">
<input type="text" name="name" value="Name *" title="Name *" />
<input type="text" name="email" value="Email *" title="Email *" />
<textarea name="message" id="message" title="Message *">Message *</textarea>
<div class="clear"></div>
<input type="reset" class="btn btn_clear" value="Clear form" />
<input type="submit" class="btn btn_blue btn_send" value="Send message!" />
<div class="clear"></div>
</form>