<?php
$ourFileName = "emaillist.txt";
$email=$_POST['email'];
if ($email!='') {
// add a line break to have only one e-mail address per line
$input = $email . "\n";
// opening with fmode w will overwrite the file every time you write a new e-mail address
$ourFileHandle = fopen($ourFileName, 'a') or die("can't open file");
// use fwrite to make use of the open file. Closing it and reopening it for file_put_contents()
// are unnecessary file operations
fwrite($ourFileHandle, $input);
fclose($ourFileHandle);
header ('Location:
http://www.example.com/thankyou.php');
}
?>