Heys guys, I've been playing around with this ajax call for a few days now. I had it posting an email with no variables earlier, but now I can't get the call to submit the form with a variable or without. Here is my code:
<form id="contactform" method="post" action="submit.php">
<input type="text" placeholder="Name" name="username" id="username" />
<input type="email" placeholder="Your Email Address" name="email" id="email" />
<input type="button" id="submit" class="submit" value="submit"></a>
</form>
AJAX:
<script type="text/javascript">
$("#submit").click(function(event){
var data = $('#contactform').serialize();
event.preventDefault();
$.ajax({
url: "submit.php",
type: "POST",
data: data,
success: function() {
alert("Success!");
}
});
return false;
});
});
</script>
submit.php:
<?php
$from = "info@email.com";
$usersubject = "Thank You!";
$usermessage = "Thank you for signing up!";
$to = $_REQUEST['email'];
$subject = "Form Info";
?>
<?php
$name = $_REQUEST['username'];
$email = $_REQUEST['email'];
$message = "Name: $name
Email: $email";
$headers = "From:" . $from;
//mail($to,$subject,$message,$headers);
mail($email,$usersubject,$usermessage,$headers);
echo 'Success';
?>
submit.php works when you access it directly with the variable (www.website.com/submit.php?username=Dave&email=davesemail@mail.com). Is there an error somewhere here that I'm missing? Any help is appreciated!