Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/272.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 联系人表单电子邮件验证_Php_Html_Twitter Bootstrap_Contact Form - Fatal编程技术网

Php 联系人表单电子邮件验证

Php 联系人表单电子邮件验证,php,html,twitter-bootstrap,contact-form,Php,Html,Twitter Bootstrap,Contact Form,我正在创建一个网站和我的一个功能,联系形式,需要调整最后一点,以真正成功。由于youtube上的一段精彩视频,我能够通过SMTP发送电子邮件。但是另一个教程(由同一个上传者提供)演示了如何验证电子邮件地址,我有代码,但是当我将它与index.php文件一起使用时,它似乎不起作用 我的意思是,在单击submit(根据视频,这是应该发生的事情)后,验证不会显示。我需要帮助,以了解在我的index.php代码中,在何处放置FILTER_VALIDATE php位 我不确定github链接在这里是否流行

我正在创建一个网站和我的一个功能,联系形式,需要调整最后一点,以真正成功。由于youtube上的一段精彩视频,我能够通过SMTP发送电子邮件。但是另一个教程(由同一个上传者提供)演示了如何验证电子邮件地址,我有代码,但是当我将它与index.php文件一起使用时,它似乎不起作用

我的意思是,在单击submit(根据视频,这是应该发生的事情)后,验证不会显示。我需要帮助,以了解在我的index.php代码中,在何处放置FILTER_VALIDATE php位

我不确定github链接在这里是否流行,但这是我的github

这些是我所说的联系方式的文件。它发送电子邮件没有问题(如下面的感谢屏幕所示)

下面是联系人表单的html:index.php

<?php

session_start();
require_once 'security.php';
$errors = isset($_SESSION['errors']) ? $_SESSION['errors'] : [];
$fields = isset($_SESSION['fields']) ? $_SESSION['fields'] : [];
?>

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable = no">
    <title>Contact</title>
    <!-- Bootstrap -->
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <link href="css/custom.css" rel="stylesheet">
  </head>
  <body>
    <div class="container alt3">
            <div class="page-header" id="contact">
                <h2>Contact us<small> Contact us for more!</small></h2>
            </div><!--end page header-->
                <div class="col-lg-8">
                <?php if(!empty($errors)): ?>
                    <div class = "panel">
                        <ul>
                            <li> <?php echo implode('</li><li>', $errors); ?></li>
                        </ul>
                    </div>
            <?php endif; ?>

            <?php 
            if (isset($_POST['email']) == true && empty($_POST['email']) == false) {
              $email = $_POST['email'];
                if (filter_var($email, FILTER_VALIDATE_EMAIL) == true) {
                echo 'That\'s a valid email address';
                } else {
                echo 'Not a valid email address';
                }
            }
            ?>
                <form action="contact.php" class="form-horizontal"  method="post">
                 <div class="form-group">
                    <label for ="name" class="col-lg-2 control-label">
                    Name</label>
                    <div class="col-lg-10">
                        <input type="text" name = "name" class="form-control" id="name" placeholder="Enter your name" <?php echo isset($fields['name']) ? 'value ="' . e($fields['name']). '"' : '' ?>>
                    </div>

                 </div><!--end form-group-->

                 <div class="form-group">
                    <label for="email" class="col-lg-2 control-label"> Email</label>
                    <div class="col-lg-10">
                        <input type="text" name = "email" class="form-control" id="email" placeholder="Enter your Email Address" <?php echo isset($fields['email']) ? 'value ="' . e($fields['email']). '"' : '' ?>>
                    </div>

                 </div><!--end form-group-->


                 <div class="form-group">
                    <label for="message" class="col-lg-2 control-label"> Any message</label>
                    <div class="col-lg-10">
                        <textarea name="message" id="message" class="form-control" 
                        cols="20" rows="10" placeholder="Enter your Message"><?php echo isset($fields['message']) ? e($fields['message']). '"' : '' ?></textarea>
                    </div>
                 </div><!--end form-group-->

                 <div class="form-group">
                    <div class="col-lg-10 col-lg-offset-2">
                        <button type="submit" class="btn btn-primary">Submit</button>
                    </div>
                    </form>
                </div>
  </body>
</html>
<?php
unset($_SESSION['errors']);
?>

接触
联系我们联系我们获取更多信息!
名称 > 有消息吗 提交
下面是contact.php,它工作得很好

这是index.php中的“FILTER\u VALIDATE”php位,我认为它不起作用。在他的视频教程中,它应该在提交时显示电子邮件地址是否有效,但在我的例子中,它只是继续发送电子邮件

请帮忙


多谢各位。很明显,我是php新手,我这么做只是为了一个即将到来的重要事件和未来的广告目的,这里的几个问题很难理解,因为他们要么不回答我的问题,或者问题本身是一个完全不同的代码,我不需要这个基本的联系人表单。

似乎缺少结尾标记。

您的
表单
操作标记指向
contact.php
文件

您应该在那里验证电子邮件,而不是在
index.php
页面上验证

那么,给你

if (isset($_POST['name'], $_POST['email'], $_POST['message'])) {
    // right now check the email. If it's ok - keep on, if not add to $errors some message

到底什么不起作用?电子邮件验证似乎不起作用。如果我打字abc@gmail,没有了.com,它仍然会发送电子邮件。那么带有过滤器的php应该在contact.php中吗?你能在我的github中看到它并告诉我它在哪里吗?即使有这行代码,出于某种原因它仍然不起作用。我刚打过“abc@abertw.com“它仍然会发送电子邮件。
abc@abertw.com
是普通电子邮件。文件中的逻辑无效,是吗?这是否会在将来网站上线时引发问题,如垃圾邮件或注入攻击?我确实包含了一个security.php文件来防止javascript注入。
是这样吗?
你是什么意思?顺便说一句,你最好现在把密码改成你的gmail(确实在那里。当我在这里复制粘贴我的代码时,我错过了它,因为我不得不从主网站上裁剪出很多代码。很抱歉!