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ść: </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ś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łędny podpis.';
}
if (!mail_x.match(/^([a-z0-9._-]+@[a-z0-9._-]+\\.[a-z]{2,4}$)/i)) {
valid_x += '<br />Błędny Email.';
}
if (subject_x.length<1) {
valid_x += '<br />Błędny tytuł.';
}
if (text_x.length<1) {
valid_x += '<br />Błędna treść.';
}
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łanie wiadomoś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ł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";
}
?>