从PHP / HTML联系表单创建外部PHP文件

时间:2015-04-27 15:36:28

标签: php html forms

我不熟悉PHP,无处不在地寻找解决方案。我也看了这里,但没有得到我可以使用的答案。我的问题是:如何使用PHP和HTML组合的页面的PHP代码创建外部PHP文件?我试图在一个页面上应用三个联系表单,使用Christopher Glimmers脚本。为了避免干扰并分离表单的数据,我想给任何形式自己的PHP处理程序。所以我试图私有化"包含外部PHP文件中的PHP代码。但是,这些只会生成一个空白的PHP页面。我检查了外部PHP,这是正确的。 我从原始PHP / HTML页面派生的代码是

<?php
if ($_POST["submit"]) {
    $name = $_POST['name'];
    $email = $_POST['email'];
    $message = $_POST['message'];
    $human = intval($_POST['human']);
    $from = 'Demo Contact Form'; 
    $to = 'info@robhordijk.nu'; 
    $subject = 'Message from Contact Demo ';

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

    // Check if name has been entered
    if (!$_POST['name']) {
        $errName = 'Please enter your name';
    }

    // Check if email has been entered and is valid
    if (!$_POST['email'] || !filter_var($_POST['email'], 
FILTER_VALIDATE_EMAIL)) {
        $errEmail = 'Please enter a valid email address';
    }

    //Check if message has been entered
    if (!$_POST['message']) {
        $errMessage = 'Please enter your message';
    }
    //Check if simple anti-bot test is correct
    if ($human !== 5) {
        $errHuman = 'Your anti-spam is incorrect';
    }

// If there are no errors, send the email
if (!$errName && !$errEmail && !$errMessage && !$errHuman) {
if (mail ($to, $subject, $body, $from)) {
    $result='<div class="alert alert-success">Thank You! I will be in
     touch</div>';
} else {
    $result='<div class="alert alert-danger">Sorry there was an error 
 sending your message. Please try again later.</div>';
}
}
}
?>

有人可以帮忙吗?

0 个答案:

没有答案