I am trying to create a form that is using AJax to submit the form instead of doing a page reload, but every code i've tried does not send anything to the email i specified.
Here is my code:
compform.php
<?php
if(isset($_POST['submit'])){
$to = "[email protected]";// this is your Email address
$from = $_POST['mail']; // this is the sender's Email address
$name = $_POST['name'];
$mail = $_POST['mail'];
$subject = "Quadflow Content Writing Service Request";
$message = 'Hi Uriel, you have a new content writing request email from Quadflow App';
$message .= $name;
$headers = "From:" . $from;
mail($to,$subject, $message,$headers);
header("Location: " . $_SERVER['REQUEST_URI'] . "?mail=sent");
exit();
}
?>
Jquery (Ajax):
$('.compform').submit(function(event) {
var formData = {
'name' : $('input[name=name]').val(),
'mail' : $('input[name=mail]').val()
};
$.ajax({
type : 'POST', // define the type of HTTP verb we want to use (POST for our form)
url : 'compform.php', // the url where we want to POST
data : formData, // our data object
dataType : 'json', // what type of data do we expect back from the server
encode : true
})
.done(function(data) {
console.log(data);
});
event.preventDefault();
$('.compform button').html('Success!');
});
Html
<form class="compform" action="compform.php" method="post">
<input placeholder="Name" name="name">
<input placeholder="Email" name="mail">
<input placeholder="Type of Website" name="type">
<select name="selectoptions">
<option value="choose" disabled selected>Choose a Style</option>
<option value="modern">Modern</option>
<option value="serious">Serious</option>
<option value="light">Light Tone</option>
<option value="creative">Creative</option>
</select>
<textarea placeholder="Additional Information" name="info"></textarea>
<button type="submit" name="submit">Submit</button>
</form>