Php 联系方式不起作用

Php 联系方式不起作用,php,forms,contact,Php,Forms,Contact,我为联系人表单编写了代码,但我不知道为什么它不起作用。一切都设置好了表格,但我没有收到电子邮件。我没有得到任何错误或什么。这是html代码: <!-- Form --> <form method="post" action="contact_form.php" name="contactform" id="contactform" class="row"> <fieldset> <div class="form-field col

我为联系人表单编写了代码,但我不知道为什么它不起作用。一切都设置好了表格,但我没有收到电子邮件。我没有得到任何错误或什么。这是html代码:

<!-- Form -->
<form method="post" action="contact_form.php" name="contactform" id="contactform" class="row">
    <fieldset>
        <div class="form-field col-sm-6">
            <label for="name">Name</label>
            <span><input type="text" name="name" id="name" /></span>
        </div>
        <div class="form-field col-sm-6">
            <label for="email">Email</label>
            <span><input type="email" name="email" id="email" /></span>
        </div>
        <div class="form-field col-sm-6">
            <label>*What is 2+2? (Anti-spam)</label>
            <span><input name="human" placeholder="Type Here"></span>
        </div>
        <div class="form-field col-sm-12">
            <label for="message">Message</label>
            <span><textarea name="message" id="message"></textarea></span>
        </div>
    </fieldset>
    <div class="form-click center col-sm-12">
        <span><input type="submit" name="submit" value="Send it" id="submit" /></span>
    </div>
    <div id="alert" class="col-sm-12"></div>
</form>
<?php

$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$from = 'From: TangledDemo';
$to = 'kreso.galic8@gmail.com';
$subject = 'Hello';
$human = $_POST['human'];

$body = "From: $name\n E-Mail: $email\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>';
    }
}
?>

名称
电子邮件
*什么是2+2?(反垃圾邮件)
消息
这是php代码:

<!-- Form -->
<form method="post" action="contact_form.php" name="contactform" id="contactform" class="row">
    <fieldset>
        <div class="form-field col-sm-6">
            <label for="name">Name</label>
            <span><input type="text" name="name" id="name" /></span>
        </div>
        <div class="form-field col-sm-6">
            <label for="email">Email</label>
            <span><input type="email" name="email" id="email" /></span>
        </div>
        <div class="form-field col-sm-6">
            <label>*What is 2+2? (Anti-spam)</label>
            <span><input name="human" placeholder="Type Here"></span>
        </div>
        <div class="form-field col-sm-12">
            <label for="message">Message</label>
            <span><textarea name="message" id="message"></textarea></span>
        </div>
    </fieldset>
    <div class="form-click center col-sm-12">
        <span><input type="submit" name="submit" value="Send it" id="submit" /></span>
    </div>
    <div id="alert" class="col-sm-12"></div>
</form>
<?php

$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$from = 'From: TangledDemo';
$to = 'kreso.galic8@gmail.com';
$subject = 'Hello';
$human = $_POST['human'];

$body = "From: $name\n E-Mail: $email\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>';
    }
}
?>

如果($\u POST['submit']){不起作用,则似乎

您应该使用
empty
isset

if (!empty($_POST['submit'])) {

请注意,如果用户在输入字段中按enter键而不是单击submit按钮,提交值将不会被发送

您可以改为使用隐藏字段:

<input type="hidden" name="ok" value="1" />


表单是否显示任何消息?是否有其他使用
mail()的PHP脚本
工作?可能您的服务器上没有正确配置邮件软件。echo您的邮件已发送!

没有显示这两封邮件中的任何内容。没有。没有任何内容工作。@KresoGalic我测试了您的代码,它工作了!输出您的邮件已发送!!!它甚至将电子邮件发送到我更改的电子邮件!!看到了吗?是的,我收到了电子邮件我想是你说的,但我认为jquery在我的代码中有冲突