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