简体   繁体   English

PHP表单处理器脚本未重定向

[英]PHP form processor script not redirecting

i am making an html contact form with PHP processor script. 我正在用PHP处理器脚本制作html联系人表格。 Here is my code 这是我的代码

HTML HTML

    <form enctype="multipart/form-data" action="contactprocessor.php" method="post" class="wpcf7-form" onSubmit="return validatePage1();">
      <div class="form-row">
        <label class="label">Name*</label>
        <span class="wpcf7-form-control-wrap name">
        <input type="text" id=field_1 name=field_1 value="" size="40" class="wpcf7-form-control wpcf7-text wpcf7-validates-as-required text-input" aria-required="true" placeholder="Introduce yourself" />
        </span></div>
      <div class="form-row">
        <label class="label">Company</label>
        <span class="wpcf7-form-control-wrap company">
        <input type="text" name=field_2 id=field_2 value="" size="40" class="wpcf7-form-control wpcf7-text text-input" placeholder="Fly your company flag" />
        </span></div>
      <div class="form-row">
        <label class="label">Email* </label>
        <span class="wpcf7-form-control-wrap email">
        <input type="email" name=field_3 id=field_3 value="" size="40" class="wpcf7-form-control wpcf7-text wpcf7-email wpcf7-validates-as-required wpcf7-validates-as-email text-input" aria-required="true" placeholder="Help us keep in touch" />
        </span></div>
      <div class="form-row">
        <label class="label">Phone</label>
        <span class="wpcf7-form-control-wrap phone">
        <input type="tel" name=field_4 id=field_4 value="" size="40" class="wpcf7-form-control wpcf7-text wpcf7-tel wpcf7-validates-as-tel text-input" placeholder="If you fancy a chat" />
        </span></div>
      <div class="form-row">
        <label class="label">Subject*</label>
        <span class="wpcf7-form-control-wrap subject">
        <input type="text" name=field_5 id=field_5 value="" size="40" class="wpcf7-form-control wpcf7-text text-input" placeholder="What’s on your mind?" />
        </span></div>
      <div class="form-row">
        <label class="label">Message*</label>
        <span class="wpcf7-form-control-wrap message">
        <textarea name=field_6 id=field_6 cols="40" rows="14" class="wpcf7-form-control wpcf7-textarea wpcf7-validates-as-required" aria-required="true" placeholder="Share your thoughts and comments"></textarea>
        </span></div>
      <div class="form-row">
        <input id="saveForm" type="submit" value="Get In Touch" class="wpcf7-form-control wpcf7-submit btn--invert" />
      </div>

    </form>

Here is the contactprocessor.php code 这是contactprocessor.php代码

<?php

  mail("jen@abhayayks.com",$_POST['field_5'],

  "Form data:

   Name: " . $_POST['field_1'] . "
   \nEmail: " . $_POST['field_3'] . " 
   \nPhone : " . $_POST['field_4'] . " 
   \nCompany : " . $_POST['field_2'] . "  
   \nMessage : " . $_POST['field_6'] . " 

    ");

    header("Location: contact.php");

   ?>

Now when i submit the form, i am receiving the mail confirming that PHP script is working. 现在,当我提交表单时,我收到确认PHP脚本正在工作的邮件。 But i not getting redirected back to contact.php (i have tried using index.php also and even http://www.google.com ). 但是我没有重定向回contact.php(我也尝试过使用index.php甚至http://www.google.com )。 Can you please point out the mistake? 您能指出错误吗?

Edit: Now, i have switched on error log and error reporting from php.ini file, have restarted my local server, ran the script, got the mail, again not redirecting, no error in error log file. 编辑:现在,我从php.ini文件打开了错误日志和错误报告,重新启动了本地服务器,运行了脚本,收到了邮件,再次没有重定向,错误日志文件中没有错误。 I have uploaded the files on my online server. 我已将文件上传到在线服务器上。 You can confirm the issue. 您可以确认问题。 Link 链接

Edit 2 I just have noticed that nothing is working except the mail function. 编辑2我只是注意到,除了邮件功能之外,其他任何功能都没有起作用。 I mean have tried using 我的意思是尝试使用

echo '<script type="text/javascript">window.onload = function(){ alert("Thank you");}</script>';

and this is also not working. 而且这也不起作用。 I have also tried including some other file using include("confirm.html"); 我也尝试过使用include(“ confirm.html”);包含其他文件。 and that file is not getting included. 并且该文件未包含在内。

header("Location:contact.php"); 标题( “位置:contact.php”); should be header("Location: contact.php"); 应该是header(“ Location:contact.php”);

It seems that code is correct 似乎代码是正确的

Did you check your error log ? 您检查错误日志了吗?

What charset encoding is your file? 您的文件使用哪种字符集编码? ( There are problem if file is UTF-8 with BOM when browser can't send headers after BOM go to the output stream ) (当BOM表转到输出流后浏览器无法发送标头时,如果文件是带有BOM表的 UTF-8 则会出现问题)

Plese Try bellow code, you need to give space between Location: and Contact.php 请尝试下面的代码,您需要在Location:和Contact.php之间留出空格

<?php
header("Location: contact.php");
exit();
?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM