Contact php not working

Hi guys I would like to ask my php setting I don’t know if my php goes wrong or my javascript…in my inbox only show “name” and “email” success but the message only show Message: message… regardless what i type in my message form…

here’s my form :
<form method=“post” id=“ajax_form” action=“”>
<p class=“input-field”><label><input class=“text_input clear” type=“text” name=“name” id=“name” value=“Name” /></label></p>
<p class=“input-field”><label><input class=“text_input clear” type=“text” name=“email” id=“email” value=“Email” /></label></p>
<p class=“input-field”><label><input class=“text_input clear” type=“text” name=“cheque” id=“cheque” value=“Are you a robot? If you aren’t - Type ‘no’ in lowercase” /></label></p>
<p class=“text-area-wrap”><label><textarea name=“message” cols=“10” rows=“5” class=“text_area clear” id=“message”>Message</textarea></label></p>
<div class=“sb-ct”><input type=“button” class=“submit” /></div>
</form>

here’s my jquery form :

$(document).ready(function(){

$('form#ajax_form .submit').click(function(){

	$('#ajax_form .error').hide();	//if error visibile, hide on new click
	
	var name = $('input#name').val();
	if (name == "" || name == " " || name == "Name") {
	    $('input#name').focus().before('&lt;div class="error"&gt;You have a Name?&lt;/div&gt;');
	    return false;
	}
	
	var email_test = /^([a-z0-9_\\.-]+)@([\\da-z\\.-]+)\\.([a-z\\.]{2,6})$/;
	var email = $('input#email').val();
	if (email == "" || email == " ") {
	   $('input#email').focus().before('&lt;div class="error"&gt;Psst. You missed one.&lt;/div&gt;');
	   return false;
	} else if (!email_test.test(email)) {
	   $('input#email').select().before('&lt;div class="error"&gt;Please Check your Email again...&lt;/div&gt;');
	   return false;
	}
	
var cVal = $('input#cheque').val();
	if (cVal != 'no') {
	    $('input#cheque').focus().before('&lt;div class="error"&gt;Type \\'no\\' if you\\'re not robots&lt;/div&gt;');
	    return false;
	}
	
	var message = $('#message').val();
	if (message == "" || message == " " || message == "Message") {
	    $('#message').focus().fadeIn('slow').before('&lt;div class="error"&gt;Please do not leave me blank message!&lt;/div&gt;');
	    return false;
	}
	
	var data_string = $('form#ajax_form').serialize();

	$.ajax({
	    type:       "POST",
	    url:        "contact.php",
	    data:       data_string,
	    success:    function() {

	$('form#ajax_form').slideUp('fast').before('&lt;div id="success"&gt;&lt;/div&gt;');
	$('#success').html('&lt;p&gt;Thanks, I\\'ll be in touch with you soon :)&lt;/p&gt;').slideDown(7000);

	    }//end success function


	}) //end ajax call

	return false;


}) //end click function

var current_data = new Array();

$('.clear').each(function(i){
	$(this).removeClass('clear').addClass('clear'+i);
	current_data.push($(this).val());

	$(this).focus(function(){
		if($(this).val() == current_data[i]) {
			$(this).val('');
		}
	});
	$(this).blur(function(){
		var stored_data = current_data[i];
		if($(this).val()==''){
			$(this).val(stored_data);
		}
	})
});

})

and Here’s my PHP:
<?php

if(!$_POST) exit;

$email = $_POST[‘email’];

//$error = preg_match(‘/\b[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/i’, $POST[‘email’]) ? ‘’ : ‘INVALID EMAIL ADDRESS’;
if(!eregi("[1]+([
\\.-][a-z0-9]+)" .“@”."([a-z0-9]+([\.-][a-z0-9]+))+“.”\\.[a-z]{2,}“.”$",$email )){
$error.=“Invalid email address entered”;
$errors=1;
}
if($errors==1) echo $error;
else{
$values = array (‘name’,‘email’,‘message’);
$required = array(‘name’,‘email’,‘message’);

$your_email = "kriscahya@redka3d.com";
$email_subject = "New Message: ".$_POST['subject'];
$email_content = "new message:\

";

foreach($values as $key =&gt; $value){
  if(in_array($value,$required)){
	if ($key != 'subject' && $key != 'company') {
	  if( empty($_POST[$value]) ) { echo 'PLEASE FILL IN REQUIRED FIELDS'; exit; }
	}
	$email_content .= $value.': '.$_POST[$value]."\

";
}
}

if(@mail($your_email,$email_subject,$email_content)) {
	echo 'Message sent!'; 
} else {
	echo 'ERROR!';
}

}
?>

Appreciate any help thanks guys


  1. a-z0-9 ↩︎

Its finally working thanks for the info!

Try var_dumping $_POST to see what gets posted to the server.

Also, please use [ code ] and [ php ] tags to make your code readable on the forums :wink: