The code "works" as in it gives the correct message when fields are filled out, but it does not send the email. Could this be something I need to set on go-daddy's end? or is the code wrong. I am new to all of this and still learning how everything works.
I am building a site for my wife and am very new, I got this info from a great video on you tube because the classes I am taking have not gotten this far. I am still on CSS and Bootstrap.
I put the php on a page in the root folder, I have double checked the file name. main_parser.php
<?php
if( isset($_POST['n']) && isset($_POST['e']) && isset($_POST['p']) ){
$n = $_POST['n'];
$e = $_POST['e'];
$p = $_POST['p'];
$to = "redacted@gmail.com";
$from = $e;
$subject = 'Contact Form Message';
$message = '<b>Name:</b> '.$n.' <br><b>Email:</b> '.$e.' <p>'.$p.'</p>';
$headers = "From: $from\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\n";
if( mail($to, $subject, $message, $headers) ){
echo "success";
} else {
echo "The server failed to send the message. Please try again later.";
}
}
?>
--------------------------------------------
<script>
function _(id){ return document.getElementById(id); }
function submitForm(){
_("main-submit").disabled = true;
_("status").innerHTML = 'please wait ...';
var formdata = new FormData();
formdata.append( "n", _("n").value );
formdata.append( "e", _("e").value );
formdata.append( "p", _("p").value );
var ajax = new XMLHttpRequest();
ajax.open( "POST", "main_parser.php" );
ajax.onreadystatechange = function() {
if(ajax.readyState == 4 && ajax.status == 200) {
if(ajax.responseText == "success"){
_("main-form").innerHTML = '<h2>Thanks '+_("n").value+', your message has been sent.</h2>';
} else {
_("status").innerHTML = ajax.responseText;
_("main-submit").disabled = false;
}
}
}
ajax.send( formdata );
}
</script>
--------------------------------------------------------------------
<form id="main-form" onsubmit="submitForm(); return false;">
<div class="col-lg-4 space label-adj">
<label for="" class="form-label">JOIN THE CAMPAIGN TODAY!</label>
</div>
<div class="form-row">
<div class="col-lg-4 space">
<input id="n" type="text" class="form-control" placeholder="Name" required>
</div>
</div>
<div class="form-row">
<div class="col-lg-4 space">
<input id="e" type="email" class="form-control" placeholder="E-Mail Address" required>
</div>
</div>
<div class="form-row">
<div class="col-lg-4 space">
<input id="p" type="Phone" class="form-control" placeholder="Phone Number" required>
</div>
</div>
<div class="form-row space">
<div class="col-lg-4">
<button id="main-submit" type="submit" class="btn btn-dark btn-block submit-b"><span id="status"></span>Submit</button>
</div>
</div>
</form>