I have an html form that sends user entered data to PHP.
I am unsure why my code is not working. I am using POST to retrieve the data. I am able to use a javascript alert window to show the form data. But something is wrong in my code that is preventing my email from being received, if even sent.
Here is my html form:
<form action="contact.php" method="POST" id="messageForm" name="messageForm">
<label>Name</label>
<input class="form-control" id="name" name="name" type="text" placeholder="Enter Full Name" />
<label>Phone</label>
<input class="form-control" id="phone" name="phone" type="text" placeholder="Enter Phone Number" />
<label>Email</label>
<input class="form-control" id="email" name="email" type="text" placeholder="Enter Valid Email" />
<label>Interest</label>
<select class="form-control" id="interest" name="interest" value="interest">
<option value="" disabled selected>Make selection</option>
<option value="one">one</option>
<option value="two">two</option>
<option value="three">three</option>
</select>
<label>Comments</label>
<textarea class="form-control" id="comment" name="comment" style="resize: none;" rows="10"></textarea>
<input class="btn btn-danger" type="submit" id="submitMessage" name="submitMessage" value="Submit" />
</form>
Inside the form, I have my PHP looking like this:
<?php
if(isset($_POST['submitMessage']))
{
$name = htmlspecialchars($_POST['name']);
$phone = htmlspecialchars($_POST['phone']);
$email = htmlspecialchars($_POST['email']);
$interest = htmlspecialchars($_POST['interest']);
$comment = htmlspecialchars($_POST['comment']);
$cc = 'myEmail@yahoo.com';
$to = 'myOtherEmail@gmail.com';
$subject = 'Web Message';
$headers = "From: ".$email."" . "\r\n";
$headers .= "CC: " . $cc . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$message = "You have received a message<br /><br />";
$message .= "Greetings<br /><br />";
$message .= '<html><body>';
$message .= '<table>';
$message .= '<tr><th>Name</th><th>Phone</th><th>Email</th><th>Interest</th><th>Comment</th></tr>';
$message .= '<tr><td>'.$name.'</td><td>'.$phone.'</td><td>'.$email.'</td><td>'.$interest.'</td><td>'.$comment.'</td></tr>';
$message .= '</table></body></html>';
$message .= 'Thank you';
@mail($to, $subject, $message, $headers);
echo ("<script language='javascript'>
window.alert('Thank you, ".$name.". Your message has been sent.')
window.location.href=''
</script>");
}
?>
I am not receiving an on-page error. It appears the email is being sent, but no email is being received.
Please help.
Thank you.