[AJAX] The problem with sending emails (variable post)

I have a problem that the script sends me an email but no data from the form fields. So the problem is with the sending POST variable. What am I doing wrong?

I have two files:
index.php


<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>

        <form id="formail" action="" method="post">

          <?php echo $blad_wysylania; ?>

          <div id="wynik_wysylania"></div>

          <div><label for="e_nazwa">Podpis: </label><input id="e_nazwa" type="text" name="e_nazwa" /></div>

          <div><label for="e_mail">Twój e-mail: </label><input id="e_mail" type="text" name="e_mail" /></div>

          <div><label for="e_temat">Temat: </label><input id="e_temat" type="text" name="e_temat" /></div>

          <div><label for="e_tresc">Tre&#347;&#263;: </label><textarea id="e_tresc" name="e_tresc" rows="10" cols="30"></textarea></div>

          <div><input type="submit" id="e_wyslij" name="e_wyslij" value="Wy&#347;lij e-mail" /></div>

      </form>			



			</div><!-- #content -->

		</div><!-- #container -->



<script type="text/javascript">





$("#e_wyslij").click(function(){

	var valid_x = '';

	var name_x = $("#e_nazwa").val();

	var mail_x = $("#e_mail").val();

	var subject_x = $("#e_temat").val();

	var text_x = $("#e_tresc").val();

	if (name_x.length<1) {

		valid_x += '<br />B&#322;&#281;dny podpis.';

	}

	if (!mail_x.match(/^([a-z0-9._-]+@[a-z0-9._-]+\\.[a-z]{2,4}$)/i)) {

		valid_x += '<br />B&#322;&#281;dny Email.';

	}

	if (subject_x.length<1) {

		valid_x += '<br />B&#322;&#281;dny tytu&#322;.';

	}

	if (text_x.length<1) {

		valid_x += '<br />B&#322;&#281;dna tre&#347;&#263;.';

	}

	if (valid_x!='') {

		$("#wynik_wysylania").fadeIn("slow");

		$("#wynik_wysylania").html("Error:"+valid_x);

	}

	else {

		var datastr ='name_x=' + name_x + '&mail_x=' + mail_x + '&subject_x=' + subject_x + '&text_x=' + text_x;

		//var datastr = { 'name_x': name_x, 'mail_x': mail_x, 'subject_x': subject_x, 'text_x': text_x }

		$("#wynik_wysylania").css("display", "inline-block");

		$("#wynik_wysylania").html("Wysy&#322;anie wiadomo&#347;ci .... ");

		$("#wynik_wysylania").fadeIn("slow");

		setTimeout("send('" + datastr + "')",1000);

	}

	return false;

});



function send(datastr){

	$.ajax({	

		type: "POST",

		url: "x_mail.php",

		data: datastr,

		cache: false,

		success: function(html){

		$("#wynik_wysylania").fadeIn("slow");

		$("#wynik_wysylania").html(html);

    //$("#wynik_wysylania").html("Wys&#322;ane!");

		//setTimeout('$("#wynik_wysylania").fadeOut("slow")',2000);

		setTimeout('$("#wynik_wysylania").fadeOut("slow")',1000);

	}

	});

}

</script>


x_mail.php:


<?php
 $mail_x = $_GET['e_mail'];

 $name_x = $_GET['e_nazwa'];

 $subject_x = $_GET['e_temat'];

 $text_x = $_GET['e_tresc'];



$to_x = "zxc@tlen.pl";

 $message_x ="You received  a mail from ".$mail_x;

 $message_x .="Text of the message : ".$text_x;



if(mail($to_x, $subject_x,$message_x)){

 echo "mail successful send";

 }

 else{

 echo "theres some errors to send the mail, verify your server options";

 }





 ?>

Your PHP code is currently using _GET when your Ajax request is using _POST, simply change all your $_GET’s to $_POST’s and the issue will be fixed.

Yes, I forgot, before I changed the GET (in ajax too).Fixed the POST and still not working.

The other thing I just noticed is your array keys aren’t the same as whats in your PHP. E.g.

$mail_x = $_GET['e_mail']; // In your JavaScript this is called mail_x not e_mail

THX VERY MUTCH!