73
rated 0 times
[
78]
[
5]
/ answers: 1 / hits: 114109
/ 11 Years ago, fri, march 8, 2013, 12:00:00
Thanks for taking the time to look, guys. I'm creating a pretty basic AJAX contact form using jQuery. The email sends, but upon opening the email there is no POST data, so I just get the strings I defined in the PHP script. On my phone's email client, the content of the email literally says 'undefined'. I've tried adding different types of header data to no avail, and a number of variations on the PHP mail() function.
I am more than willing to adopt an easier solution for a simple AJAX form, so thanks in advance for any new approaches.
Here is the form:
<section id=left>
<label for=form_name>Name</label>
<input name=form_name id=form_name type=text >
<label for=form_email>Email</label>
<input name=form_email id=form_email type=email >
</section>
<section id=right>
<label for=form_msg>Message</label>
<textarea name=form_msg id=form_msg></textarea>
<input id=submit class=button name=submit type=submit value=Send>
</section>
</form>
The jQuery AJAX:
$(function() {
$(#contact .button).click(function() {
var name = $(#form_name).val();
var email = $(#form_email).val();
var text = $(#msg_text).val();
var dataString = 'name='+ name + '&email=' + email + '&text=' + text;
$.ajax({
type: POST,
url: email.php,
data: dataString,
success: function(){
$('.success').fadeIn(1000);
}
});
return false;
});
});
The PHP script (external file 'email.php'):
<?php
if($_POST){
$name = $_POST['form_name'];
$email = $_POST['form_email'];
$message = $_POST['form_msg'];
//send email
mail([email protected], This is an email from: .$email, $message);
}
?>
More From » php