views:

42

answers:

2

I need to create a mailing list for an Alumni site I am building. Below is how I'd ideally like the mailing list to function.

The User
The user would go to the website, enter their email address (and possibly First/Last name) into the field(s), click on the Subscribe button and then get a verification message (either via pop up, redirect, or email message).

The Site Manager
Each email address (and name) that has successfully subscribed would be compiled into a text document on the server or a group email address. The manager could then either log-in with an admin password to send a bulk email to the subscriber list (ex. http://justincross.net/stuff/join2.php) OR the admin could just email the list from a G-Mail account.

Does anyone know how to do this effectively? I've searched for days for a tutorial/template but the very few I've tried seem to be either broken, or using a mySQL (which I'd prefer not do).

Thanks in advance!

+1  A: 

Use this: http://www.phplist.com/ .. the best in the market and very adaptive !

Stewie
Much appreciated. Not sure how I overlooked that resource when I began looking around...
Justin Cross
+1  A: 

The database way is, indeed, the best one. If you rather use the text file approach i would suggest something like this:

Inserting Data into the file

$email = "the email";
$firstName = "the first name";
$lastName = "the last name";

$new_line = "$email|$firstName|$lastName\n"; // |  could be other character

$file = fopen("subscribers.txt", "a");
fputs($file, $new_line);
fclose($file);

Reading and Parsing Data

$subscribers = array();

$handle = @fopen("subscribers.txt", "r");
if ($handle) {
    while (!feof($handle)) {
        $line = fgets($handle, 4096);

        //parsing the line
        $ar = explode('|', $line);

        //$ar[0] holds the email
        if(key_exists(0, $ar)){
          $email = $ar[0];
        }else{
          $email= '';
        }

        //$ar[1] holds the first name
        if(key_exists(1, $ar)){
          $firstName = $ar[1];
        }else{
          $firstName = '';
        }

        //$ar[2] holds the last name
        if(key_exists(2, $ar)){
          $lastName = $ar[2];
        }else{
          $lastName = '';
        }

        $temp = array(
          'email' => $email,
          'firstName' => $firstName,
          'lastName' => $lastName
        );

        $subscribers[] = $temp;
        //

    }
    fclose($handle);
}

For looping through the subscribers and using you function to send email

foreach($subscribers as $subscriber){
    //the email
    $subscriber['email'];

    //the firstname
    $subscriber['firstName'];

    //the lastname
    $subscriber['lastName'];
}
Mario Cesar
Thanks, Mario! Gonna take a look at this and see how it works out!
Justin Cross