0

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!

Sirale_92
  • 1
  • 2
  • Te 500 error is coming from the server, so you're connected but you have. syntax error somewhere. – Jay Blanchard Apr 13 '20 at 18:27
  • Dear @JayBlanchard , I've checked many times, and also used PHP checker for syntax errors, but the Php code does not have them, apparently. So unluckily, the guide doesn't help. Thank you very much. – Sirale_92 Apr 14 '20 at 21:04
  • You're probably getting syntax errors in the values you're passing to PHP. Perhaps not all of your variables are populated properly. But it is a sure thing there is something wrong with your script, the server doesn't hand out 500 errors just for nothing. Do you have pages that work? – Jay Blanchard Apr 14 '20 at 21:18
  • Thank you so much for your answers. That's for sure, it's a code error of mine that I'm not smart enough to find. Probably variables. All the HTML website is working, the only PHP file is the one associated with the contact form, and the only that's not working when I try to send myseld emails. – Sirale_92 Apr 14 '20 at 22:25

0 Answers0