I'm integrating reCaptcha and CDONTS into a contact form. I've got everything working except the form does not send mail :confused: (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:
<%@ Language="VBScript" %>
<%
recaptcha_challenge_field = Request("recaptcha_challenge_field")
recaptcha_response_field = Request("recaptcha_response_field")
recaptcha_public_key = "(removed for forum posting)" ' your public key
recaptcha_private_key = "(removed for forum posting)" ' your private key
' returns the HTML for the widget
function recaptcha_challenge_writer()
recaptcha_challenge_writer = _
"<script type=""text/javascript"">" & _
"var RecaptchaOptions = {" & _
" theme : 'blackglass'," & _
" tabindex : 0" & _
"};" & _
"</script>" & _
"<script type=""text/javascript"" src=""http://api.recaptcha.net/challenge?k=" & recaptcha_public_key & """></script>" & _
"<noscript>" & _
"<iframe src=""http://api.recaptcha.net/noscript?k=" & recaptcha_public_key & """ frameborder=""1""></iframe><br>" & _
"<textarea name=""recaptcha_challenge_field"" rows=""3""cols=""40""></textarea>" & _
"<input type=""hidden"" name=""recaptcha_response_field""value=""manual_challenge"">" & _
"</noscript>"
end function
' returns "" if correct, otherwise it returns the error response
function recaptcha_confirm(rechallenge,reresponse)
Dim VarString
VarString = _
"privatekey=" & recaptcha_private_key & _
"&remoteip=" & Request.ServerVariables("REMOTE_ADDR") & _
"&challenge=" & rechallenge & _
"&response=" & reresponse
Dim objXmlHttp
Set objXmlHttp = Server.CreateObject("Msxml2.ServerXMLHTTP")
objXmlHttp.open "POST", "http://api-verify.recaptcha.net/verify", False
objXmlHttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
objXmlHttp.send VarString
Dim ResponseString
ResponseString = split(objXmlHttp.responseText, vblf)
Set objXmlHttp = Nothing
if ResponseString(0) = "true" then
'They answered correctly
recaptcha_confirm = ""
else
'They answered incorrectly
recaptcha_confirm = ResponseString(1)
end if
end function
server_response = ""
newCaptcha = True
if (recaptcha_challenge_field <> "" or recaptcha_response_field <> "") then
server_response = recaptcha_confirm(recaptcha_challenge_field, recaptcha_response_field)
newCaptcha = False
end if
%>
<html>
<head>
<script language="javascript" type="text/javascript">
<!--
/***********************************************
* Required field(s) validation v1.10- By NavSurf
* Visit Nav Surf at http://navsurf.com
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/
function formCheck(formobj){
// Enter name of mandatory fields
var fieldRequired = Array("Name", "Email", "Message");
// Enter field description to appear in the dialog box
var fieldDescription = Array("Name", "Email", "Message");
// dialog message
var alertMsg = "Please complete the following field(s):\n";
var l_Msg = alertMsg.length;
for (var i = 0; i < fieldRequired.length; i++){
var obj = formobj.elements[fieldRequired[i]];
if (obj){
switch(obj.type){
case "select-one":
if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == ""){
alertMsg += " - " + fieldDescription[i] + "\n";
}
break;
case "select-multiple":
if (obj.selectedIndex == -1){
alertMsg += " - " + fieldDescription[i] + "\n";
}
break;
case "text":
case "textarea":
if (obj.value == "" || obj.value == null){
alertMsg += " - " + fieldDescription[i] + "\n";
}
break;
default:
}
if (obj.type == undefined){
var blnchecked = false;
for (var j = 0; j < obj.length; j++){
if (obj[j].checked){
blnchecked = true;
}
}
if (!blnchecked){
alertMsg += " - " + fieldDescription[i] + "\n";
}
}
}
}
if (alertMsg.length == l_Msg){
return true;
}else{
alert(alertMsg);
return false;
}
}
// -->
</script>
</head>
<body>
<form name="contactform" action="contact3.asp" method="post" onSubmit="return formCheck(this);">
<div class="style4">
<table border="0" align="center">
<tr>
<td width="120" align="right" valign="middle" class="style5">* <em>Required</em></td>
<td width="180" valign="middle" class="style3"><img src="images/clearspace.gif" width="1" height="20" alt="">
<% if server_response <> "" or newCaptcha then
'there was an error
if newCaptcha = False then Response.Write("Incorrect Captcha!")
'''''''''''''''''''EVERYTHING WORKS FINE UNTIL HERE'''''''''''''''''''
end if
if newCaptcha = True then
'Send an Email
function SendMail
Dim EmailFrom
Dim EmailTo
Dim Subject
Dim Name
Dim Company
Dim Email
Dim Phone
Dim Message
' get posted data into variables
EmailFrom = Trim(Request.Form("Email"))
EmailTo = "(removed for forum posting)"
Subject = "Email From UFO Recordings Website"
Name = Trim(Request.Form("Name")) & vbCrLf
Company = Trim(Request.Form("Company")) & vbCrLf
Email = Trim(Request.Form("Email")) & vbCrLf
Phone = Trim(Request.Form("Phone")) & vbCrLf
Message = Trim(Request.Form("Message"))
' prepare email body text
Dim Body
Body = Body & "Name: " & Name & VbCrLf
Body = Body & "Company: " & Company & VbCrLf
Body = Body & "Email: " & Email & VbCrLf
Body = Body & "Phone: " & Phone & VbCrLf
Body = Body & "Message: " & Message & VbCrLf
' send email
Dim mail
Set mail = Server.CreateObject("CDONTS.NewMail")
mail.To = EmailTo
mail.From = EmailFrom
mail.Subject = Subject
mail.Body = Body
mail.Send
end function
end if
%>
</td>
</tr>
<tr>
<td width="120" align="right" valign="middle" class="style2"><span class="style5">*</span> Name</td>
<td width="180" valign="middle"><input type="text" name="Name" size="30" maxlength="80"></td>
</tr>
<tr>
<td align="right" valign="middle" class="style2">Company</td>
<td valign="middle"><input type="text" name="Company" size="30" maxlength="80"></td>
</tr>
<tr>
<td align="right" valign="middle" class="style2"><span class="style5">*</span> Email Address</td>
<td valign="middle"><input type="text" name="Email" size="30" maxlength="80"></td>
</tr>
<tr>
<td align="right" valign="middle" class="style2">Phone Number</td>
<td valign="middle"><input type="text" name="Phone" size="30" maxlength="30"></td>
</tr>
<tr>
<td valign="middle" align="right" class="style2"></td>
<td valign="middle"> </td>
</tr>
<tr>
<td valign="middle" align="right" class="style2"><span class="style5">*</span> Message</td>
<td valign="middle"><textarea name="Message" cols="23" rows="5"></textarea>
<br>
</td>
</tr>
</table>
<%=recaptcha_challenge_writer()%>
<br>
<input type="submit" name="submit" value="Send Email">
</div>
</form>