我联系表单中的php似乎无法正常工作。我得到了一个 "请更正以下错误:
写下你的信息 点击后退按钮再试一次"如果有经验的人可以分享一些建议,我非常感激。谢谢 !
<?php
/* Set e-mail recipient */
$myemail = "myemail@com.com";
/* Check all form inputs using check_input function */
$name = check_input($_POST['name'], "Enter your name");
$phone = check_input($_POST['phone'], "Enter phone number");
$email = check_input($_POST['email']);
$message = check_input($_POST['message'], "Write your message");
/* If e-mail is not valid show error message */
if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email))
{
show_error("E-mail address not valid");
}
/* Let's prepare the message for the e-mail */
$message = "
Name: $name
E-mail: $email
Phone: $phone
Message:
$message
";
/* Send the message using mail() function */
mail($myemail, $phone, $message);
/* Redirect visitor to the thank you page */
header('Location: thanks.html');
exit();
/* Functions we used */
function check_input($data, $problem='')
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
if ($problem && strlen($data) == 0)
{
show_error($problem);
}
return $data;
}
function show_error($myError)
{
?>
<html>
<body>
<p>Please correct the following error:</p>
<strong><?php echo $myError; ?></strong>
<p>Hit the back button and try again</p>
</body>
</html>
<?php
exit();
}
?>
<div class="wrapper">
<div id="contact_form">
<form name="form1" id="ff" method="post" action="form.php">
<label>
<span>Name*:</span>
<input type="text" placeholder="Please enter your name" name="name" id="name" required autofocus>
</label>
<label>
<span>Phone:</span>
<input type="tel" placeholder="Please enter your phone" name="phone" id="phone">
</label>
<label>
<span>Email*:</span>
<input type="email" placeholder="youremail@gmail.com" name="email" id="email" required>
</label>
<label>
<span>Message:</span>
<textarea placeholder="message"></textarea>
</label>
<input class="sendButton" type="submit" name="Submit" value="Send">
</form>
</div>
</div>
答案 0 :(得分:3)
您正在寻找名为“消息”的值:
$_POST['message']
但您的表单中没有名为“message”的表单元素。
为textarea
添加姓名:
<textarea name="message" placeholder="message"></textarea>