我创建了非常简单的消息表单,但存在一些问题。至少发送消息并显示感谢页面,但在第 14 行有 Notice: Undefined index: name in public_www/n..../contact-form-handler.php 和另一个错误是 name is not发送。
感谢您的任何提示
<form class='contact_form' method="POST" action="contact-form-handler.php" >
<ul>
<li>
<label for="name" >Name:</label>
<input type="text" id="name" />
</li>
<li>
<label for="email" id="email">Email:</label>
<input type="email" name="email" />
</li>
<li>
<label for="message" id="message">Message:</label>
<textarea name="message" cols="40" rows="6" required ></textarea>
</li>
<li>
<button class="submit" value="submit">Submit Form</button>
</li>
</ul>
</form>
PHP是:
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$to = "test@test.com";
$subject = "Contact";
$name_field = $_POST['name'];
$email_field = $_POST['email'];
$message = $_POST['message'];
$body = "From: $name_field\n E-Mail: $email_field\n Message:\n $message";
echo include( "contact-form-thank-you.html" );
mail($to, $subject, $body);
} else {
echo include( "contact-form-error.html" );
}
?>