PHP页面不起作用,不完全确定原因

时间:2014-02-03 21:20:21

标签: php html

你好,stackoverflow的人。
我是Sixth Form的学生,目前我正在开发一个网站,其中添加了一些内容作为我的项目,但我已经用这一页打了一个墙。这是一个联系表单,在填写完成后发送电子邮件,然后告诉他们使用PHP。我遇到的问题是,它不是加载页面,而是加载......好吧,没有。
如果你们中的任何一个人都能借给我一只手并告诉我哪里出错了那么我将非常感激! (代码如下)

<?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');
?>

我非常确定HTML工作正常,因为在我放入PHP之前页面工作正常所以如果你可以看一看并给我一个抬头甚至为我纠正它那么那就是奇妙。

提前致谢, 奥利

3 个答案:

答案 0 :(得分:0)

您错过了)

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

应该是

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

答案 1 :(得分:0)

试试这个..     

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;
    }
}
?>

答案 2 :(得分:-1)

添加此行

使用error_reporting(E_ALL);

同时添加

的var_dump($ _ POST)

打印出变量