#php #html #forms #comments
#php #HTML #формы #Комментарии
Вопрос:
Я знаю, что это базово, но я использую форму комментариев 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: $namen E-Mail: $emailn Message:n $message";
if ($_POST['submit'] amp;amp; $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'] amp;amp; $human != '4') {
echo '<p>You answered the anti-spam question incorrectly!</p>';
}
?>
Все, что мне прислали по электронной почте, это имя, адрес электронной почты и сообщение, что я делаю не так? Пожалуйста, пожалуйста, сообщество может помочь.
Комментарии:
1. Нет ничего, что требовало бы заполнения поля — они могут не отображаться, если это не так. Также я предлагаю вам взглянуть на типы ввода HTML5. У вас должен быть код для проверки ваших входных данных в вашем скрипте в любом случае. Ваш HTML-код также может быть плохо сформирован — у вас, похоже, есть блуждающий
div class="form-button">
элемент без закрытия</div>
и закрывающий div без открывающего в форме2. Очевидно, вы получите только имя, адрес электронной почты и сообщение, потому что это то, что вы вводите
$body
. Поместите остальные переменные в поле$body
, и вы их получите.
Ответ №1:
Вам нужно добавить поля электронной почты в переменную $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: $namen E-Mail: $emailn Message:n $message Postcode: n $postcode DOB: n $dob n";
if ($_POST['submit'] amp;amp; $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'] amp;amp; $human != '4') {
echo '<p>You answered the anti-spam question incorrectly!</p>';
}
Ответ №2:
Вы не используете ни одно из дополнительных полей, которые вы захватываете. Если вы хотите, чтобы они были включены, вам нужно добавить их в сообщение.
Ответ №3:
<!-- 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>