-2

I have never used PHP before so apologies if this is totally ridiculous. I am struggling to get my contact form to work. Here is my HTML:

<form method="post" action="contact-form.php">

            <div class="input-third">

                <label for="name">Name: <small>*</small></label>
                <br>
                <input class="input"  type="text" name="name" placeholder="John Smith" />

            </div>

            <div class="input-third">

                <label for="email">Email: <small>*</small></label>
                <br>
                <input class="input"  type="text" name="email" placeholder="mail@example.com" />

            </div>

            <div class="input-third">

                <label for="phone">Phone:</label>
                <br>
                <input class="input"  type="text" name="phone" placeholder="Type Here" />

            </div>

            <br>
            <br>

            <label for="message">Message: <small>*</small></label> <br>
            <textarea class="message" name="message" placeholder="Write a message to us"></textarea>

            <br>

            <label>*What is 2+2? (Anti-spam)</label>
            <input name="human" placeholder="Type Here">

            <input class="submit" type="submit" value="Send" name="submit">

        </form>

And Here is the PHP:

<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$message = $_POST['message'];
$from = 'From: IPS Facilities Contact Form';
$to = 'noah.searle@gmail.com';
$subject = 'Enquiry';
$human = $_POST['human'];

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

if ($_POST['submit'] && $human == '4') {
    if (mail ($to, $subject, $body, $from)) { 
        echo '<p>Your message has been sent!</p>';
    } else { 
        echo '<p>Something went wrong, go back and try again!</p>'; 
    }
} else if ($_POST['submit'] && $human != '4') {
    echo '<p>You answered the anti-spam question incorrectly!</p>';
}
?>

When I hit submit, it displays the message has been sent but I have not received anything! I'm sure it is something silly but I would appreciate some input!

Noah
  • 1
  • 2

4 Answers4

1

Think this may have already been answered in the comments or other answers, but thought that I would just add this for your reference and also for any future readers.

If you are having an error 500, it means there is an error in your php code. You can set error reporting to 'on' in your php by adding the following to the top of your php file:

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

If you add that, then reload the front end you should get some more details about the error and it may help you decipher the problem and fix it.

jock.perkins
  • 469
  • 6
  • 23
  • This is really helpful thank you. However I am still not receiving the messages. From the other comments I realised I had missed a semi colon. I get the "Message sent" feedback but nothing received. – Noah Mar 22 '17 at 07:56
0

$message = $_POST['message'] // you miss ;

Beny Hdez
  • 92
  • 1
  • 8
0

Missing semicolon on $message = $_POST['message'] and your mail function is missing dollar signs against the variables.

0

you have missed a semicolon here in $message = $_POST['message'] also you missed a $ sign here if (mail(to, subject, message, from))

and make sure your php file name is contact-form.php

Ch Hamza Javed
  • 320
  • 1
  • 9