联系表单+重定向不起作用

I made a simple "name and email" contact form and I would want it to redirect to "page2.html" after the information has been submitted.

I cant get it to work.

This is the html part I made for the submission form. Im still not sure what does "name" part stand for, the id part (with the dash) refers to CSS styling. But anyhow, this is how I made the contact "name and email" form.

<form method="post" action="submission.php" name="contactform" id="contact-form">
        <fieldset>
        <label for=name accesskey=U><span class="required">*</span> Name</label>
        <input name="name" type="text" id="name" size="30" value="" /> 
        <br />
        <label for=email accesskey=E><span class="required">*</span> Email</label>
        <input name="email" type="text" id="email" size="30" value="" />
        <br />
        <input type="submit" class="submit" id="submit-button" value="Submit" />
        </fieldset>        
</form>

and php part is recycled, i tried entering header with redirect in the last line but it doesnt work, the best it does is opens up a blank page in the browser that prints out the info I entered in the form.

I would like to have the form redirect after the info has been submitted, so...thanks for help, in advance :D

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="jquery-1.3.2.min.js"></script>
<script src="http://www.google.com/jsapi"></script>
<script type="text/javascript">google.load("jqueryui", "1.5.2");</script>
<? 
if($_POST['name']!="" ){


    $headers    = "From: Webmaster";
    $message    = 
  strtoupper($_POST['name'])."
".strtoupper($_POST['email'])."
";
    echo str_replace("
","<br />", $message);
    $headers2   = "From: Sender Name <email@gmail.com>
Content-Type:     text/plain; charset=UTF-8; format=flowed
MIME-Version: 1.0
Content-Transfer-Encoding:     8bit
X-Mailer: PHP
";
    $message2   = "Message
";

    mail("webmaster@gmail.com", "Subject", $message, $headers);
    mail("$_POST[email]", "Subject", $message2, $headers2);

    $myFile = "submissions.txt";
    $fh = fopen($myFile, 'a') or die("can't open file");
    $stringData =     "$_POST[name]*$_POST[email]*".$_SERVER['REMOTE_ADDR']."*".date("d-m-Y H:i")."
";
    fwrite($fh, $stringData);
    fclose($fh);

} else {
    echo "You didnt enter anything";
    ?>
    <script language="javascript">
    alert("You didnt enter anything");
    </script>
    <?
}
?>

The name attribute in the form will give the $_POST array is name. E.g., using

<input type="text" name="awesometext"/>

in a form with method="post" will make the value of that text field accessible through $_POST['awesometext'] in the php script you define in the form's action.

If after sending the email you want to redirect the user to another page using header(), no output must be generated on the page before that. Get rid of all echoes and html output, so remove the html you have at the beginning. You may only have php code without output if you want to use header().

Then you can use header('Location:somepage.php'); to direct to somepage.php.

Your code would then be:

<?php 
if($_POST['name']!="" ){


$headers    = "From: Webmaster";
$message    = 
strtoupper($_POST['name'])."
".strtoupper($_POST['email'])."
";
echo str_replace("
","<br />", $message);
$headers2   = "From: Sender Name <email@gmail.com>
Content-Type:     text/plain; charset=UTF-8; format=flowed
MIME-Version: 1.0
Content-Transfer-Encoding:     8bit
X-Mailer: PHP
";
$message2   = "Message
";

mail("webmaster@gmail.com", "Subject", $message, $headers);
mail("$_POST[email]", "Subject", $message2, $headers2);

$myFile = "submissions.txt";
$fh = fopen($myFile, 'a') or die("can't open file");
$stringData =     "$_POST[name]*$_POST[email]*".$_SERVER['REMOTE_ADDR']."*".date("d-m-Y H:i")."
";
fwrite($fh, $stringData);
fclose($fh);

//header here
header('Location:somepage.php');

} else {
echo "You didnt enter anything";
?>

The header() needs to be called before any output is generated. The code above should work.

$a = mail("webmaster@gmail.com", "Subject", $message, $headers);
$b = mail("$_POST[email]", "Subject", $message2, $headers2);

if($a && $b)
{
  echo '<script>document.location="page2.html"; </script>'
}

you cant send php redirect headers if you have anyoutput in your script. either change your php part to the top of the page but you can do in php

header("location:page2.html"):

or use javascript redirect in php

echo '<script>document.location="page2.html"; </script>';