与-form.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
。我找不到问题。谢谢你的帮助。
答案 0 :(得分: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
但从不使用它。
答案 1 :(得分:0)
请务必使用操作中的文件名检查文件名!!