PHP注释表单不解析所有字段


PHP comment form not parsing all fields

我知道这是基本的,但我在我的网站上使用php评论表单,但它没有向我发送所有输入字段的信息,请有人帮助我。

这是我使用的HTML:

<form method="post" action="assets/php/mail.php">
    <label>Name</label>
    <input name="name" placeholder="Type Here">
    <label>Email</label>
    <input name="email" type="email" placeholder="Type Here">
    <label>Postcode</label>
    <input name="postcode" placeholder="Type Here">
    <label>Child's Date of Birth</label>
    <input name="dob" placeholder="Type Here">
    <label>Year your child will begin primary school in Reception class</label>
    <input name="year" placeholder="Type Here">
    <label>I would select York Community Free School as first choice for my child</label>
    <input name="send" placeholder="Type Here">
    <label>Message</label>
    <textarea name="message" placeholder="Type Here"></textarea>
    <label>*What is 2+2? (Anti-spam)</label>
    <input name="human" placeholder="Type Here">
    <div class="form-button">
        <input id="submit" name="submit" type="submit" value="Submit">
    </div>
</form>

我正在使用的PHP:

<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$postcode = $_POST['postcode'];
$dob = $_POST['dob'];
$year = $_POST['year'];
$send = $_POST['send'];
$from = 'From: York Free School Comment form'; 
$to = 'yorkfreeschool@gmail.com'; 
$subject = 'Hello';
$human = $_POST['human'];
$body = "From: $name'n E-Mail: $email'n Message:'n $message";
if ($_POST['submit'] && $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>';
}

?>

所有通过电子邮件发送给我的是名字,电子邮件和信息,我做错了什么?

您需要将电子邮件字段添加到$body变量中以便发送。在本例中,我只添加了DOB和邮政编码

<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$postcode = $_POST['postcode'];
$dob = $_POST['dob'];
$year = $_POST['year'];
$send = $_POST['send'];
$from = 'From: York Free School Comment form'; 
$to = 'yorkfreeschool@gmail.com'; 
$subject = 'Hello';
$human = $_POST['human'];
//Look here
$body = "From: $name'n E-Mail: $email'n Message:'n $message Postcode: 'n $postcode DOB: 'n $dob 'n";
if ($_POST['submit'] && $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>';
}

您没有使用任何正在抓取的附加字段。如果希望包含它们,则需要将它们附加到消息中。

<!-- ur html code is not valid, look at submit input -->
<form method="post" action="assets/php/mail.php">
    <label>Name</label>
    <input name="name" placeholder="Type Here">
    <label>Email</label>
    <input name="email" type="email" placeholder="Type Here">
    <label>Postcode</label>
    <input name="postcode" placeholder="Type Here">
    <label>Child's Date of Birth</label>
    <input name="dob" placeholder="Type Here">
    <label>Year your child will begin primary school in Reception class</label>
    <input name="year" placeholder="Type Here">
    <label>I would select York Community Free School as first choice for my child</label>
    <input name="send" placeholder="Type Here">
    <label>Message</label>
    <textarea name="message" placeholder="Type Here"></textarea>
    <label>*What is 2+2? (Anti-spam)</label>
    <input name="human" placeholder="Type Here">
    <!--</div> i think that closing div tag should go after input with id == "submit" -->
    <div class="form-button">
    <input id="submit" name="submit" type="submit" value="Submit">
    </div> <!-- here -->
</form>