【发布时间】:2017-05-31 04:36:31
【问题描述】:
表单有效,我收到了电子邮件,但是当您单击提交时,它不会将您带到感谢页面,它给了我以下错误消息:
Error 404 - Not Found
The document you are looking for may have been removed or re-named.
Please contact the web site owner for further assistance.
这是表单的代码:
<section class="contactForm">
<h1><strong>Contact Andrea</strong></h1>
<form action="http://ddion.com/webcert_s17/andreas/DW_FINAL/formmail.php" method="post" name="form1" id="form1">
<label for="name">Name:</label>
<input name="name" type="text" required class="formStyle" id="name" form="form1">
<br>
<label for="email">Email:</label>
<input name="email" type="email" required class="formStyle" id="email" form="form1">
<br>
<label for="comments">Comments:</label>
<textarea name="comments" cols="5" required class="formStyle" id="comments" form="form1"></textarea>
<br>
<input type="submit" class="formStyle" name="submit" id="submit" value="Submit">
</form>
</section>
这是PHP
<?php
$name=addslashes($_POST['name']);
$email=addslashes($_POST['email']);
$comments=addslashes($_POST['comments']);
// you can specify which email you want your contact form to be emailed to here
$toemail = "anlsimental@gmail.com";
$subject = "from AndreaSimentalPhotogragy.com";
$headers = "MIME-Version: 1.0\n"
."From: \"".$name."\" <".$email.">\n"
."Content-type: text/html; charset=iso-8859-1\n";
$body = "Name: ".$name."<br>\n"
."Email: ".$email."<br>\n"
."Comments:<br>\n"
.$comments;
if (!ereg("^[a-zA-Z0-9_]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$", $email))
{
echo "That is not a valid email address. Please return to the"
." previous page and try again.";
exit;
}
mail($toemail, $subject, $body, $headers);
echo "Thanks for submitting your comments";
?>
我的thankyou.html 位于php 旁边。但不知何故不起作用......有什么想法吗?
【问题讨论】:
-
在浏览器上打开 F12。打开日志记录。在页面之间保留日志。您导航到哪个页面会导致 404?什么是感谢页面?它们有什么区别?
-
您在哪里编写了重定向到感谢页面的代码?
-
为什么你的感谢文件
.. DW_FINAL/0;URL=thankyou.html?不应该只是...DW_FINAL/thankyou.html吗? -
警告:ereg 函数在 PHP 5.3.0 中被弃用,在 PHP 7.0.0 中被移除。
-
回显任何东西都会阻止重定向工作。您需要输出
Location标头而不是 echo 输出。
标签: php html forms email phpmailer