Creating a Newsletter system

Registration

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>

<CFOUTPUT>
<CFIF Unsubscribe.recordcount GTE "1">
Thank you #Name#,
Your email address [#Email#] Has been removed from our mailing list. You'll never receive mailing again!
<CFELSE>
We're sorry, your email address could not be found! <a href="Javascript:history.go(-1)">try again</a>?
</CFIF>
</CFOUTPUT>

<CFELSE>

<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>

You might also like...

Comments

About the author

Pablo Varando United States

I've been around computers ever since I could remember, The first time I toyed around with a computer, I was about 3 years old. I ran my own BBS service in Miami from age 7 to 13 and I found it ...

Interested in writing for us? Find out more.

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Nine people can't make a baby in a month.” - Fred Brooks