Creating a Newsletter System
Get all the latest news and info about ColdFusion
01.22.03
Search iEntry News:

Hello ColdFusionProNews Readers!

Are you tired of people asking you what ColdFusion is good for? Do your unenlightened friends think it's a dry, esoteric database language? Well, the next time someone tells you ColdFusion is dull or outdated, point them to today's article by Pablo Varando. Follow his easy step-by-step instructions and you'll build yourself a fully functional, automated newsletter management system based on ColdFusion. The system lets users subscribe and unsubscribe automatically. Of course, you'll also need to think up content for your newsletter (ColdFusion doesn't handle that part). Enjoy the article! I hope you find it useful.

Developer Kit for Macromedia Dreamweaver MX FREE

Creating a Newsletter System

By Pablo Varando

This tutorials will show you how to create a fully automated system to allow visitors to subscribe and unsubscribe to your newsletter. It also shows the administration panel to mass mail all members. Let's Begin:

Here's what's involved.
1) Create the database
2) Create a page for people to sign up.
3) Create a page to unsubscribe.
4) Create a page to send newsletter.

First, lets create the database. Create a table called: Newsletter. Next, create the following fields.

Field Name
Field Type
MemberID
Autonumber
Name
Text
Email
Text
EmailType
Number

Once you have created the database, create a DSN pointing to the database by going to Data Sources (ODBC) in Administrative Tools on Windows. Now we need to create the actual pages...

Here's the code for the Subscribe and Unsubscribe Page.

Subscribe.cfm
<CFIF IsDefined("Email")>
<!--- Insert Member Information Into Database --->
<CFINSERT DATASOURCE="YourDSN" TABLENAME="Newsletter" Formfields="Name, Email, Subscribe, EmailType">

<CFOUTPUT>
Thank you #Name#,
Your email address [#Email#] Has been entered into our mailing list. You'll receive the next mailing!
</CFOUTPUT>

<CFELSE>
<!--- Prompt User To Enter information --->
<form action="Subscribe.cfm" method="post">
Name: <input type="Text" Value="" Name="Name"><BR>
Email: <input type="Text" Value="" Name="Email"><BR>
Receive in: Text <input type="Radio" name="EmailType" value="1">
HTML <input type="Radio" name="EmailType" value="0">
<input type="Submit" Value="Join Newsletter">
</FORM>
</CFIF>

The unsubscribe page:

unsubscribe.cfm
<CFIF IsDefined("Email")>
<CFQUERY DATASOURCE="YourDSN" NAME="Unsubscribe">
DELETE
FROM Newsletter
WHERE Email = '#Email#'
</CFQUERY>

FREE!! WebTrends Developer Kit for Macromedia® Dreamweaver® MX. -Build more effective sites by integrating web analytics into your development cycle.

<CFOUTPUT>
Thank you,<br>
Your email address [#Email#] Has been removed from our mailing list. You'll never receive mailing again!
</CFOUTPUT>

<CFELSE>
<!--- Display the unsubscribe form --->
<form action="unsubscribe.cfm" method="post">
Name: <input type="Text" Value="" Name="Name"><BR>
Email: <input type="Text" Value="" Name="Email"><BR>
<input type="Submit" Value="Join">
</FORM>
</CFIF>

Finally, we need to create a page to send newsletter:

SendNewsletter.cfm
<CFIF IsDefined("Message")>
<CFQUERY NAME="GetMembers" DATASOURCE="Your DSN">
SELECT *
FROM Newsletter
<CFIF Form.EmailType EQ "1">
WHERE EmailType = 1
<CFELSE>
WHERE EmailType = 0
</CFIF>
ORDER BY MemberID
</CFQUERY>

<CFLOOP QUERY="GetMembers">
<!--- Determine if email going out will be in HTML format or not --->
<CFIF #Form.EmailType# EQ "1">
<CFMAIL To="#GetMembers.Email#"
From="newsletter@mysite.com"
Subject="This Week's Newsletter!">

#FORM.Message#
Sent: #DateFormat(Now(), 'ddd. mmmm dd, yyyy')#
to Unsubcribe visit: http://www.mysite.com/unsubscribe.cfm

</CFMAIL>
<CFELSE>

<CFMAIL To="#GetMembers.Email#"
From="newsletter@mysite.com"
Subject="This Week's Newsletter!"
type="HTML">

#FORM.Message#
Sent: #DateFormat(Now(), 'ddd. mmmm dd, yyyy')#
to Unsubcribe visit: http://www.mysite.com/unsubscribe.cfm

</CFMAIL>
</CFIF>
</CFLOOP>

<CFELSE>
<form action="sendnewsletter.cfm" method="post">
The Message: <Textarea Name="Message"></textarea><BR>
Send as:
Text <input type="Radio" name="EmailType" value="1">
HTML <input type="Radio" name="EmailType" value="0"><br>
<input type="Submit" Value="Mail Newsletter">
</FORM>
</CFIF>

That's it! You've now created a fully interactive newsletter system for your site!

Originally published at http://tutorial14.easycfm.com/

EasyCFM.Com introduces at least three new tutorials each week, written by the webmaster (Pablo Varando) and also from individual people who post their own tutorials for visitors to learn from. For more information please visit: http://www.easycfm.com [EasyCFM is Hosted by Colony One On-Line - http://www.colony1.net]
Free Newsletters

Web Developers / Programmers
ColdFusionProNews
CProgrammingTrends
DesignNewz
DevNewz
DevWebPro.
DevWebProAU
DevWebProCA
DevWebProUK
FlashNewz
JavaProNews


















-- ColdFusionProNews is an iEntry, Inc. ® publication --
© 2003 iEntry, Inc. All Rights Reserved Privacy Policy and Legal
archives | advertising info | news headlines | free newsletters | comments/feedback | submit article