Include the following php code at the VERY TOP of your page:
PHP Code:
<?php
if ($email = stripslashes($_POST['email'])) {
$filename = "emails.phplist";
$filecontents = @file_get_contents($filename);
if ($_POST['choice'] == "join") {
if (strpos($filecontents) != "") break;
if (strlen($filecontents) > 0) $comma = ", ";
$add = $comma.$email;
$emails = $filecontents.$add;
$file = @fopen($filename, "w+");
@fwrite($file, $emails);
@fclose($file);
$message = "Your email was added to the mailing list.".
"<br>Redirecting to the last page.";
}
elseif ($_POST['choice'] == "leave") {
$edited = str_replace($email,"",$filecontents);
$file = @fopen($filename, "w+");
@fwrite($file, $edited);
@fclose($file);
$message = "Your email was removed from the mailing list.".
"<br>Redirecting to the last page.";
}
}
if ($message != "") die("<html><head>".
"<meta http-equiv=\"refresh\" content=\"3;url=\">".
"</head><body>".$message."</body></html>");
?>
<!-- YOUR HTML GOES BELOW HERE -->
HTML Code:
<!-- THEN JUST INCLUDE THE FOLLOWING SOMEWHERE IN YOUR BODY SECTION -->
<form action="" method="post">
Join our newsletter!<br>
Email: <input type="text" name="email"><br>
<select name="choice">
<option value="join">Join</option>
<option value="leave">Leave</option>
</select>mailing list.<br>
<input type="Submit" value="Go!">
</form>
Random note... after writing this, i've decided there must be a better way to write scripts than in the post window 
Ok... gotta run. This should work, but I haven't tested it yet...
I'll check back when I get a chance.
EDIT: Fixed two errors in the code.
Bookmarks