James Patrick Dunne


<% '******************************************************* '* ASP 101 Sample Code - http://www.asp101.com * '* * '* This code is made available as a service to our * '* visitors and is provided strictly for the * '* purpose of illustration. * '* * '* Please direct all inquiries to webmaster@asp101.com * '******************************************************* %> <% Dim objCDONTS ' Email object Dim strFromName ' From persons' real name Dim strFromEmail, strToEmail1, strToEmail2, strToEmail3, strToEmail4, strToEmail5, strToEmail6, strToEmail7, strToEmail8, strToEmail9, strToEmail10 ' Email addresses Dim strSubject, strBody ' Message Dim strThisPage ' This page's URL Dim strReferringPage ' The referring page's URL Dim bValidInput ' A boolean indicating valid parameters ' Retrieve this page name and referring page name strThisPage = Request.ServerVariables("SCRIPT_NAME") strReferringPage = Request.ServerVariables("HTTP_REFERER") ' Debugging lines: 'Response.Write strThisPage & "
" & vbCrLf 'Response.Write strReferringPage & "
" & vbCrLf ' Read in and set the initial values of our message parameters strFromName = Trim(Request.Form("txtFromName")) strFromEmail = Trim(Request.Form("txtFromEmail")) strToEmail1 = Trim(Request.Form("txtToEmail1")) strToEmail2 = Trim(Request.Form("txtToEmail2")) strToEmail3 = Trim(Request.Form("txtToEmail3")) strToEmail4 = Trim(Request.Form("txtToEmail4")) strToEmail5 = Trim(Request.Form("txtToEmail5")) strToEmail6 = Trim(Request.Form("txtToEmail6")) strToEmail7 = Trim(Request.Form("txtToEmail7")) strToEmail8 = Trim(Request.Form("txtToEmail8")) strToEmail9 = Trim(Request.Form("txtToEmail9")) strToEmail10 = Trim(Request.Form("txtToEmail10")) strSubject = "Check out James Patrick Dunne's website!" strBody = Trim(Request.Form("txtMessage")) ' I set the body message to a message that referenced the page the ' user arrived from. This makes it great if you place a link to it ' from your different articles, but can be weird if people link in ' from other web sites. If strBody = "" Then If strReferringPage = "" Or InStr(1, strReferringPage, "www.jamespatrickdunne.com", 1) = 0 Then strBody = "" strBody = strBody & "I highly recommend ordering this CD as a gift. I'm sure you'll love the music of James Patrick Dunne. Click on this site and buy his CDs for yourself or a friend." & vbCrLf strBody = strBody & vbCrLf strBody = strBody & " http://www.jamespatrickdunne.com" & vbCrLf Else strBody = "" strBody = strBody & "I found a website I thought you'd like to see:" & vbCrLf strBody = strBody & vbCrLf strBody = strBody & " " & "http://www.jamespatrickdunne.com" & vbCrLf End If End If ' Quick validation just to make sure our parameters are somewhat valid bValidInput = True bValidInput = bValidInput And strFromName <> "" bValidInput = bValidInput And IsValidEmail(strFromEmail) bValidInput = bValidInput And IsValidEmail(strToEmail1) ' If valid send email and show thanks, o/w show form If bValidInput Then ' Set up our email object and send the message Set objCDONTS = Server.CreateObject("CDONTS.NewMail") objCDONTS.From = strFromName & " <" & strFromEmail & ">" objCDONTS.To = strToEmail1 & ", " & strToEmail2 & ", " & strToEmail3 & ", " & strToEmail4 & ", " & strToEmail5 & ", " & strToEmail6 & ", " & strToEmail7 & ", " & strToEmail8 & ", " & strToEmail9 & ", " & strToEmail10 objCDONTS.Bcc = "james@communicationcenter.com" objCDONTS.Subject = strSubject objCDONTS.Body = strBody objCDONTS.Send Set objCDONTS = Nothing ' Show our thank you message ShowThanksMsg Else If "http://" & Request.ServerVariables("HTTP_HOST") & strThisPage = strReferringPage Then Response.Write "There's been an error. Please check your entries:" & "
" & vbCrLf End If ' Show our information retrieval form ShowReferralForm strThisPage, strFromName, strFromEmail, strToEmail1, strToEmail2, strToEmail3, strToEmail4, strToEmail5, strToEmail6, strToEmail7, strToEmail8, strToEmail9, strToEmail10, strBody End If ' End of page logic... subs and functions follow! %> <% ' Subroutines and Functions that encapsulate some functionality ' and make the above code easier to write... and read. ' A quick email syntax checker. It's not perfect, ' but it's quick and easy and will catch most of ' the bad addresses than people type in. Function IsValidEmail(strEmail) Dim bIsValid bIsValid = True If Len(strEmail) < 5 Then bIsValid = False Else If Instr(1, strEmail, " ") <> 0 Then bIsValid = False Else If InStr(1, strEmail, "@", 1) < 2 Then bIsValid = False Else If InStrRev(strEmail, ".") < InStr(1, strEmail, "@", 1) + 2 Then bIsValid = False End If End If End If End If IsValidEmail = bIsValid End Function ' I made this a function just to get it out of the ' logic and make it easier to read. It just shows the ' form that asks for the input Sub ShowReferralForm(strPageName, strFromName, strFromEmail, strToEmail1, strToEmail2, strToEmail3, strToEmail4, strToEmail5, strToEmail6, strToEmail7, strToEmail8, strToEmail9, strToEmail10, strBody) ' I use script_name so users can rename this script witout having to change the code. %>

Your Name:
Your Email Address:
Friend's E-mail:
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
Message:
<% '

The Message to be sent:

'

Subject: < %= strSubject % >

'

Body: < %= strBody % >

End Sub ' This just shows our thank you message... probably didn't need to ' be a function, but since I made the form one I figured I'd do this ' for consistency. Sub ShowThanksMsg() %> Your message has been sent.

Thanks for helping us spread the word about James Patrick Dunne's website
!
<% End Sub %>

 

©2002 JAMES PATRICK DUNNE ENTERTAINMENT COMPANY