%
' Newsletter Status:
' 0=Unsubscribed
' 1=Subscribed
' 2=Awaiting Verification
' 3=Bad Email
Set db = Server.CreateObject("ADODB.Connection")
set rs = server.createObject("ADODB.Recordset")
'
myAction=request("action")
if len(request("u"))>0 then
'myAction="unsubscribe"
myEmail=lcase(request("u"))
end if
if len(request("s"))>0 then
myAction="subscribe"
myEmail=lcase(request("s"))
end if
if len(myEmail)<1 then
myEmail=lcase(request("email"))
end if
select case myAction
case "subscribe"
rs.open "Select * from newsletter WHERE email='" & myEmail & "'", db
if rs.eof then
dosubscribe="yes"
else
if rs("status")="3" then
response.write "email in database but marked bad so resending confirmation"
else
if rs("status")="1" then
response.write "This e-mail address has already been subscribed and enabled."
else
dosubscribe="yes"
db.execute "delete from newsletter WHERE email='" & myEmail & "'"
end if
end if
end if
rs.close
if dosubscribe="yes" then
if badEmail(myEmail) then
response.write "Invalid email."
else
verification=CLng(DateDiff("s", "01/01/1970 00:00:00", Now))
randomize
verification=verification & Chr(Int(26 * Rnd + 97))
randomize
verification=verification & Chr(Int(26 * Rnd + 97))
db.execute("INSERT into newsletter (email,newsletter,status,verification,signup) VALUES ('" & myEmail & "','free','2','" & verification & "','" & now() & "')")
Set objNewMail = Server.CreateObject("CDONTS.NewMail")
objNewMail.Send "mailer@redlightningrecords.com", myEmail, "Redlightningrecords.com Newsletter Subscription", "test" ,2, "localhost"
set objNewMail = nothing
response.write "An email has been sent to " & myEmail & " to verify your email address.
You MUST click the link sent in that email to be subscribed. If, for some reason, you cannot click the link, simply copy it and paste it into your browser's address (URL) bar and hit ENTER (RETURN).
Click here to return to Redlightningrecords.com
"
end if
end if
case "unsubscribe"
rs.open "Select * from newsletter WHERE email='" & myEmail & "'", db
if rs.eof then
response.write "Sorry, " & myEmail & " was not found in our database or has already been unsubscribed."
else
'response.write "Unsubscribing email... "
db.execute("Delete from newsletter WHERE email='" & myEmail & "'")
response.write "Done."
response.write "We are sorry to see you go. If any time in the future you wish to re-subscribe to this newsletter visit http://project3.microswift.com/newsletter/"
Set objNewMail = Server.CreateObject("CDONTS.NewMail")
objNewMail.Send "Redlightningrecords.com ", myEmail, "Redlightningrecords.com Newsletter Unsubscription", ReadFile("unsubscribed_" & rs("newsletter") & ".txt")
set objNewMail = nothing
end if
case else
if len(request.servervariables("Query_String"))>0 AND len(request("u"))<1 then
rs.open "Select * from newsletter WHERE verification='" & request.servervariables("Query_String") & "'", db
if rs.eof then
response.write "Sorry, the verification code you provided was not found. It may have been entered incorrectly or the code has expired. CLICK HERE to re-subscribe or check your current status."
else
if rs("status")="1" then
response.write "This e-mail address has already been subscribed and enabled."
else
response.write "Subscribing email... "
db.execute ("UPDATE newsletter SET status='1' WHERE verification='" & request.servervariables("Query_String") & "'")
response.write "Done."
response.write "
Thank you for your subscription. If you wish to unsubscribe at any point, you will find directions in every email on how to do so.
Click here to return to Redlightningrecords.com
"
Set objNewMail = Server.CreateObject("CDONTS.NewMail")
objNewMail.Send "Redlightningrecords.com ", myEmail, "Redlightningrecords.com Newsletter Subscription", ReadFile("verified_" & rs("newsletter") & ".txt")
set objNewMail = nothing
end if
end if
rs.close
else
%>
Please enter your email below to subscribe to our free newsletter. A verification email will
be sent to the address provided. You MUST click on the link within it to confirm your subscription.
<%
end if
end select
set rs = nothing
set db = nothing
Function ReadFile(filename)
Dim objFSO
Dim objTStream
Dim strText
Const ForReading = 1
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
Set objTStream = objFSO.OpenTextFile(Server.MapPath(filename), ForReading)
strText = objTStream.ReadAll
Set objTStream = Nothing
Set objFSO = Nothing
strText = Replace(strText, "{verification}", verification)
strText = Replace(strText, "{email}", myEmail)
strText = Replace(strText, "{time}", now())
strText = Replace(strText, "{ip}", Request.ServerVariables("REMOTE_ADDR"))
ReadFile = strText
End Function
%>