-1

I don't get any errors. I used to get Undefined index/variable errors before but I fixed that with isset(). I fill the form out and hit submit but nothing shows up but a blank white screen.

This is my PHP code:

    <?php 


    $name = isset($_POST['name']) ? $_POST['name'] : '';
    $email = isset($_POST['email']) ? $_POST['email'] : '';
    $message = isset($_POST['message']) ? $_POST['message'] : '';   
    $from = 'From: ContactForm'; 
    $to = 'email@email.com'; 
    $subject = 'Hello';
    $verify = $_POST['verify'];

    $body = "From: $name\n E-Mail: $email\n Message:\n $message";

    if (isset($_POST["submit"]) && $verify == '4') {
        if (mail ($name, $email, $message)) { 
            echo '<p>Your message has been sent!</p>';
         } 

        else { 
            echo '<p>Something went wrong, go back and try again!</p>'; 
         }
      }    
        else if (isset($_POST["submit"]) && verify != '4') {
            echo '<p>You answered the anti-spam question incorrectly!</p>';
         }

?>

This is my HTML code:

          <form action="pages/mail.php" method="post">

                        <div class="col-md-12">
                            <div class="form-group">
                                <label for="name" class="sr-only">Name</label>
                                <input placeholder="Name" id="name" type="text" class="form-control input-lg">
                            </div>  
                        </div>

                        <div class="col-md-12">
                            <div class="form-group">
                                <label for="email" class="sr-only">Email</label>
                                <input placeholder="Email" id="email" type="text" class="form-control input-lg">
                            </div>  
                        </div>

                        <div class="col-md-12">
                            <div class="form-group">
                                <label for="message" class="sr-only">Message</label>
                                <textarea placeholder="Message" id="message" class="form-control input-lg" rows="3"></textarea>
                            </div>  
                        </div>

                        <div class="col-md-12">
                            <div class="form-group">
                                <input id="submit" type="submit" class="btn btn-primary btn-lg " value="Send">
                            </div>  
                        </div>

                        <div class="col-md-12">
                            <div class="form-group">
                            <label for="verify" class="sr-only">Verify</label>
                            <input name="verify" placeholder="What is 2+2" class="form-control input-lg">
                            </div>
                        </div>
                    </form> 
Kris.Du
  • 3
  • 3

3 Answers3

1

Your input have no name attribute, therefore there is no "submit" key there and none of your conditions which have an echo is called (white page without error).

Lucero
  • 59,176
  • 9
  • 122
  • 152
0

Turn on showing the PHP errors and warnings during development, so you see exactly what went wrong.

The mail function call is missing the recipient address ($to), so it will hardly send the email anyways.

But the script execution breaks because you have an extra } just before the else if. If you had all error messages enabled, you would get something like Fatal error: syntax error: Unexpected T_ELSE at line xy.

Rápli András
  • 3,869
  • 1
  • 35
  • 55
  • My email is on my php script. I just left it out the question for privacy. Its more of a placeholder: email@email.com – Kris.Du Oct 24 '16 at 00:11
0

White screen usually means internal or syntax error

PHP, unlike JavaScript doesn't let you get away with missing semicolons or curly braces. First, make sure your code is syntactically valid and without typos before going on to fixing the logic. Errors can be displayed in most cases by including the following lines at the top of your PHP file:

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

After you find and fix those errors, here is why the form itself doesn't work:

Inputs need to be referenced by their name attribute

While it is good practice to set the IDs of input elements, your PHP script doesn't know about them. You need to give your input fields a name attribute with the same value as you expect on the server side.

This means if you have the following HTML form and input

<form action="whatever.php" method="POST">
  <input type="text" name="my_text_input">
</form>

You can access it on the server side in whatever.php like so

<?php

$myTextBoxValue = $_POST['my_text_input'];

?>

Hope this helps!

ppajer
  • 3,045
  • 1
  • 15
  • 22