0

联系表格.html

<form method="POST" name="contactform" action="contact-form-handler.php"> 
<p>
<label for='name'>Your Name:</label> <br>
<input type="text" name="name">
</p>
<p>
<label for='email'>Email Address:</label> <br>
<input type="text" name="email"> <br>
</p>
<p>
<label for='message'>Message:</label> <br>
<textarea name="message"></textarea>
</p>
<input type="submit" value="Submit"><br>
</form>

联系表格handler.php

<?php 
$errors = '';
$myemail = 'net.dev@spikyarc.net';
if(empty($_POST['name'])  || 
empty($_POST['email']) || 
empty($_POST['message']))
{
   $errors .= "\n Error: all fields are required";
}

$name = $_POST['name']; 
$email_address = $_POST['email']; 
$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 = $myemail; 
$email_subject = "Contact form submission: $name";
$email_body = "You have received a new message. ".


$headers = "From: $myemail\n"; 
$headers .= "Reply-To: $email_address";

mail($to,$email_subject,$email_body,$headers);
//redirect to the 'thank you' page
header('Location: contact-form-thank-you.html');
  } 
?>

这两个文件我都放在 wwwroot 文件夹中,但是当我提交 html 表单时,它给出了错误The page cannot be displayed。我找不到问题。谢谢你帮助我。

4

2 回答 2

0

将 HTML 表单中的操作设置为:

contact-form-handler.php

喜欢:

<form method="POST" name="contactform" action="contact-form-handler.php"> 

更新1:并检查:

改变

$email_subject = "Contact form submission: $name";

$email_subject = "Contact form submission:" . $name;

更新2:这也是:

$headers = "From: $myemail\n"; 
$headers .= "Reply-To: $email_address";

至:

$headers = "From: " . $myemail . "\n"; 
$headers .= "Reply-To:" . $email_address;

更新 3:

您验证了电子邮件地址$email_address,但从不使用它。

于 2013-09-12T06:52:12.247 回答
0

一定要在动作中检查文件名!!

于 2013-09-12T12:25:04.230 回答