php redirect after form success
<p>Total noob here, be gentle.
Using php script to allow people to add their email to a mailing list. When it successfully writes the email to the .txt doc it displays a success message on a white page. I want it to redirect to a page I've designed to look like the rest of the site. I've read elsewhere that I need to use the header function, but I can't figure out where to put it since the preceding portion of my code contains outputs. I'd appreciate any guidance. Thanks.
I think this is the relevant code: </p>

<pre><code>// Write to file if email doesn't already exist
    if ($emailexists != "yes") {

        // Write to the list and give success message
        fwrite($fh, "$_POST[email]\n");
        $msg = "Your e-mail address $EmailFix was successfully added to the list!";
    }

    // Close the list
    fclose($fh);
}
</code></pre>

<p>Then this:</p>

<pre><code>// Show success message if there was one and end script, and no errors were encountered
} elseif (isset($msg)) {
echo "&lt;b&gt;" . $msg . "&lt;/b&gt;\n";
echo "&lt;/body&gt;\n";
echo "&lt;/html&gt;\n";
exit;
}
</code></pre>
