PHP表单邮件重定向页面无法正常工作

时间:2017-05-31 04:36:31

标签: php html forms email phpmailer

表单有效,我收到了电子邮件,但是当您点击提交时,它不会带您到感谢页面,它会给我以下错误消息:

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>
&#13;
&#13;
&#13;

这是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旁边。但不知何故不起作用......任何想法为什么?

2 个答案:

答案 0 :(得分:0)

您要做的是重定向到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=来修复它。

答案 1 :(得分:0)

deprecated ereg()功能preg_match()

使用此

<强> preg_match()