PHP联系表单有效期/安全性

时间:2015-05-03 05:29:08

标签: php html forms contact

我是一个完整的PHP新手,这个文件是我做过的第二个PHP。基本上,我在网上找到了一个联系表单教程,我想确保它在我从测试域中删除之前是安全的,添加正确的电子邮件并使其生效。

正如我发现的那样,第84行中的某些内容并不正确,但我一点都不知道我需要修理它是什么。 任何帮助将不胜感激!

编辑 - 我正在通过Bootstrap构建我的网站,如果这对任何事情都有任何影响。

    <?php
  if ($_POST["submit"]) {
    $InputName = $_POST['InputName'];
    $InputEmail = $_POST['InputEmail'];
    $InputSubject = $_POST['InputSubject'];
    $InputMessage = $_POST['InputMessage'];
    $InputReal = intval($_POST['InputReal']);
    $from = 'Contact Form'; 
    $to = 'test@email.com'; 
    $subject = $InputSubject;

    $body = "From: $InputName\n E-Mail: $InputEmail\n Message:\n $InputMessage";
}

if (!$_POST['InputName']) {
    $errName = 'Please enter your name';
}


if (!$_POST['InputEmail'] || !filter_var($_POST['InputEmail'], FILTER_VALIDATE_EMAIL)) {
    $errEmail = 'Please enter a valid email address';
}

if (!$_POST['InputSubject']) {
    $errSubject = 'Please enter a subject.';
}

if (!$_POST['InputMessage']) {
    $errMessage = 'Your message is empty!';
}

if ($InputReal !== 7) {
    $errHuman = 'Your anti-spam is incorrect';
}


if (!$errName && !$errEmail && !$errMessage && !$errHuman) {
    if (mail ($to, $subject, $body, $from)) {
        $result='   <div class="alert alert-success">
      <strong>
        <span class="glyphicon glyphicon-send"></span> Thank you! I will be in touch. 
      </strong>
    </div> ';
    } else {
        $result='    <div class="alert alert-danger">
      <strong>
        <span class="glyphicon glyphicon-send"></span> A problem occured. Please try again shortly. 
      </strong>
    </div> ';
    }
}
?>


<!DOCTYPE html>

<html>
<head>
  <meta charset="UTF-8">
  <title>Contact - The Illustrated Hermit</title>

  <meta name="keywords" content="art, digital, illustration,portfolio">
  <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1">

  <link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet" type="text/css">
  <link href='http://fonts.googleapis.com/css?family=Open+Sans:300,400' rel='stylesheet' type='text/css'>
  <link href="includes/main.css" rel="stylesheet" type="text/css" media="screen">


  <link rel="icon" href="favicon.ico">
  <link rel="apple-touch-icon" href="apple-touch-icon.png">

</head>
<body>

<div id='navload'></div><!--Navload-->

<div class='content contact'>
<div class="row">
  <div class="col-md-7">

   <?php echo $result; ?>

    <?php echo "<p class='text-danger'><div class="alert alert-danger">
      <span class="glyphicon glyphicon-alert"></span><strong> $errName </strong>
    </div></p>";?>
    <?php echo "<p class='text-danger'><div class="alert alert-danger">
          <span class="glyphicon glyphicon-alert"></span><strong> $errEmail </strong>
        </div></p>";?>
    <?php echo "<p class='text-danger'><div class="alert alert-danger">
          <span class="glyphicon glyphicon-alert"></span><strong> $errSubject </strong>
        </div></p>";?>
    <?php echo "<p class='text-danger'><div class="alert alert-danger">
          <span class="glyphicon glyphicon-alert"></span><strong> $errMessage </strong>
        </div></p>";?>
    <?php echo "<p class='text-danger'><div class="alert alert-danger">
          <span class="glyphicon glyphicon-alert"></span><strong> $errHuman </strong>
        </div></p>";?>
  </div>

  <form role="form" action="" method="post" class='col-md-7'>
    <div class="col-md-12">
      <div class="well well-sm">
        <strong><i class="glyphicon glyphicon-ok form-control-feedback"></i> Required Field</strong>
      </div>

      <div class="form-group">
        <label for="InputName">Your Name</label>
        <div class="input-group">
          <input type="text" class="form-control" name="InputName" id="InputName" placeholder="Enter Name" required value="<?php echo htmlspecialchars($_POST['InputName']); ?>">
          <span class="input-group-addon"><i class="glyphicon glyphicon-ok form-control-feedback"></i></span></div>
      </div>

      <div class="form-group">
        <label for="InputEmail">Your Email</label>
        <div class="input-group">
          <input type="email" class="form-control" id="InputEmail" name="InputEmail" placeholder="Enter Email" required  value="<?php echo htmlspecialchars($_POST['InputEmail']); ?>">
          <span class="input-group-addon"><i class="glyphicon glyphicon-ok form-control-feedback"></i></span></div>
      </div>

      <div class="form-group">
        <label for="InputSubject">Subject</label>
        <div class="input-group">
          <input type="email" class="form-control" id="InputSubject" name="InputSubject" placeholder="Enter Subject" required  value="<?php echo htmlspecialchars($_POST['InputSubject']); ?>">
          <span class="input-group-addon"><i class="glyphicon glyphicon-ok form-control-feedback"></i></span></div>
      </div>

      <div class="form-group">
        <label for="InputMessage">Message</label>
        <div class="input-group">required> value="<?php echo htmlspecialchars($_POST['InputMessage']); ?>" </textarea>
          <span class="input-group-addon"><i class="glyphicon glyphicon-ok form-control-feedback"></i></span></div>
      </div>

      <div class="form-group">
        <label for="InputReal">What is 4+3? (Simple Spam Checker)</label>
        <div class="input-group">
          <input type="text" class="form-control" name="InputReal" id="InputReal" require
          <textarea name="InputMessage" id="InputMessage" class="form-control" rows="5" d>
          <span class="input-group-addon"><i class="glyphicon glyphicon-ok form-control-feedback"></i></span></div>
      </div>
      <input type="submit" name="submit" id="submit" value="Submit" class="btn btn-info pull-right">
    </div>
  </form>

  <hr class="featurette-divider hidden-lg">

    <div class="col-md-4 col-md-push-1">
      <h3>Social Media Link Reiteration</h3>
        <p>
          Tumblr
          Facebook
          Linked In
          Behance
          Redbubble
        </p>
    </div>
</div>

</div>

<script src="http://code.jquery.com/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
<script type="text/javascript" src='includes/main.js'></script>

  <script>
      (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
      (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
      m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
      })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

      ga('create', 'UA-59497650-1', 'auto');
      ga('send', 'pageview');
  </script>
</body>
</html>

0 个答案:

没有答案