不知道php需要一些信息,如果这是正确的。这是一个联系页面

不知道php需要一些信息,如果这是正确的。这是一个联系页面,php,html,Php,Html,这是html 它叫contact.html,php是外部文件 这就是php <form action="mailer.php" method="post"> <label>Name</label> <input name="name" placeholder="Type Here"> <label>Email</label> <input na

这是html

它叫contact.html,php是外部文件

这就是php

 <form action="mailer.php"  method="post">

          <label>Name</label>
        <input name="name" placeholder="Type Here">

        <label>Email</label>
        <input name="email" type="email" placeholder="Type Here">

        <label>Contact Number</label>
        <input name="number" type="text" placeholder="Type Here">

        <label>Message</label>
        <textarea name="message" placeholder="Type Here"></textarea>
        <br/>

        <input id="submit" name="submit" type="submit" value="Submit">

    </form>

名称
电子邮件
联系电话
消息

下面是名为mailer.php的php文件。我需要知道这个表格是否有效,以及 没有什么不对劲。或者如果你有其他的建议。 谢谢你的帮助

 <?php
        $name = $_POST['name'];
        $email = $_POST['email'];
        $number = $_POST['number'];
        $message = $_POST['message'];
        $from = 'From:me'; 
        $to = 'me@hotmail.com'; 
        $subject = 'Hello';

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




 if ($_POST['submit']) {
        if ($name != '' && $email != '') {
            if ($human == '4') {                 
                if (mail ($to, $subject, $body, $from)) { 
                echo '<p>Your message has been sent!</p>';
            } else { 
                echo '<p>Something went wrong, go back and try again!</p>'; 
            } 
        } else if ($_POST['submit'] && $human != '4') {
            echo '<p>You answered the anti-spam question incorrectly!</p>';
        }
        } else {
            echo '<p>You need to fill in all required fields!!</p>';
        }
    }
    ?>

我唯一看到的错误是
$human
任何引用。你没有在任何地方申报过。我想这是某种捕获。可能是一个标签为“Whats2+2”的输入字段。如果4写在输入字段中,则它是人类,如果不是,则它是机器人。这是低级别的机器人测试,但可能足以满足您的需要。一个应该保持为空的隐藏字段也是测试机器人的好方法。机器人将屏幕读取并填写隐藏字段,从而使表单无效

<form action="mailer.php"  method="post">

          <label>Name</label>
        <input name="name" placeholder="Type Here">

        <label>Email</label>
        <input name="email" type="email" placeholder="Type Here">

        <label>Contact Number</label>
        <input name="number" type="text" placeholder="Type Here">

        <label>Message</label>
        <textarea name="message" placeholder="Type Here"></textarea>
        <br/>

        <label>What's 2+2</label>
         <input name="human" type="number" placeholder="Type Here">
        <br/>

        <input id="submit" name="submit" type="submit" value="Submit">

    </form>
在你的php文件的末尾放上这个,它会把他们带到一个你可以创建的感谢页面

header("Location: thanks.html");
或者你可以把这个

header("Location: contact.php?thanks");
请注意,您需要将联系人页面上的文件扩展名从
.html
更改为
.php
。就是这样,然后我们在您的页面上运行
php
,检查页面是否从php文件加载,如果是,我们可以显示感谢消息而不是表单

把你的表格改成这样。它将检查页面是否已从php文件加载

<?php
if($_REQUEST["thanks"]) {
    ?>
    <p>Thanks for your form submition</p>
    <?php
} else {
?>
  <form action="mailer.php"  method="post">

          <label>Name</label>
        <input name="name" placeholder="Type Here">

        <label>Email</label>
        <input name="email" type="email" placeholder="Type Here">

        <label>Contact Number</label>
        <input name="number" type="text" placeholder="Type Here">

        <label>Message</label>
        <textarea name="message" placeholder="Type Here"></textarea>
        <br/>

        <label>What's 2+2</label>
         <input name="human" type="number" placeholder="Type Here">
        <br/>

        <input id="submit" name="submit" type="submit" value="Submit">

    </form>
<?php
}
?>

谢谢你的表格提交

名称 电子邮件 联系电话 消息
2+2是什么

至少,您的mailer.php文件将失败,因为未设置$human,但正在检查/需要发送电子邮件

下面我添加了一行(上面有评论),这将允许邮件发送

警告:进行此更改将打开此表单,供机器人使用/spam

$name = $_POST['name'];
$email = $_POST['email'];
$number = $_POST['number'];
$message = $_POST['message'];
$from = 'From:me'; 
$to = 'me@hotmail.com'; 
$subject = 'Hello';
// To at least get it to run, add the below (this will allow spamming, but get the form to work)
$human = 4;

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




if ($_POST['submit']) {  
    if ($name != '' && $email != '') {
        // $human variable is not being set above, so this will never pass
        if ($human == '4') {                 
            if (mail ($to, $subject, $body, $from)) { 
                echo '<p>Your message has been sent!</p>';
            } else { 
                echo '<p>Something went wrong, go back and try again!</p>'; 
            } 
        } else if ($_POST['submit'] && $human != '4') {
            echo '<p>You answered the anti-spam question incorrectly!</p>';
        }
    } else {
        echo '<p>You need to fill in all required fields!!</p>';
    }
}
?>
$name=$\u POST['name'];
$email=$_POST['email'];
$number=$_POST['number'];
$message=$_POST['message'];
$from='from:me';
$to$me@hotmail.com'; 
$subject='Hello';
//至少要让它运行,请添加以下内容(这将允许垃圾邮件,但要让表单正常工作)
$human=4;
$body=“From:$name\n E-Mail:$email\n Number:$Number\n Message:\n$Message”;
如果($_POST['submit']){
如果($name!=''&&$email!=''){
//$human变量未设置在上面,因此这将永远不会通过
如果($human=='4'){
如果(邮件($to,$subject,$body,$from)){
回显“您的邮件已发送!

”; }否则{ echo“出现问题,请返回并重试!

”; } }否则如果($_POST['submit']&&$human!='4'){ echo“您错误地回答了反垃圾邮件问题!

”; } }否则{ echo“您需要填写所有必填字段!!

”; } } ?>
为什么不试试看发生了什么事?你的mailer.php文件正在检查
$human
是否等于4,但是你似乎没有在任何地方捕获、传递或设置该变量。我看不到,我对php一无所知。只需上传所有内容并加载表单,填写并提交,看看会发生什么。您收到任何错误消息或邮件,然后给我们更多的上下文-您不能运行这个吗?如果不能,那么这样做的目的是什么?编写无法运行/测试的php是徒劳的-存在各种潜在问题(邮件
mail
函数是否工作?php配置是否正确?等等)$human=$\u POST['human'];现在应该可以用了?非常感谢。当用户添加了他们的数据时,我如何使表单清晰?我编辑了我的答案,告诉你如何显示谢谢
$name = $_POST['name'];
$email = $_POST['email'];
$number = $_POST['number'];
$message = $_POST['message'];
$from = 'From:me'; 
$to = 'me@hotmail.com'; 
$subject = 'Hello';
// To at least get it to run, add the below (this will allow spamming, but get the form to work)
$human = 4;

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




if ($_POST['submit']) {  
    if ($name != '' && $email != '') {
        // $human variable is not being set above, so this will never pass
        if ($human == '4') {                 
            if (mail ($to, $subject, $body, $from)) { 
                echo '<p>Your message has been sent!</p>';
            } else { 
                echo '<p>Something went wrong, go back and try again!</p>'; 
            } 
        } else if ($_POST['submit'] && $human != '4') {
            echo '<p>You answered the anti-spam question incorrectly!</p>';
        }
    } else {
        echo '<p>You need to fill in all required fields!!</p>';
    }
}
?>