I've got a little problem when I try to use my contact form on my website HTML page. It is a simple landing page with a form in the lower end, but when I try to send the message from the form, the page start to buffer and a blank page with an error appears. The error is "HTTP ERROR 500", so basically can't connect with the server. Can someone help me?
Here's the HTML code:
<form class="contact-form form" method="POST" action="contact.php">
<div class="contact-form-content">
<div class="row">
<div class="col-lg-6 col-md-6 col-sm-6">
<div data-100p-top="transform[swing]:translateX(-25px);opacity[swing]:0"
data-75p-top="transform[swing]:translateX(0);opacity[swing]:1">
<div class="form-group has-feedback">
<input type="text" class="form-control"
placeholder="Enter name" name="cf_name">
<span class="glyphicon glyphicon-user form-control-feedback"></span>
</div>
<div class="form-group has-feedback">
<input type="email" class="form-control"
placeholder="Enter email" name="cf_email">
<span class="glyphicon glyphicon-envelope form-control-feedback"></span>
</div>
</div>
</div>
<div class="col-lg-6 col-md-6 col-sm-6">
<div data-100p-top="transform[swing]:translateX(25px);opacity[swing]:0"
data-75p-top="transform[swing]:translateX(0);opacity[swing]:1">
<div class="form-group">
<textarea class="form-control" rows="3" cols="40"
placeholder="Your Message" name="cf_message">
</textarea>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-6 col-md-offset-6">
<div data-100p-top="transform[swing]:translateX(25px);opacity[swing]:0"
data-75p-top="transform[swing]:translateX(0);opacity[swing]:1">
<button type="submit" class="btn btn-transparent btn-lg btn-block"
value="Send">
<span class="icon icon-basic-mail"></span> Send
</button>
</div>
</div>
</div>
</div>
</form>
And here's the "contact.php" code:
<?php
$field_name = $_POST['cf_name'];
$field_email = test_input($_POST['cf_email']);
$field_message = $_POST['cf_message'];
$mail_to = 'example.example@gmail.com';
$subject = 'Message from website '.$field_name;
$body_message = 'From: '.$field_name."\n";
$body_message .= 'E-mail: '.$field_email."\n";
$body_message .= 'Message: '.$field_message;
$headers = 'From: '.$field_email."\r\n";
$headers .= 'Reply-To: '.$field_email."\r\n";
$mail_status = mail($mail_to, $subject, $body_message, $headers);
if (!filter_var($field_email,FILTER_VALIDATE_EMAIL)) { ?>
<script language="javascript" type="text/javascript">
alert('Invalid email format. Try again or send an email to example.example@gmail.com');
window.location = 'index.html';
</script>
<?php
}
else
{
if ($mail_status) { ?>
<script language="javascript" type="text/javascript">
alert('Thank you for the message. I will contact you shortly.');
window.location = 'index.html';
</script>
<?php
}
else { ?>
<script language="javascript" type="text/javascript">
alert('Message failed. Please, send an email to example.example@gmail.com');
window.location = 'index.html';
</script>
<?php
}}
?>
Thank you sooo much for the help!