Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Nov 2005
    Posts
    750
    Thanks
    138
    Thanked 1 Time in 1 Post

    reCaptcha ASP question

    Hello

    I am trying to add a reCaptcha image (the form processing is done via ASP) to a Web form. The form without the reCaptcha image works, but when I try to use reCaptcha with the form the server just doesn't like it (I get an Internal Server 500 error message).

    The following script, which I have now, does not generate any errors (but neither does it send the form):

    Code:
    <%
    'Declaring Variables
    Dim smtpserver,youremail,yourpassword,ContactUs_Name,ContactUs_Email
    Dim ContactUs_Subject,ContactUs_Body,Action,IsError
    	
    smtpserver = "smtp.mySite.com"
    youremail = "info@mySite.com"
    yourpassword = "myPWD"
    	
    ' Grabbing variables 
    ContactUs_Name = Request("ContactUs_Name")
    ContactUs_Email = Request("ContactUs_Email")
    ContactUs_Subject = Request("ContactUs_Subject")
    ContactUs_Body = Request("ContactUs_Body")
    Action = Request("Action")
    	
    ' Check email
    Function IsValidEmail(Email)
    	Dim ValidFlag,BadFlag,atCount,atLoop,SpecialFlag,UserName,DomainName,atChr,tAry1
    	ValidFlag = False
    		If (Email <> "") And (InStr(1, Email, "@") > 0) And (InStr(1, Email, ".") > 0) Then
    			atCount = 0
    			SpecialFlag = False
    			For atLoop = 1 To Len(Email)
    			atChr = Mid(Email, atLoop, 1)
    				If atChr = "@" Then atCount = atCount + 1
    				If (atChr >= Chr(32)) And (atChr <= Chr(44)) Then SpecialFlag = True
    				If (atChr = Chr(47)) Or (atChr = Chr(96)) Or (atChr >= Chr(123)) Then SpecialFlag = True
    				If (atChr >= Chr(58)) And (atChr <= Chr(63)) Then SpecialFlag = True
    				If (atChr >= Chr(91)) And (atChr <= Chr(94)) Then SpecialFlag = True
    			Next
    			If (atCount = 1) And (SpecialFlag = False) Then
    				BadFlag = False
    				tAry1 = Split(Email, "@")
    				UserName = tAry1(0)
    				DomainName = tAry1(1)
    			If (UserName = "") Or (DomainName = "") Then BadFlag = True
    			If Mid(DomainName, 1, 1) = "." then BadFlag = True
    			If Mid(DomainName, Len(DomainName), 1) = "." then BadFlag = True
    				ValidFlag = True
    			End If
    		End If
    		If BadFlag = True Then ValidFlag = False
    		IsValidEmail = ValidFlag
    End Function
    %>
    
    
    <html>
    
    <head>
    <title>Contact Us Form</title>
    </head>
    
    <body style="font-family: Arial; font-size: 12px">
    
    <form action="recaptcha.asp" method="POST">
    <input type="hidden" name="Action" value="SendEmail">
    <font size="2">Contact Us:</font>
    <br><br>
    	<table border="0" cellspacing="1">
    		<tr>
    			<td valign="top">
    				Name:
    			</td>
    			<td colspan="2">
    				<input type="text" name="ContactUs_Name" size="35" value="<% =ContactUs_Name %>">
    			</td>
    		</tr>
    		<tr>
    			<td valign="top">
    				Email:
    			</td>
    			<td colspan="2">
    				<input type="text" name="ContactUs_Email" size="35" value="<% =ContactUs_Email %>">
    			</td>
    		</tr>
    		<tr>
    			<td valign="top">
    				Subject:
    			</td>
    			<td colspan="2">
    				<input type="text" name="ContactUs_Subject" value="<% =ContactUs_Subject %>" size="35">
    			</td>
    		</tr>
    		<tr>
    			<td valign="top">
    				Message:
    			</td>
    			<td valign="top">
    				<textarea rows="10" name="ContactUs_Body" cols="40"><% =ContactUs_Body %></textarea>
    			</td>
    		</tr>
    		<tr>
    			<td valign="top">
    				&nbsp;
    			</td>
    			<td colspan="2">
    				<input type="submit" value="Send Message">
    			</td>
    		</tr>
    	</table>
    </form>
    
    <% End If %>
    
    </body>
    
    </html>

    But once I begin to add the following (checking email fields, and getting the email to send, etc), I run into problems. I am trying to add the script below immediately after this line:

    <body style="font-family: Arial; font-size: 12px"> in the above script.


    Code:
    <%
    If Action = "SendEmail" Then
    	
    	' Check for correct information
    
    	If IsValidEmail(ContactUs_Email) = "False" Then
    		IsError = "Yes"
    		Response.Write("<font color=""red"">You did not enter a valid email address.</font><br>")
    	End If
    	
    	If ContactUs_Name = "" Then
    		IsError = "Yes"
    		Response.Write("<font color=""red"">You did not enter a Name.</font><br>")
    	End If
    	
    	If ContactUs_Subject = "" Then
    	IsError = "Yes"
    		Response.Write("<font color=""red"">You did not enter a Subject.</font><br>")
    	End If
    	
    	If ContactUs_Body = "" Then
    		IsError = "Yes"
    		Response.Write("<font color=""red"">You did not enter a Body.</font><br>")
    	End If
    	
    End If
    	
    ' Send email if no errors
    
    If Action = "SendEmail" And IsError <> "Yes" Then
    	
    	Dim strBody
    	
    	' Create html body
    
    	strBody = strBody & "<font face=""Arial"">Contact Us Form submitted at " & Now() &  vbCrLf & "<br><br>"
    	strBody = strBody & "From http://" & Request.ServerVariables("HTTP_HOST") &  vbCrLf & "<br>"
    	strBody = strBody & "IP " & Request.ServerVariables("REMOTE_ADDR") & vbCrLf & "<br>"
    	strBody = strBody & "Name" & " : " & " " & Replace(ContactUs_Name,vbCr,"<br>") & "<br>"
    	strBody = strBody & "Email" & " : " & " " & Replace(ContactUs_Email,vbCr,"<br>") & "<br>"
    	strBody = strBody & "Subject" & " : " & " " & Replace(ContactUs_Subject,vbCr,"<br>") & "<br>"
    	strBody = strBody & "<br>" & Replace(ContactUs_Body,vbCr,"<br>") & "<br>"
    	strBody = strBody & "</font>"
    	
    	Dim ObjSendMail
    	Set ObjSendMail = CreateObject("CDO.Message") 
         
    	'SMTP server configuration
         
    	ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 'Send the message using the network (SMTP over the network).
    	ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = smtpserver
    	ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 
    	ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False 'Use SSL for the connection (True or False)
    	ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
         
    	ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 'basic (clear-text) authentication
    	ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") = youremail
    	ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = yourpassword
         
    	ObjSendMail.Configuration.Fields.Update
         
    	'End remote SMTP server configuration section==
         
    	ObjSendMail.To = youremail
                       ObjSendMail.CC = ContactUs_Email
    	ObjSendMail.Subject = ContactUs_Subject
    	ObjSendMail.From = ContactUs_Email
         
    	' Send html email
    
    	ObjSendMail.HTMLBody = strBody
    	'ObjSendMail.TextBody = strBody
         
    	ObjSendMail.Send
         
    	Set ObjSendMail = Nothing 	
    
    %>
    
    <font size="2">Your message as seen below has been sent. Thank You !!
    <br><br>
    <font color="blue">
    <% =Replace(ContactUs_Body,vbCr,"<br>") %>
    </font>
    </font>
    <% Else %>
    I would be grateful for ideas on how to solve this.

    Thanks.

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,605
    Thanks
    80
    Thanked 4,634 Times in 4,596 Posts
    Well, first of all, you need to turn on debugging mode both in your browser and in IIS, so that you get real error messages instead of useless 500 messages.

    But then you need to learn basic debugging techniques. First of all, start by removing all the email sending code. Still have the error? Then it's not there. Error gone? Then it's somewhere in that block of code. So start adding lines one or two at a time until you get the error again.

    It's a sad fact of life that if you can't debug, you can't program.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    SteveH (04-04-2012)

  • #3
    Senior Coder alykins's Avatar
    Join Date
    Apr 2011
    Posts
    1,927
    Thanks
    46
    Thanked 203 Times in 202 Posts
    Quote Originally Posted by Old Pedant View Post
    It's a sad fact of life that if you can't debug, you can't program.
    I don't think it's a "sad fact" moreover a hard one- granted I have asked questions before that had I debugged I would have found the answer on my own; until you get to the point of realizing that debugging tells you how your code is behaving you usually don't think of it... I think they should, instead of teaching language "blah" they should teach basic debugging techniques and methodologies- I think it would help beginners a lot more than more advanced techniques. I've seen too many instances of people making custom classes and such but not knowing how to debug- or error handle... just my thoughts

    apologies for being a little off-topic; sorry OP I can't offer you any answer that OldPedant wouldn't see before me; I just wanted to share my agreement/thought on debugging essentials

    I code C hash-tag .Net
    Reference: W3C W3CWiki .Net Lib
    Validate: html CSS
    Debug: Chrome FireFox IE

  • Users who have thanked alykins for this post:

    SteveH (04-04-2012)

  • #4
    Regular Coder
    Join Date
    Nov 2005
    Posts
    750
    Thanks
    138
    Thanked 1 Time in 1 Post
    I will try to work it out, thanks!

  • #5
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,605
    Thanks
    80
    Thanked 4,634 Times in 4,596 Posts
    Yeah, I've said it before and I'll say it again: Software development in commercial environments is typically only 20% to 25% programming. The rest of the time is closely divided between debugging, testing, planning, and documenting.

    If you are a relative beginner programmer in such an environment, you can almost count on 50% debugging and 50% programming. The more advanced you get, the less of either you do and the more time you spend on planning and other aspects.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •