CoverYourASP --> utils/Newsletter.asp" --> Source

Free membership

Join in the fun! Sign in
Member Services

Site navigation
Download the entire site!
Search my articles
Free Magazines
Browse the directory

Send me feedback
Buy my boxer shorts

Recommend this page
Printer-friendly page

Resources I recommend
Link to my site
Advertising slashed!
About your privacy
Legal stuff
Site statistics
42 active users
779 visitors today
1204 pages today
(only part of today)
Tools I use

CoverYourASP
Copyright © 1999-2013 James Shaw.
All rights reserved.

ASP.NET Blog
RSS submissions
E-commerce

Now open source with SourceForge!

This page shows the actual source code used on this site. If this is the first CYA source code you've seen you should read this overview first.

Did you know you can download all the source code (and the database) of this site? Then get my newsletter to be emailed when I update the source code!

Please spread the word by recommending my site to your friends and colleagues!

This is JScript (server-side JavaScript), not the more common VBScript. More...

utils/Newsletter.asp

<%
// ============================================
// add email to database
// ============================================
function AddEmail ( sEmail )
{      
   // open the connection
   DBInitConnection ( );

   // first see if they are already subscribed
   DBGetRecords ( 'SELECT Email FROM MailingList WHERE Email=\'' + DBEncode ( sEmail ) + '\'' );

   if ( !oRecordSet.EOF )
   {
      Out ( '<h5><font color="red">' + sEmail + ' is already subscribed to my newsletter!</font></h5>' );
      return;
   }

   // this section needs more work - what should be done is that an email is
   // sent to the email address, and only added to the database when I
   // get a reply. that way I know the address is valid and the recipient
   // really wants to join the list. for now though, I'll add to the db now,
   // and if it bounces I'll remove it.
   if ( oConnection )
      oConnection.Execute( 'INSERT INTO MailingList (Email) VALUES (\'' + DBEncode ( sEmail ) + '\');' );

   // free the connection
   DBReleaseConnection ( );

   Out ( sEmail + ' has been successfully subscribed to my newsletter. ' );
   Out ( '<p>You will now receive an email whenever I write new articles, or if I make an important update to any.' );

//   SendEmail ( 'Newsletter@' + sHostDomain, sEmail, '', 'Subscribed to the CoverYourASP Newsletter', 'You have successfully subscribed to the newsletter at CoverYourASP. If you didn\'t request this please reply to this email and tell me so, or visit http://' + sHostDomain + '/subscribe.asp to unsubscribe.\n\nThank you.\n\nJames Shaw\nhttp://CoverYourASP.com/' );
}


// ============================================
// remove email from database
// ============================================
function RemoveEmail ( sEmail )
{      
   // open the connection
   DBInitConnection ( );

   // first see if they are already subscribed
   DBGetRecords ( 'SELECT Email FROM MailingList WHERE Email=\'' + DBEncode ( sEmail ) + '\'' );

   if ( oRecordSet.EOF )
   {
      Out ( '<h5><font color="red">' + sEmail + ' isn\'t subscribed to my newsletter!</font></h5>' );
      return;
   }

   // delete from the database
   oConnection.Execute( 'DELETE FROM MailingList WHERE Email=\'' + DBEncode ( sEmail ) + '\';' );

   // free the connection
   DBReleaseConnection ( );

   Out ( sEmail + ' has been successfully removed from my newsletter.' );
   Out ( '<p>You have been sent a confirmation email, but after that you will not receive any more emails.' );

//   SendEmail ( 'Newsletter@' + sHostDomain, sEmail, '', 'Unsubscribed from CoverYourASP Newsletter', 'You have been successfully removed from the newsletter at CoverYourASP. If you didn\'t request this please reply to this email and tell me so, or visit http://' + sHostDomain + '/subscribe.asp to re-subscribe.\n\nThank you.\n\nJames Shaw\nhttp://CoverYourASP.com/' );
}
%>

Hopefully much of this is self-explanatory. If not, or if you see ways that I can improve the code, please drop me a line.

To see the source code for this page, click on the icon below.

Featured sponsor
My favorite resources


New Proposal Kit Professional 5.1
Brand yourself as a top professional: create quotes and amazing proposals and get many legal documents free!

The latter saved me 3 times the purchase price on the first day I owned it!

CoverYourASP Mugs, T-shirts, caps - even Boxer shorts...
I don't make a penny from these, but they're a lot of fun! Don't you need a new mouse mat?


I share my content

Supporting ASPRSS

Do you need a quick and easy way to link to my articles? All the information you need is published with ASPRSS...


Qualify for Free Trade Magazines

Free subscriptions to industry leading publications for those who qualify!


See my source code
wherever you see this icon...

You can also download the entire site source code for FREE!