Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP Forms Question

Status
Not open for further replies.

bad959fl

Technical User
Jun 16, 2005
11
US
Hello,

I'm currently using a basic formmail.pl script for the forms on my website. I have a newsletter signup option on all of my forms for visitors to subscribe. Up until now, I have been importing the email addresses and names into a text file for my mailing list. I basically copy and paste each entry. Since the newsletter is reaching 2,000 entries and the signup have been increasing every day, this is becoming a major burden on managing.

I would like to get some assistance for creating a PHP form which will do all of these tasks:

1. Only capture email address and first name for visitors who check the newsletter signup box.
2. Output the visitors email address and name into a flat file on the server.
3. Format the email and name like this:

"anyone1@email.com","Name"
"anyone2@email.com","Name"
"anyone3@email.com","Name"

4. Check and make sure any duplicate email addresses will not be added to the text file.

You can review one of my current forms here:


Any help would be greatly appreciated.

Thanks!
 
I am surprised you are not using a majordomo application like Mailman to handle the newsletter list.

But, anyway - the script you want to write is quite simple.
1. Capturing the e-mail address and firstname from input in the form is done anyway (they are all in $_POST. The code will have to check for the presence of the checkbox value and do what's step 2 and 3.
2. I would do your step #3 befor committing it to the file.
Formatting is quite easy.
Code:
$line= '"'.$_POST['email'].'","'.$_POST['name'].'"'."\n";
Validation of the proper e-mail format would be good, also checking that no offending characters are in the name (some idi** may type in double quotes etc.).
3. You'll have to open the file and read it. There's no way around that if you use a flat file. A regular expression (preg_match()) will make sure it's not in there yet.
Then append to the end and write out the file.
With 2000 records a database might be quite helpful, as you can search and ascertain quickly if the e-mail address is already enrolled.
The flat file - if needed by the mail software - can easily produced just before the softeware send the newsletter.

These are the basic ideas. If you need more concrete help, let us know.
 
DRJ478-

Thanks for the info. I have a sample script which I have had help with and been working on for the last few days. I just posted it on this forum. I'm having a hard time receiving specific info from the form.

If you have a sec, can you check it out?

Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top