Sign up form-optional checkbox to save email in a TXT file

Hi,
Right now my sign up form looks like this:

I want to make it like this:

Obviously I can make the design changes. Problem is I don’t know how to make it function as I need.

User will enter his Username, email, password. Accepting to Terms is compulsory.
IF he checks “Tell me about Contests”, then Click Submit, then the email he entered should be saved in a txt file in the server (one email per line).
If he doesn’t check it, then his email address will not be saved in a txt file.
I only need the email address. I don’t need username, password.

My objective is, I need to collect email addresses to send them updates, news, notifications about contests etc. This way I will get the email addresses of people who are willing to receive those emails.

My site is based on wordpress. So if someone can provide a sample code in php, I think I can substitute it with my site code.
Not sure if it matter, but I have a referral signup system, email confirmation/ account activation system in place.

Thanks

Well not sure about Wordpress or the name of your form fields. I will use email and subscribe.

<?php
if(isset($_POST['subscribe']) && !empty($_POST['email'])):
    $txtfilepath = "subscribers.txt";     
    $data = trim($_POST['email']).PHP_EOL;
    $fp = fopen($txtfilepath, 'a');
    fwrite($fp, $data);
endif;
?>

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.