【发布时间】:2016-07-29 05:05:50
【问题描述】:
我目前在让我的 php 和 html 正常工作时遇到问题。当我单击“提交”时,它会转到一个错误页面,说它找不到我请求的网页(www.website.com/contact-form-handler.php)。
这里是 PHP 和 HTML
HTML:
<html>
<head></head
<body>
<div>
<form action="contact-form-handler.php" method="post" name="contact_form">
<div class="col-md-6 col-sm-6 form-group">
<input name="name" type="text" class="form-control" id="nameInput" placeholder="Name" required>
<input name="email" type="email" class="form-control" id="emailInput" placeholder="Email" required>
<input name="phone" type="text" class="form-control" id="phoneInput" placeholder="Phone" required>
<input name="location" type="text" class="form-control" id="locationInput" placeholder="Event Location" required>
<select name="eventType" type="select" class="form-control" id="eventTypeInput">
<option selected>Type of Event</option>
<option value="1">Business</option>
<option value="2">Party</option>
<option value="3">Speech</option>
</select>
<select name="reference" type="select" class="form-control" id="referenceInput">
<option selected>How did you hear about us?</option>
<option value="1">Social Media</option>
<option value="2">Word of Mouth</option>
<option value="3">Google Search</option>
</select>
</div>
<div class="col-md-6 col-sm-6 form-group">
<textarea name="message" rows="7" class="form-control" id="messageInput" placeholder="Message"></textarea>
</div>
<div class="col-md-offset-4 col-md-4 col-sm-offset-3 col-sm-6 font3">
<input name="submit" type="submit" class="form-control" id="submit" value="Submit">
</div>
</form>
</div>
</body>
</html>
PHP:
<?php
$errors = '';
$emails = 'myemail@myemail.com';//<-----Put Your email address here.
if(empty($_POST['name']) ||
empty($_POST['email']) ||
empty($_POST['phone']) ||
empty($_POST['location']) ||
{
$errors .= "\n Error: Please fill out required fields";
}
$name = $_POST['name'];
$email_address = $_POST['email'];
$phone = $_POST['phone'];
$location = $_POST['location'];
$eventType = $_POST['eventType'];
$reference = $_POST['reference'];
$message = $_POST['message'];
if (!preg_match(
"/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i",
$email_address))
{
$errors .= "\n Error: Invalid email address";
}
if( empty($errors))
{
$to = $emails;
$subject = "David Does Stuff Inquiry: $name";
$email_body = "You have received a new message. ".
" Here are the details:\n Name: $name \n Email: $email_address \n Phone: $phone \n Location of event: $location \n Type of Event: $eventType \n How did you hear about us: $reference \n Message \n $message";
$headers = "From: $email_address\n";
$headers .= "Reply-To: $emails";
mail($to,$subject,$email_body,$headers);
//redirect to the 'thank you' page
header('Location: contact-form-thank-you.html');
}
?>
【问题讨论】:
-
尝试通过转到 yourdomain.com/contact-form-handler.php 直接访问该页面,看看它是否有效
-
如错误所示,页面不存在
-
@Dagon 如果您无法直接访问该页面,或者页面名称不正确或不在同一目录中