与htmlspecialchars安全的PHP联系表单($ _ SERVER [“PHP_SELF”])

时间:2015-01-19 02:16:13

标签: php

我是php的新手,我正在尝试在网页上创建一个简单,安全且有效的联系表单。我的表格如下:

<form class="form-horizontal" method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" >
<fieldset>

    <div class="form-group">
        <span class="col-md-1  text-center"><i class="fa fa-user bigicon"></i></span>
        <div class="col-md-11">
            <input id="fname" name="name" type="text" placeholder="Name" class="form-control">
        </div>
    </div>

    <div class="form-group">
        <span class="col-md-1  text-center"><i class="fa fa-envelope-o bigicon"></i></span>
        <div class="col-md-11">
            <input id="email" name="email" type="text" placeholder="Email Address" class="form-control">
        </div>
    </div>

    <div class="form-group">
        <span class="col-md-1  text-center"><i class="fa fa-pencil-square-o bigicon"></i></span>
        <div class="col-md-11">
            <textarea class="form-control" id="message" name="message" placeholder="Enter your massage for us here. We will get back to you within 2 business days." rows="7"></textarea>
        </div>
    </div>

    <div class="form-group">
        <div class="col-md-12 text-right">
            <button type="submit" class="btn btn-primary btn-lg">Send</button>
        </div>
    </div>
</fieldset>

我有以下php文件(称为mail.php),我想在按下SEND按钮时执行。

<?php 
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$formcontent="From: $name \n Message: $message";
$recipient = "some.email@gmail.com";
$subject = "Contact Form";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");?>

问题是;如果我有

action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" 

如何在mail.php中执行php脚本?

0 个答案:

没有答案