PHP
  Home arrow PHP arrow Page 3 - Creating a Mailing List Manager with P...
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Mobile Linux 
App Generation ROI 
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: 5 stars5 stars5 stars5 stars5 stars / 39
    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:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb 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


       · The code have lot of little mistakes.
       · No it doesn't whoever posted that comment above needs to get a clue.
     

       

    PHP ARTICLES

    - Working With Different Namespaces in PHP 5
    - User Management Explained: Overview
    - Using Namespaces in PHP 5
    - Database Security: Guarding Against SQL Inje...
    - Building a Modular Exception Class in PHP 5
    - Database and Password Security for Web Appli...
    - Handling MySQL Data Set Failures in PHP 5
    - Building Site Registration for Web Applicati...
    - Intercepting Customized Exceptions in PHP 5
    - Securing Your Web Application Against Attacks
    - Sub Classing Exceptions in PHP 5
    - Authentication for Web Application Security
    - Building a Content Management System with Co...
    - Filters and Login Systems for Web Applicatio...
    - Working with the Email Class in Code Igniter





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
    Stay green...Green IT