This question already has an answer here:
I have created a simple html form to send an email using php. Currently whenever I try to send the info I just get redirected to my process.php page with and browser error (myserver.com unable to handle this request).
I have already tried sending a test email by making my php page just the mail() function and it does indeed work so it has to do with my code somewhere. I'm sure it's something simple so here is my code.
HTML (contact.html):
<!-- Contact form -->
<form id="form" action="process.php" method="post">
<div>
<label for='name'><span class='required'></span></label>
<input id="Field1" type='text' name='name' placeholder='Type your Email Here' required/>
</div>
<div>
<label for='message'><span class='required'></span></label>
<textarea id="Field2" name='message' placeholder="Type a Message for us Here" required></textarea>
</div>
<div>
<button type='submit'>SEND MESSAGE</button>
</div>
</form>
PHP (process.php):
<?php
//if "email" variable is filled out, send email
if(isset($_POST['name']) && isset($_POST['message'])) {
//Email information
$admin_email = "test@mydomain.com";
$email = $_POST['name'];
$subject = "Email from contact form";
$comment = $_POST['message'];
//send email
if(mail($admin_email, $subject, $comment, "From:" . $email)) {
echo '<p>Success</p>';
header('Location: contact.html');
} else {
echo '<p>Error sending message</p>';
}
} else {
echo '<p>Please fully fill out the form</p>';
}
?>
</div>