Jump to content

looking for code examples for creating subscriber list text file


LoboTechServ

Recommended Posts

Hi,

I'm working on creating a script that will add email address from an html form into a text file and then allow the user to opt-out from another form. Not to familiar with working with text files in PHP. Any code examples would be helpfull, just point me to a good source, Thanks.

Lobo
Hi,

I hope this helps. If not come back to me.

Your form should look like this. Create a file called form.htm and put this in it.
[code]
<form action="form.php" method="post">
<input type="text" name="name"> Your name<br>
<input type="text" name="email"> Your email<br>
<input type="checkbox" name="agree" checked>Yes! Put me on the list!<br>
<input type="submit">
[/code]

Your php page should look like this. Create a file called form.php and put this in it.
[code]
<?php

//This section will add all the data to a text file called data.txt
$file = 'data.txt';
$fh = fopen($file, 'a') or die ('Cant open file'); //Use W to write to a new file A to append
fwrite($fh, "$name . $email . $agree") or die ('cant write to file');
fclose($fh);

//This section checks to see if the checkbox is ticked. If yes it will add the data to the second file, data2.txt
if ($agree = "on") {
$file = 'data2.txt';
$fh = fopen($file, 'a') or die ('Cant open file'); //Use W to write to a new file A to append
fwrite($fh, "$name . $email . $agree") or die ('cant write to file');
fclose($fh);
} else {
echo "The data was not added to the second file";
}
?>
[/code]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.