2

Hello wonderful people of stackoverflow.
I'm a student in Sixth Form and am currently working on a website with a few added bits as my project but I've hit a wall with this one page. It's a contact form which sends an e-mail when it's filled out and told to do so, using PHP. The problem I'm having is that, instead of loading the page, it just loads... well, nothing.
If any of you folks could lend me a hand and tell me where I've gone wrong then that'd be much appreciated! (Code's below)

<?php

if($_SERVER["REQUEST_METHOD"]=="POST") {
    $name = trim($_POST["name"]);
    $email = trim($_POST["email"]);
    $message = trim($_POST["message"]);

    if($name == ""){
        echo "You must enter something for your name.";
    }

    if($email == ""){
        echo "You must enter something for your e-mail.";
    }

    if($message == ""){
        echo "You must enter something for your message.";
    }

    foreach( $_POST as $value ){
        if( stripos($value,'Content-Type:' !== FALSE){
            echo "There's a problem with the information you entered.";
        }
    }

    if($_POST["ignore"] != ""){
        echo "Your form submission has an error.";
        exit;
    }

    require_once("inc/phpmailer/class.phpmailer.php");
    $mail = new PHPMailer();

    if(!$mail->ValidateAddress($email)){
        echo "You must specify a valid e-mail address.";
        exit;
    }

    $email_body = "";
    $email_body = $email_body . "Name: " . $name . "<br>";
    $email_body = $email_body . "Email: " . $email . "<br>";
    $email_body = $email_body . "Message: " . $message;

    $mail->SetFrom($email, $name);
    $address = <MY EMAIL>;
    $mail->AddAddress($address, "Steve John");
    $mail->Subject = "Contact Form Submission | ".$name;
    $mail->MasgHTML($email_body);

    if(!$mail->Send()){
        echo "There was a problem sending your message -- ".$mail->ErrorInfo;
        exit;
    }

    header("Location: contact.php?status=success");
    exit;
}

?><?php
$pageTitle = "Stephen John Eyecare - Contact";
$section = "contact";
include('inc/head.php');
?>

<!--IMAGE BANNER: CONTACT-->
<div class = "container">
    <center>
        <img class = "featuredImg" src = "img/contact.png" width = "100%">
    </center>
</div>

<!--INSTRUCTIONS-->
<center>
<br>
<br>
    <h4>If you'd like to contact us, please either fill out the contact form below or give us a call at <NUMBER></h4> 
</center>

<div class = "container">
    <form class = "form-horizontal" role = "form" method = "post">

        <!--NAME FIELD-->
        <div class = "form-group">
            <label for = "inputName">Name: </label>
            <input type = "text" class = "form-control" id = "inputName" placeholder = "Your name here">
        </div>

        <!--EMAIL FIELD-->
        <div class = "form-group">
            <label for = "inputEmail">e-mail: </label>
            <input type = "email" class = "form-control" id = "inputEmail" placeholder = "Your e-mail address here">
        </div>

        <!--MESSAGE FIELD-->
        <div class = "form-group">
            <label for = "inputMessage">Message: </label>
            <textarea class = "form-control" rows = "5" placeholder = "Your message here">
        </div>
    </form>

    <center>
        <!--CANCEL & SEND BUTTONS OR SUCCESS MESSAGE-->
        <?php if isset($_GET["status"]) AND $_GET["status"] == "success"){?>
            <div class = "alert alert-success altert-dismissable">
                <button type = "button" class = "close" data-dismiss = "alert" aria-hidden = "true">&times;</button>
                <strong>SUCCESS!</strong>  Thanks for taking the time to contact us, we'll get back to you as soon as we can!
            </div>
        <?php } else { ?>
            <a href = "index.php" class = "btn btn-danger">Cancel & return to home page</a>
            <a href = "#" class = "btn btn-success">Send message</a>
        <?php } ?>
    </center>
</div>

<!--FOOTER-->
<?php
    include('inc/footer.php');
?>

I'm pretty sure the HTML works okay as the page was working fine before I put the PHP in so if you could give it a look over and give me a heads up or even correct it for me then that'd be fantastic.

Thanks in advance, Olly

Olly John
  • 366
  • 5
  • 20

3 Answers3

0

You are missing a ):

 if( stripos($value,'Content-Type:' !== FALSE){

should be

 if( stripos($value,'Content-Type:') !== FALSE){
                                   ^          
putvande
  • 15,068
  • 3
  • 34
  • 50
0

Try this..

if($_SERVER["REQUEST_METHOD"]=="POST") {
    $name = trim($_POST["name"]);
    $email = trim($_POST["email"]);
    $message = trim($_POST["message"]);

    if($name == ""){
        echo "You must enter something for your name.";
    }

    if($email == ""){
        echo "You must enter something for your e-mail.";
    }

    if($message == ""){
        echo "You must enter something for your message.";
    }

    foreach( $_POST as $value ){
        if( stripos($value, 'Content-Type:') !== FALSE){
            echo "There's a problem with the information you entered.";
        }
    }

    if($_POST["ignore"] != ""){
        echo "Your form submission has an error.";
        exit;
    }
}
?>
Bas Kuis
  • 748
  • 1
  • 7
  • 20
-1

Add this line

error_reporting(E_ALL);

Also add

var_dump($_POST)

to print out post variables

Sean Keane
  • 411
  • 1
  • 6
  • 19