Hi, i have a php contact form that is managed with ajax, but i cant get it to work properlly.
Here is the contact form on my demo site:
http://www.bcpdemo.8...om/contact.html
I receive the name and the message but not the email, instead of email i get a subject filled with the name.
Thanks alot for the help guys.
here is how it looks in my yahoo inbox:
here is how it looks when i enter the message:
and here is the php script:
1.config_php
<?php
define("WEBMASTER_EMAIL", '
[email protected]');
?>
2.contact.php
include 'config.php';
error_reporting(E_ALL ^ E_NOTICE);
$post = (!empty($_POST)) ? true : false;
if ($post) {
include 'functions.php';
$name = stripslashes($_POST['name']);
$email = trim($_POST['email']);
$message = stripslashes($_POST['message']);
$error = '';
// Check name
if (!$name) {
$error .= 'Please enter your name.<br />';
}
// Check email
if (!$email) {
$error .= 'Please enter your e-mail adress.<br />';
}
if ($email && !ValidateEmail($email)) {
$error .= 'Invalid e-mail adress !<br />';
}
// Check message (length)
if (!$message || strlen($message) < 1) {
$error .= "Please enter your message.";
}
if (!$error) {
$subject = "your subject";
$messageform = stripslashes($_POST['message']);
$message = "Subject: " . $subject . "\n\nFrom: " . $name . "\n\nMessage: " . $messageform;
$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="notification_error">' . $error . '</div>';
}
}
?>
3.functions.php
<?php
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;
}
?>
Thanks alot for your help guys.