Thanks for taking the time to see guys. I am creating a nice basic AJAX contact form using jQuery. The email is sent, but after opening the email there is no POST data, so I just get the lines defined in the PHP script. On my email client over the phone, the contents of the letter literally say "undefined". I tried to add different types of header data to no avail, as well as a number of options for the PHP mail () function.
I am more than ready to make an easier decision for a simple form of AJAX, therefore, 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>
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; }); });
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@gmail.com ", "This is an email from:" .$email, $message); } ?>
Jason sears
source share