PHP
  Home arrow PHP arrow Page 3 - Creating a Mailing List Manager with PHP
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

Creating a Mailing List Manager with PHP
By: Duncan Lamb
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 44
    1999-12-16


    Table of Contents:
  • Creating a Mailing List Manager with PHP
  • Creating the front page
  • Adding names to the list
  • Editing the names
  • Autoresponders
  • Conclusion

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Creating a Mailing List Manager with PHP - Adding names to the list
    ( Page 3 of 6 )


    Here, we’ll automate the process of adding a name to the list:

    addnames.php3


    <html><head><title>Add an email to the list</title></head><body> <br><br> <form method=post action="saveemail.php3"> <table><tr><td valign=top> Which List?: </td><td> <select name="List" size=4> <? $fileloc = "lists.txt"; $groups = file("data/lists.txt"); for ($index=0; $index < count($groups); $index++) { $grouplist = split("\|", chop($groups[$index])); ?> <option value="<? echo $grouplist[1] ?>" <? if ($index==0) {echo "selected";} ?>> <? echo $grouplist[0] ?><br> <? } ?> </select></td></tr></table> Email Address:<input type=text name="Email" size="40"> <br><br> <input type="submit" Value="Add This Email"></FORM> <BR><BR><a href="./">Home</a>. <br><br><a href="picklist.php3">Edit/Delete names</a>. <br><br><a href="data/log.txt">View Send Log</a>. <br> </body></html>
    First, a list is chosen in lines 7-21 (this is the same function used on the index page), and then it and the email address is passed to the next script:

    saveemail.php3

    <html><head><title>Updating file....</title></head><body> <br><br> <? if (file_exists("data/$List")) { $myfile = file("data/$List"); $fh = fopen("data/$List","w"); for ($index=0; $index < count($myfile); $index++) { if ($Email != chop($myfile[$index])) {fputs($fh,$myfile[$index]);} } fputs($fh,$Email."\n"); fclose($myfile); } else { $myfile = fopen("data/$List","w"); fputs($myfile,$Email."\n"); fclose($myfile); } ?> <br> <? echo $Email ?> written to <? echo $List ?> <br><br> <a href="index.php3">Home</a>. </body></html>
    After making sure the file exists, the first thing this script does is read the current list into an array (lines 4-6), then checks for each name to see if it already exists in the list (no one likes being on the same mailing list TWICE!). It does this in lines 8-12 by writing each name back into the file, and just skipping the name if it already exists. Once every name is compared, the new name is written at the end of the file.

    You’ll notice that fopen uses "w" here, for writing, while it used "r" on the index page (for reading) and "a" is used on the Send Email page(for appending to an existing file). The format for the command is:

    fopen (filename, mode)

    With mode being either "r", "w", or "a". Writing an existing file erases the current contents, while appending starts writing at the end of the file. Each of these modes can allow both reading and writing by placing a "+" after the mode. But the initial state (whether the current contents are deleted, and where the initial pointer is) will still occur.

    Note: If you are going to open a file for reading and writing simultaneously, nasty things can happen that can destroy data in other files if a problem occurs. Good programming practice dictates you should modify a file by reading it into an array, closing the file connection (which file does automatically), making the modifications, and writing the changed contents back to the file.

    Adding lists uses the same technique, Just joining the List and Filenames together with a "|". Here’s the scripts used for to add a list to your collection:

    newlist.php3

    <html><head><title>Mailing List Administration</title></head><body> <br> <b>Both blanks must be filled in!</b><br> <form method=post action="makenewlist.php3"> <b>Name of the list:</b><input type=text name="Listname" size="40"> <br><br> <b>One word description of the list:</b> <input type=text name="Filename" size="40"> </td><td><table><tr><td valign=top> <br><br> <input type="submit" name="Submit" value="Make list"> </form> <br><br><a href="addnames.php3">Add names to an existing list</a>. <br><a href="picklist.php3">Edit/Delete names</a>. <br><br><a href="data/log.txt">View Send Log</a>. <br> </body></html>


    <html><head><title>Updating file....</title></head><body> <? $Filename = $Filename.".lst"; $myfile = fopen("data/lists.txt","a"); fputs($myfile,$Listname."|".$Filename."\n"); fclose($myfile); ?> Created new list <? echo $Listname ?>.<br> <br><br><a href="index.php3">Home</a>. <br><br><a href="addnames.php3">Add names to the list</a>. <br><br><a href="picklist.php3">Edit/Delete names</a>. <br><br><a href="data/log.txt">View Send Log</a>. <br> </body></html>


     
     
    >>> More PHP Articles          >>> More By Duncan Lamb
     

       

    PHP ARTICLES

    - Building Dynamic Queries with Chainable Meth...
    - PHP Encryption and Decryption Methods
    - Building a MySQL Abstraction Class with Meth...
    - Completing a Sample String Processor with Me...
    - Mastering WHILE Loops for PHP and MySQL
    - Method Chaining: Adding More Methods to the ...
    - Method Chaining in PHP 5
    - The Role of Interfaces in Applying the Depen...
    - Dependency Injection: Using a Setter Method ...
    - Using a Model Class with the Dependency Inje...
    - Injecting Objects Using Setter Methods with ...
    - Injecting Objects by Constructor with the De...
    - The Dependency Injection Design Pattern in P...
    - Performing Inferential Statistical Analysis ...
    - Performing Descriptive Statistical Analysis ...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
    Stay green...Green IT