im trying to find a simple script i can embed in an html form on my website so that a user can enter their email address to receive updates/invites, and when they click submit it will write the text they input into a text file on the sever, with each entry separated by a semicolon... so that everytime i add new work to my site, i can copy/paste the most recent mailing list directly into my mail client... like so:
user@domain.com; user1@domain1.com; user2@domain2.com; etc
is this possible? anyone have a code that does this or, if not, advice on how to code this myself? much appreciated.
also, if it were possible to have the code check the database for duplicates, that would be helpful.
someone gave me the following code to start, but im having problems with it:
<?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=\"0;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>
here are my questions:
- what url goes in the <form action="(url)" method="post"> tag?
- does the script autocreate a text file called "emails.phplist" or do i need to create one? if so, how do i do that and do i store it in the same directory folder?
- the php script is showing up on the html page, why is that? should i make the script external and link to that url in the form action??
- where do i make the url for the redirect page?
thanks again, sorry if these are dumb questions.