Published: Monday, January 24, 2000
Creating a Mailing List Program
By Hunter Powers
Have you ever wanted to create a mailing list on your site? Tired of
using those so-called free services that insert advertisements into all of your e-mails?
Well this is your lucky day. I have written a basic tutorial on how to
accomplish this task. Included with this article is all source code free to
download.
Part I - Database Design
This is pretty simple. First we create an Access database List.mdb. Then
we create a table, EmailList with two fields: ID and Email.
ID will be used as our primary key and Email will be used to store the e-mail
addresses.
Part II - An Insertion Script
Now that we have a database the second part is to create a database
insertion scrip to insert e-mail address into the database. The first part in
creating the insertion script is to create a generic database include script,
Datastore.inc. This script is responsible for simply establishing a connection
with the database.
<%
'DataStore.inc
'this page provides a generic database include script
' use this connect string for the Access tables
' change the following
' YourDB to the physical path
of your database
strConnect = "Driver={Microsoft Access Driver (*.mdb)}; DBQ=YourDB"
' use this connect string for a DSN data store
' change the following
' DSN=YourDSNName
'strConnect = "DSN=YourDSNName"
%>
|
Now that we have a database include script we can create our database insertion script,
AddUser.asp. Note that an the file ADOVBS.INC is included.
For all of you who don't know, ADOVBS.INC is a file that declares
various functions and variables to help deal with ActiveX Data Objects (ADO). It is
included with the source. There is also a good article on 4Guys about the issue:
ADOVBS.INC - Use It!
<!-- #INCLUDE FILE = "DataStore.inc" -->
<!-- #INCLUDE FILE = "adovbs.inc" -->
<%
'AddUser.ASP
'the purpose of this page is to add users to the database
%>
<%
'create variable to hold email address
DIM EMail
Email = Request.Form("EMail")
'create variable to hold database object and initialize it
Dim objRec
Set objRec = Server.CreateObject("ADODB.Recordset")
'open the database table EmailList
objRec.Open "EmailList", strConnect, adOpenStatic, _
adLockOptimistic, adCmdTable
'create a new record
objRec.AddNew
'set the field equal to the variable
objRec("EMail") = EMail
'update the database with the new record
objRec.Update
'close the database
objRec.Close
Set objRec = Nothing
'un-comment this line to point to your desired confirm page
'Response.Redirec("http://YourPageHere.com")
'tell the user their account is added
Response.Write("User Added")
%>
|
Now that we have a database insertion script we can create a simple page to post to our email addresses
with, Default.asp. Default.asp will use a Form into which the email address
can be entered. When the Form is submitted, AddUser.asp is called, adding the email address
to the database.
<%
'Default.asp
'A form example of how to post to the AddUser.asp script
%>
<html>
<head>
<title>Add user to list</title>
</head>
<body>
<form method="POST" action="AddUser.asp">
Enter your e-mail address: <input type="text" name="EMail" size="20">
<input type="submit" value="Add" name="B1">
</form>
</body>
</html>
|
Part III - A Web Based Admin
Okay, so now lets take a look at what we have created. We have created a database to hold our e-mail addresses
(List.mdb), a generic database include script (DataStore.inc), a script to add email addresses to
the database (AddUser.asp), and a page to post e-mail address to AddUser.asp
(Default.asp).
The next part in the creation of our Mailing List Program is to create administration pages. Some people like
to do things manually but I like nice, easy to use, web based admin pages. For the purpose of this tutorial
we will not worry about making everything attractive to the eye, but focus on making everything work.
There are three main functions that we want our admin pages to handle:
- List the current users
- Delete users, and
- (Most importantly) E-mail our users
Now, before we continue our journey to create a Mailing List Program I will speak to you about security.
I have placed all of the administrative files into an /admin folder off of the root. In order to secure
this program you need to either restrict access to this folder from the IUSR Account (if you don't know
what this is your ISP will), or edit the security.inc file with your desired security parameters.
Continue reading Part 2