Get form to send email

Reply

Join Date: Apr 2009
Posts: 3
Reputation: djkfunk is an unknown quantity at this point 
Solved Threads: 0
djkfunk djkfunk is offline Offline
Newbie Poster

Get form to send email

 
0
  #1
Apr 24th, 2009
I'm integrating reCaptcha and CDONTS into a contact form. I've got everything working except the form does not send mail (it is supposed to gather data from form fields and send to my email address after successful reCaptcha entry). Live page located at www.uforecordingsusa.com/contact3.asp . I've truncated the code for simplicity and highlighted trouble area:
  1. <%@ Language="VBScript" %>
  2. <%
  3. recaptcha_challenge_field = Request("recaptcha_challenge_field")
  4. recaptcha_response_field = Request("recaptcha_response_field")
  5. recaptcha_public_key = "(removed for forum posting)" ' your public key
  6. recaptcha_private_key = "(removed for forum posting)" ' your private key
  7.  
  8. ' returns the HTML for the widget
  9. function recaptcha_challenge_writer()
  10.  
  11. recaptcha_challenge_writer = _
  12. "<script type=""text/javascript"">" & _
  13. "var RecaptchaOptions = {" & _
  14. " theme : 'blackglass'," & _
  15. " tabindex : 0" & _
  16. "};" & _
  17. "</script>" & _
  18. "<script type=""text/javascript"" src=""http://api.recaptcha.net/challenge?k=" & recaptcha_public_key & """></script>" & _
  19. "<noscript>" & _
  20. "<iframe src=""http://api.recaptcha.net/noscript?k=" & recaptcha_public_key & """ frameborder=""1""></iframe><br>" & _
  21. "<textarea name=""recaptcha_challenge_field"" rows=""3""cols=""40""></textarea>" & _
  22. "<input type=""hidden"" name=""recaptcha_response_field""value=""manual_challenge"">" & _
  23. "</noscript>"
  24.  
  25. end function
  26.  
  27. ' returns "" if correct, otherwise it returns the error response
  28. function recaptcha_confirm(rechallenge,reresponse)
  29.  
  30. Dim VarString
  31. VarString = _
  32. "privatekey=" & recaptcha_private_key & _
  33. "&remoteip=" & Request.ServerVariables("REMOTE_ADDR") & _
  34. "&challenge=" & rechallenge & _
  35. "&response=" & reresponse
  36.  
  37. Dim objXmlHttp
  38. Set objXmlHttp = Server.CreateObject("Msxml2.ServerXMLHTTP")
  39. objXmlHttp.open "POST", "http://api-verify.recaptcha.net/verify", False
  40. objXmlHttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
  41. objXmlHttp.send VarString
  42.  
  43. Dim ResponseString
  44. ResponseString = split(objXmlHttp.responseText, vblf)
  45. Set objXmlHttp = Nothing
  46.  
  47. if ResponseString(0) = "true" then
  48. 'They answered correctly
  49. recaptcha_confirm = ""
  50. else
  51. 'They answered incorrectly
  52. recaptcha_confirm = ResponseString(1)
  53. end if
  54.  
  55. end function
  56.  
  57. server_response = ""
  58. newCaptcha = True
  59. if (recaptcha_challenge_field <> "" or recaptcha_response_field <> "") then
  60. server_response = recaptcha_confirm(recaptcha_challenge_field, recaptcha_response_field)
  61. newCaptcha = False
  62. end if
  63. %>
  64. <html>
  65. <head>
  66. <script language="javascript" type="text/javascript">
  67. <!--
  68.  
  69. /***********************************************
  70. * Required field(s) validation v1.10- By NavSurf
  71. * Visit Nav Surf at http://navsurf.com
  72. * Visit http://www.dynamicdrive.com/ for full source code
  73. ***********************************************/
  74.  
  75. function formCheck(formobj){
  76. // Enter name of mandatory fields
  77. var fieldRequired = Array("Name", "Email", "Message");
  78. // Enter field description to appear in the dialog box
  79. var fieldDescription = Array("Name", "Email", "Message");
  80. // dialog message
  81. var alertMsg = "Please complete the following field(s):\n";
  82.  
  83. var l_Msg = alertMsg.length;
  84.  
  85. for (var i = 0; i < fieldRequired.length; i++){
  86. var obj = formobj.elements[fieldRequired[i]];
  87. if (obj){
  88. switch(obj.type){
  89. case "select-one":
  90. if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == ""){
  91. alertMsg += " - " + fieldDescription[i] + "\n";
  92. }
  93. break;
  94. case "select-multiple":
  95. if (obj.selectedIndex == -1){
  96. alertMsg += " - " + fieldDescription[i] + "\n";
  97. }
  98. break;
  99. case "text":
  100. case "textarea":
  101. if (obj.value == "" || obj.value == null){
  102. alertMsg += " - " + fieldDescription[i] + "\n";
  103. }
  104. break;
  105. default:
  106. }
  107. if (obj.type == undefined){
  108. var blnchecked = false;
  109. for (var j = 0; j < obj.length; j++){
  110. if (obj[j].checked){
  111. blnchecked = true;
  112. }
  113. }
  114. if (!blnchecked){
  115. alertMsg += " - " + fieldDescription[i] + "\n";
  116. }
  117. }
  118. }
  119. }
  120.  
  121. if (alertMsg.length == l_Msg){
  122. return true;
  123. }else{
  124. alert(alertMsg);
  125. return false;
  126. }
  127. }
  128. // -->
  129. </script>
  130. </head>
  131. <body>
  132. <form name="contactform" action="contact3.asp" method="post" onSubmit="return formCheck(this);">
  133.  
  134.  
  135. <div class="style4">
  136. <table border="0" align="center">
  137.  
  138. <tr>
  139. <td width="120" align="right" valign="middle" class="style5">* <em>Required</em></td>
  140. <td width="180" valign="middle" class="style3"><img src="images/clearspace.gif" width="1" height="20" alt="">
  141.  
  142. <% if server_response <> "" or newCaptcha then
  143. 'there was an error
  144. if newCaptcha = False then Response.Write("Incorrect Captcha!")
  145.  
  146. '''''''''''''''''''EVERYTHING WORKS FINE UNTIL HERE'''''''''''''''''''
  147.  
  148. end if
  149.  
  150. if newCaptcha = True then
  151.  
  152. 'Send an Email
  153.  
  154. function SendMail
  155.  
  156. Dim EmailFrom
  157. Dim EmailTo
  158. Dim Subject
  159. Dim Name
  160. Dim Company
  161. Dim Email
  162. Dim Phone
  163. Dim Message
  164.  
  165. ' get posted data into variables
  166. EmailFrom = Trim(Request.Form("Email"))
  167. EmailTo = "(removed for forum posting)"
  168. Subject = "Email From UFO Recordings Website"
  169. Name = Trim(Request.Form("Name")) & vbCrLf
  170. Company = Trim(Request.Form("Company")) & vbCrLf
  171. Email = Trim(Request.Form("Email")) & vbCrLf
  172. Phone = Trim(Request.Form("Phone")) & vbCrLf
  173. Message = Trim(Request.Form("Message"))
  174.  
  175. ' prepare email body text
  176. Dim Body
  177. Body = Body & "Name: " & Name & VbCrLf
  178. Body = Body & "Company: " & Company & VbCrLf
  179. Body = Body & "Email: " & Email & VbCrLf
  180. Body = Body & "Phone: " & Phone & VbCrLf
  181. Body = Body & "Message: " & Message & VbCrLf
  182.  
  183. ' send email
  184. Dim mail
  185. Set mail = Server.CreateObject("CDONTS.NewMail")
  186. mail.To = EmailTo
  187. mail.From = EmailFrom
  188. mail.Subject = Subject
  189. mail.Body = Body
  190. mail.Send
  191.  
  192. end function
  193.  
  194. end if
  195.  
  196. %>
  197. </td>
  198. </tr>
  199.  
  200. <tr>
  201. <td width="120" align="right" valign="middle" class="style2"><span class="style5">*</span> Name</td>
  202. <td width="180" valign="middle"><input type="text" name="Name" size="30" maxlength="80"></td>
  203. </tr>
  204.  
  205. <tr>
  206. <td align="right" valign="middle" class="style2">Company</td>
  207. <td valign="middle"><input type="text" name="Company" size="30" maxlength="80"></td>
  208. </tr>
  209.  
  210. <tr>
  211. <td align="right" valign="middle" class="style2"><span class="style5">*</span> Email Address</td>
  212. <td valign="middle"><input type="text" name="Email" size="30" maxlength="80"></td>
  213. </tr>
  214.  
  215. <tr>
  216. <td align="right" valign="middle" class="style2">Phone Number</td>
  217. <td valign="middle"><input type="text" name="Phone" size="30" maxlength="30"></td>
  218. </tr>
  219.  
  220. <tr>
  221.  
  222. <td valign="middle" align="right" class="style2"></td>
  223.  
  224. <td valign="middle">&nbsp;</td>
  225. </tr>
  226.  
  227. <tr>
  228.  
  229. <td valign="middle" align="right" class="style2"><span class="style5">*</span> Message</td>
  230.  
  231. <td valign="middle"><textarea name="Message" cols="23" rows="5"></textarea>
  232. <br>
  233.  
  234. </td>
  235. </tr>
  236. </table>
  237. <%=recaptcha_challenge_writer()%>
  238. <br>
  239. <input type="submit" name="submit" value="Send Email">
  240. </div>
  241. </form>
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC