【问题标题】:PHP Form mail redirecting page not workingPHP表单邮件重定向页面不起作用
【发布时间】: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


【解决方案1】:

您想要做的是重定向到http://ddion.com/webcert_s17/andreas/DW_FINAL/thankyou.html 而不是http://ddion.com/webcert_s17/andreas/DW_FINAL/0;URL=thankyou.html。通过从 URL 中的文件名中删除前面的 0;URL= 来修复它。

【讨论】:

  • 我删除了 0;URL= 但现在它只是将我发送到一个空白页面,感谢您的 cmets。 电子邮件表单
【解决方案2】:

deprecated ereg() 函数到preg_match()

使用这个

preg_match()

【讨论】:

  • 这可能是真的,但这不是答案。等到你有评论权限。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-03-16
  • 1970-01-01
  • 2014-11-27
  • 2019-02-04
相关资源
最近更新 更多