home *** CD-ROM | disk | FTP | other *** search
/ 66.165.151.112 / 66.165.151.112.tar / 66.165.151.112 / www / formmail.asp < prev    next >
Text File  |  2004-08-07  |  14KB  |  303 lines

  1. <%@ Language = vbscript%>
  2. <%option explicit %>
  3. <%server.scripttimeout = 600 %>
  4. <%
  5. '------------------------------------------- FORMMAIL V1.3 ------------------------------------------
  6.  
  7. '----------------------------------------------------------------------------------------------------
  8. 'copyright information
  9. '----------------------------------------------------------------------------------------------------
  10. 'Copyright 2002: Sorted Sites http://www.sortedsites.com
  11. 'Authors Jonas Tornqvist, David Parkes and Karl Snares
  12. 'This script is Freeware, which means you are free to use and modify 
  13. 'the script for your own use.
  14. 'The only condition is this copyright header remain intact and you don't 
  15. 'try and sell this script for profit without first asking us. 
  16. 'And of course also ask Matt Wright who wrote the original perl version of Formmail.
  17.  
  18. '----------------------------------------------------------------------------------------------------
  19. 'license agreement - Important
  20. '----------------------------------------------------------------------------------------------------
  21. 'By using this script you agree to indeminfy the developers - Sorted Sites of any loss
  22. 'or damages that may arise from its use or missue.
  23. 'This script is provided as is with all faults - no warranties and no guarantees.
  24. 'basically its free - use it at your own risk and cost.
  25. 'No warranties and no tech support - if you need help with this don't ask us!
  26. 'The documentation is provided as is with all the help we can offer.
  27. 'As we develop this script we shall post updates hopefully fix any bugs
  28. 'We are not obliged to release any future versions and we might not bother...
  29. 'By using this script you accept this license agreement!
  30.  
  31. '----------------------------------------------------------------------------------------------------
  32. 'documentation v1.3
  33. '----------------------------------------------------------------------------------------------------
  34.  
  35. '####################################################################################################
  36. 'this is where the code starts for real
  37. '####################################################################################################
  38.  
  39. '----------------------------------------------------------------------------------------------------
  40. 'declare variables
  41. '----------------------------------------------------------------------------------------------------
  42. Dim strFrom, strTo, strSubject, strBody
  43. Dim objMessage, objConfig, strServer, intPort
  44. Dim recipient, redirect, subject, realname, email, required, strEmail1, strEmail2
  45. Dim referer, url, url_verified, icounter, query, iloop, query2, query3, i, agree, validation, error0, error0ok
  46.  
  47. '############################## CONFIGURATION VARIABLES ####################################
  48.  
  49. 'These are the only lines you will need to change
  50. '----------------------------------------------------------------------------------------------------
  51. strServer = "mail.sweatblood.com" 'set which smtp server will be used to send the email. enter ip address or domain name. eg: "xxx.xxx.xxx.xxx" or "smtp.your-domain.com"
  52. intPort = 25 'set the smtp port to be used when sending mail (by default port 25 is used)
  53. 'Referrer's Array is defined here. Enter the valid domains which may use this script.
  54. url = Array("www.sweatblood.com","sweatblood.com")'Set which urls that will be accepted. http://xxxxx/
  55.     'Seperate multiple domains by commas 
  56.     'eg: url= Array("www.your-domain.com","your-domain.com","www.my-domain.com")
  57.     'computer names can be used instead of domains if this script is being run locally
  58.     'eg: url = Array("computername")
  59.  
  60. '######################################### IMPORTANT NOTICE #########################################
  61. 'IMPORTANT: do not modify anything below this line unless you know what you are doing!!
  62. '######################################### IMPORTANT NOTICE #########################################
  63.     
  64. '----------------------------------------------------------------------------------------------------
  65. 'information type and CDOSYS constants
  66. '----------------------------------------------------------------------------------------------------
  67. %>
  68. <!--METADATA TYPE="typelib"
  69. UUID="CD000000-8B95-11D1-82DB-00C04FB1625D"
  70. NAME="CDO for Windows 2000 Library" -->
  71. <!--METADATA TYPE="typelib"
  72. UUID="00000205-0000-0010-8000-00AA006D2EA4"
  73. NAME="ADODB Type Library" -->
  74. <%
  75. '----------------------------------------------------------------------------------------------------
  76. 'retrieved default fields
  77. '----------------------------------------------------------------------------------------------------
  78. recipient = request("recipient")
  79. redirect = request("redirect")
  80. subject = request("subject")
  81. email = request("email")
  82. required = request("required") 
  83. if required = "" then
  84.     required = "recipient,subject,email,redirect"
  85. else
  86.     required = "recipient,subject,email,redirect," & required
  87. end if
  88.  
  89. '----------------------------------------------------------------------------------------------------
  90. 'verify the referer
  91. '----------------------------------------------------------------------------------------------------
  92. referer = request.ServerVariables("HTTP_REFERER") 
  93. referer = split(referer,"/")
  94. url_verified = "no"
  95. for icounter = Lbound(url) to Ubound(url) '
  96.     if referer(2) = url(icounter) then
  97.         url_verified = "yes"
  98.     end if
  99. next
  100. if not url_verified = "yes" then 
  101.     response.write("The url specified is invalid!")
  102.     response.End
  103. end if
  104.  
  105. '----------------------------------------------------------------------------------------------------
  106. 'verify the recipient(not tested)
  107. '----------------------------------------------------------------------------------------------------
  108. 'trimed_referer = split(referer(2),".")'
  109. 'response.write recipient & "<br>" & referer(2) & "=" & trimed_referer(0) & "<br>"
  110. 'if trimed_referer(0) = "www" then
  111. '    if InStr(1,recipient,trimed_referer(1),1) = 0 then
  112. '        response.write "recipient don't match the referer"
  113. '        response.end
  114. '    end if
  115. 'else
  116. '    if InStr(1,recipient,trimed_referer(0),1) = 0 then
  117. '        response.write "recipient don't match the referer"
  118. '        response.end
  119. '    end if
  120. 'end if
  121.  
  122. '----------------------------------------------------------------------------------------------------
  123. 'retrieve form contents and create email fields
  124. '---------------------------------------------------------------------------------------------------- 
  125. query = Request.ServerVariables("QUERY_STRING") 
  126. query = split(query,"&")
  127. query3 = split(required,",")
  128.     For iLoop = Lbound(query) to UBound(query)
  129.         query2 = split(query(iloop),"=")
  130.     
  131. '----------------------------------------------------------------------------------------------------
  132. 'form validation, checks required fields are not null
  133. '----------------------------------------------------------------------------------------------------
  134.         for i = LBound(query3) to UBound(query3)
  135.             if query3(i) = query2(0) then
  136.                 if query2(1) = "" then
  137.                     response.write ("you must enter a valid ") & query2(0)
  138.                     response.end
  139.                 end if
  140.             end if
  141.             
  142.             'if query2(0) = "agree" then
  143.                 'if query2(1) <> "on" or query2(1) = "" then
  144.                 '    response.write("You must agree to terms and conditions to enable Formmailv1.3 to execute!")
  145.                 'response.end
  146.                 'end if
  147.             'end if
  148.             
  149. '----------------------------------------------------------------------------------------------------
  150. 'form validation, checks a valid email address has been specified
  151. '----------------------------------------------------------------------------------------------------            
  152.             if query2(0) = "email" then
  153.                 trim(query2(0))
  154.                 if len(query2(1))<8 then
  155.                     response.Write("You must specify a valid ") & query2(0)
  156.                     response.end
  157.                 end if
  158.                 if instr(query2(1),"@")=0 and instr(query2(1),".")=0 then
  159.                     response.write query2(1)
  160.                     response.Write("You must specify a valid ") & query2(0)
  161.                     response.end
  162.                 end if
  163.                 strEmail1 = split(query2(1),"@")
  164.                 if len(strEmail1(1))<3 then
  165.                     response.Write("You must specify a valid ") & query2(0)
  166.                     response.end
  167.                 end if
  168.                 strEmail2 = split(strEmail1(1),".")
  169.                 if len(strEmail2(0))<3 then
  170.                     response.Write("You must specify a valid ") & query2(0)
  171.                     response.end
  172.                 end if
  173.                 if len(strEmail2(1))<2 then
  174.                     response.Write("You must specify a valid ") & query2(0)
  175.                     response.end
  176.                 end if
  177.             end if
  178.  
  179. '----------------------------------------------------------------------------------------------------
  180. 'form validation, checks terms and conditions checkbox has been ticked
  181. '----------------------------------------------------------------------------------------------------
  182.             
  183.         Next
  184.         if not query2(0) = "recipient" and not query2(0) = "redirect" and not query2(0) = "subject" and not query2(0) = "realname" and not query2(0) = "email" and not query2(0) = "required" and not query2(0) = "agree" then
  185.             strBody = strBody & vbnewline & vbnewline & query2(0) &": " & query2(1) 
  186.         end if
  187.     Next
  188. if email = "" then
  189.     email = "formmail@" & referer(2)
  190. end if
  191. '----------------------------------------------------------------------------------------------------
  192. 'replaces any special characters parsed through the query string
  193. '----------------------------------------------------------------------------------------------------
  194. strbody = replace(strbody, "+"," ")
  195. strbody = replace(strbody, "%26%238364%3B","Ç")
  196. strbody = replace(strbody, "%A1","í")
  197. strbody = replace(strbody, "%A3","ú")
  198. strbody = replace(strbody, "%A8","¿")
  199. strbody = replace(strbody, "%AA","¬")
  200. strbody = replace(strbody, "%AC","¼")
  201. strbody = replace(strbody, "%B4","┤")
  202. strbody = replace(strbody, "%B7","╖")
  203. strbody = replace(strbody, "%BA","║")
  204. strbody = replace(strbody, "%BF","┐")
  205. strbody = replace(strbody, "%C7","╟")
  206. strbody = replace(strbody, "%E7","τ")
  207. strbody = replace(strbody, "%0D%0A",vbnewline)
  208. strbody = replace(strbody, "%21","!")
  209. strbody = replace(strbody, "%23","#")
  210. strbody = replace(strbody, "%24","$")
  211. strbody = replace(strbody, "%25","%")
  212. strbody = replace(strbody, "%26","&")
  213. strbody = replace(strbody, "%27","'")
  214. strbody = replace(strbody, "%28","(")
  215. strbody = replace(strbody, "%29",")")
  216. strbody = replace(strbody, "%2B","+")
  217. strbody = replace(strbody, "%2C",",")
  218. strbody = replace(strbody, "%2D","-")
  219. strbody = replace(strbody, "%2E",".")
  220. strbody = replace(strbody, "%2F","/")
  221. strbody = replace(strbody, "%3A",":")
  222. strbody = replace(strbody, "%3B",";")
  223. strbody = replace(strbody, "%3C","<")
  224. strbody = replace(strbody, "%3D","=")
  225. strbody = replace(strbody, "%3E",">")
  226. strbody = replace(strbody, "%3F","?")
  227. strbody = replace(strbody, "%5B","[")
  228. strbody = replace(strbody, "%5C","\")
  229. strbody = replace(strbody, "%5D","]")
  230. strbody = replace(strbody, "%5E","^")
  231. strbody = replace(strbody, "%5F","_")
  232. strbody = replace(strbody, "%60","`")
  233. strbody = replace(strbody, "%7B","{")
  234. strbody = replace(strbody, "%7C","|")
  235. strbody = replace(strbody, "%7D","}")
  236. strbody = replace(strbody, "%7E","~")
  237.  
  238. '----------------------------------------------------------------------------------------------------
  239. 'this creates the body of the mail message, the text in quotes can be modified accordingly 
  240. '---------------------------------------------------------------------------------------------------
  241. strBody = "Here is the results of your form submitted from" & referer(2)  & vbnewline & vbnewline & "Name: " & realname & vbnewline &  vbnewline & "Email: " & email & vbnewline & strBody & vbnewline &  vbnewline & "############# End Formmail Tranmission #############" 
  242.  
  243. '----------------------------------------------------------------------------------------------------
  244. 'checks if a smtp port has been specified, if not it uses the default port 25
  245. '----------------------------------------------------------------------------------------------------
  246. if intport <> 25 then
  247.     intport = intport
  248. else
  249.     intport = 25
  250. end if
  251.  
  252. '----------------------------------------------------------------------------------------------------
  253. 'send the mail message
  254. '----------------------------------------------------------------------------------------------------    
  255. set objMessage = CreateObject("CDO.Message")
  256. objMessage.To = recipient
  257. objMessage.From = email
  258. objMessage.Subject = subject
  259. objMessage.Sender = email
  260. objMessage.Textbody = strBody
  261.  
  262. '----------------------------------------------------------------------------------------------------
  263. 'cdosys configuration setup
  264. '----------------------------------------------------------------------------------------------------
  265. set objConfig = CreateObject("CDO.Configuration")
  266. objConfig.Fields(cdoSendUsingMethod) = cdoSendUsingPort
  267. objConfig.Fields(cdoSMTPServer) = strServer
  268. objConfig.Fields(cdoSMTPServerPort) = intPort
  269. objConfig.Fields(cdoSMTPAuthenticate) = cdoAnonymous
  270. objConfig.Fields.Update
  271. set objMessage.Configuration = objConfig
  272.  
  273. '----------------------------------------------------------------------------------------------------
  274. 'define error handling procedures
  275. '----------------------------------------------------------------------------------------------------
  276. On Error Resume Next
  277.     objMessage.Send
  278. If Err.Number = 0 then
  279.     response.write("Formmail v1.3 processed all operations successfully!")
  280. else
  281.     response.write("Formmail v1.3 detected the following errors:")& "<br>"
  282.     response.write("error no.: ")&err.number & "<br>"
  283.     response.write("description: ")&err.description & "<br>"
  284.     response.end
  285. End If
  286. On Error Goto 0
  287.     
  288. '----------------------------------------------------------------------------------------------------
  289. 'send them to the page specified
  290. '----------------------------------------------------------------------------------------------------
  291. Response.Redirect redirect
  292.  
  293. '####################################################################################################
  294. 'This is where the code ends
  295. '####################################################################################################
  296. %>
  297. <!-- That's All Folks -->
  298. <!-- Happy Surfing -->
  299. <!-- Credits -->
  300. <!-- David Parkes - Project Planning -->
  301. <!-- Jonas Tornqvist - Lead Programmer version 1-->
  302. <!-- Karl Snares - Lead Programmer version 1.2 & 1.3
  303. <!-- Matt Wright - Original Formmail CGI Developer -->