0

I have a php from that includes the external process.php, which handles all my validation and sending the mail function and submits to it self by setting
action="<?php echo $_SERVER['PHP_SELF'] ?>"
Everything works great, it validates properly and mails the form to my email, but when I try to include the header("location: thanks.html") to redirect after submit, it doesn't redirect. Am I doing this incorrectly or is it an issue with self-submitting the form? I'm also using Jquery and Jquery Mobile. Any help is appreciated

Heres my php

<?php 
if(($_SERVER['REQUEST_METHOD'] =='POST') && (!empty ($_POST['action']))):

if (isset ($_POST['myname'])){$myname=$_POST['myname'];}
if (isset ($_POST['myphone'])){$myphone=$_POST['myphone'];}
if (isset ($_POST['myemail'])){$myemail=$_POST['myemail'];}
if (isset ($_POST['job'])){$job=$_POST['job'];}
if (isset ($_POST['comments'])){
    $comments= filter_var($_POST['comments'], FILTER_SANITIZE_STRING);}

$formerrors = false;



      if($myname === '') :
      $err_myname = '<div class="error"> Sorry, your name is rquired</div>';
      $formerrors=true;
      endif;    

      if($myphone === ''):
      $err_myphone = '<div class="error"> Sorry, your phone number is rquired</div>';
      $formerrors=true;
      endif;    

      if($myemail === ''):
      $err_myemaile =  '<div class="error"> Sorry, your email is rquired</div>';
      $formerrors=true;
      endif;    

      if($job === ''):
      $err_job =  '<div class="error"> Sorry, your business is rquired</div>';
      $formerrors=true;
      endif;    



if (!($formerrors)) :
$to = "myemail@emial.com";
$subject = " Request from $myname --Show and Tell";

$message = "A new show and tell request from:\n
            $myname \n
            $myemail\n
            $myphone\n
            $job\n
            $comments\n";
$replyto = "From: $myemail";


if(mail($to, $subject, $message)):
    $msg ="Thanks for filling out our form";
    header('location: http://localhost/thanks.html');
    else:
    $msg = "There was a problem sending the message";
    endif; //mail data

endif; //check errors

endif; //form submitted

?>

And my html

<div data-role="content">
<?php if (isset($msg)) { echo '<div id="formmessage"><p>', $msg, '</p> </div>';}?>
<form id="form" action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post">
  <li data-role="fieldcontain">
    <label for="myname">Your Name*:</label><br>
    <input type="text" name="myname" id="myname" placeholder="John Smith" value="<?php if (isset($myname)) {echo $myname;}  ?>" required/>
    <?php  if (isset($err_myname)) {echo $err_myname;} ?>
  </li>

    <li data-role="fieldcontain">
    <label for="myemail">Email*:</label><br>
    <input type="email" name="myemail" id="myemail" placeholder="jsmith@email.com" value="<?php if (isset($myemail)) {echo $myemail;}  ?>"  />
    <?php  if (isset($err_myemail)) {echo $err_myemail;} ?>
    <?php  if (isset($err_wrong)) {echo $err_wrong;} ?>
  </li>

    <li data-role="fieldcontain">
    <label for="myphone">Phone number*:</label><br>
    <input onblur="formatPhone(this);" type="tel" name="myphone" id="myphone" placeholder="1234567890"   value="<?php if (isset($myphone)) {echo $myphone;}  ?>"  required/>
    <?php  if (isset($err_myphone)) {echo $err_myphone;} ?>
  </li>

      <li data-role="fieldcontain">
    <label for="job">Name of Business*:</label><br>
    <input  type="text" name="job" id="job" placeholder="Where do you work?"   value="<?php if (isset($job)) {echo $job;}  ?>"  required/>
    <?php  if (isset($err_job)) {echo $err_job;} ?>
  </li>


    <li data-role="fieldcontain">
      <label for="comments">Comments:</label><br>
      <textarea cols="40" rows="8" name="comments" id="comments" placeholder="Questions or Comments?">
      <?php if (isset($comments)) {echo $comments;}?>
      </textarea>

    </li>

<div data-inline="true" data-type="horizontal">
<input name="Reset" type="reset" value="Reset" data-role="button" data-inline="true" />

<input type="submit" value="Submit" data-role="button" 
data-inline="true" name="action" />


</div>


</form>



</div>
4

1 回答 1

2

1/简单的测试,你确定你没有空格或任何其他字符之前发送header()

2/ 你检查你有没有http://www.php.net/manual/en/outcontrol.configuration.php#ini.output-buffering选项?(否则您必须显式启动输出缓冲)

于 2013-07-24T15:58:33.443 回答