You have a few things you'll need to update here:
Form elements need to have different names, so you can differentiate between them in the PHP server-side code. Something like this:
<form action="emaillist.php" method="post">
<input type="text" name="email" />
<br />
<br />
<input type="submit" name="emailSubmit" value="submit" />
<br />
</form>
You need to wrap your server-side code in a conditional to make sure it's a form post. Currently, when you first load this page, it's going to write to the file. But there's no content until you post back to the page again with the form data. So you need to check if it's a form post. A common way to do this is to check for the presence of the submit button in the post data:
if (isset($_POST["emailSubmit"])) {
$file = fopen("emaillist.txt","a+");
fwrite($file,$email);
fclose($file);
print_r(error_get_last());
}
Just to confirm, since you say you're new to PHP... You're expecting the file to be written on the server and not on the client, correct?
To redirect to another page, you can simply set the location header in the server-side PHP code. This needs to be done before any content is emitted to the client. Since you only want this to happen on a post event, it should be in the same conditional as before:
if (isset($_POST["emailSubmit"])) {
$file = fopen("emaillist.txt","a+");
fwrite($file,$email);
fclose($file);
print_r(error_get_last());
header("Location: http://www.yoursite.com/newPage.php") ;
}
register_globalsbeing activated. it is not a deprecated and REMOVED mis-feature in PHP. your code is also trying to append to that file, whether a POST was actually performed or not...<form name="email"and<input type="submit" name="email" value="submit">. For starters, rename your<form nameto something else.