if ( sEmail.search ( /\w+((-\w+)|(\.\w+)|(\_\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0- 9]+)*\.[A-Za-z]{2,5}/ ) != -1 )
return true;
else
return false;
}
// ============================================
// add email to database
// ============================================
function AddEmail ( sEmail )
{
// open the connection
DBInitConnection ( );
// first see if they are already subscribed
var sSQL = 'SELECT Email FROM MailingList WHERE Email="' + sEmail + '";';
DBGetRecords ( sSQL );
if ( !oRecordSet.EOF )
{
Out ( '<h5><font color="red">' + sEmail + ' is already subscribed to my mailing list!</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 we
// get a reply. that way we know the address is valid and the recipient
// really wants to join the list. for now though, we'll add to the db now.
sSQL = 'INSERT INTO MailingList (Email) VALUES ("' + sEmail + '");';
oConnection.Execute( sSQL );
// free the connection
DBReleaseConnection ( );
Out ( sEmail + ' has been successfully subscribed to my mailing list. ' );
Out ( '<p>You will now receive an email whenever I write new articles, or if I make an important update to any.' );
Email ( 'Joined the ShawThing mailing list', sEmail, 'You have successfully subscribed to the mailing list at ShawThing. If you didn\'t request this please reply to this email, or visit
http://www.shawthing.com/subscribe.asp to unsubscribe.\n\nThank you.\n\nJames Shaw\nhttp://www.shawthing.com/' );
}
// ============================================
// remove email from database
// ============================================
function RemoveEmail ( sEmail )
{
// open the connection
DBInitConnection ( );
// first see if they are already subscribed
var sSQL = 'SELECT Email FROM MailingList WHERE Email="' + sEmail + '";';
DBGetRecords ( sSQL );
if ( oRecordSet.EOF )
{
Out ( '<h5><font color="red">' + sEmail + ' isn\'t subscribed to my mailing list!</font></h5>' );
return;
}
// delete from the database
sSQL = 'DELETE FROM MailingList WHERE Email="' + sEmail + '";';
oConnection.Execute( sSQL );
// free the connection
DBReleaseConnection ( );
Out ( sEmail + ' has been successfully removed from my mailing list. ' );
Out ( '<p>You have been sent a confirmation email, but after that you will not receive any more emails.' );
Email ( 'Removal from ShawThing mailing list', sEmail, 'You have been successfully removed from the mailing list at ShawThing. If you didn\'t request this please reply to this email, or visit
http://www.shawthing.com/subscribe.asp to re-subscribe.\n\nThank you.\n\nJames Shaw\nhttp://www.shawthing.com/' );
}
// ============================================
// email me!
// ============================================
function Email ( sSubject, sEmail, sMessage )
{ // send an email to the address just to confirm what just happened
var oMail = Server.CreateObject ( "CDONTS.NewMail" );
// setup the mail
oMail.From = 'DB@shawthing.com';
oMail.To = sEmail;
oMail.Importance = 1;
oMail.Subject = sSubject;
oMail.Body = sMessage;
// send it
oMail.Send ( );
// release object
oMail = null;
}
%>
utils/Database.asp
<%
// globals
var oConnection;
var oRecordSet;