简体   繁体   中英

PHP form processor script not redirecting

i am making an html contact form with PHP processor script. Here is my code

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

<?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. But i not getting redirected back to contact.php (i have tried using index.php also and even 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. 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. 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"); and that file is not getting included.

header("Location:contact.php"); should be 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 )

Plese Try bellow code, you need to give space between Location: and Contact.php

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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