I am using the below code, that I got from my hosting services (Aplus) web site, but I am getting the error denoted below. Can you please help me get this working? I'm probably doing something wrong.
I have this code all in one asp page named myasp.asp. Is that the correct way to do it? Soemthing makes me think I should have two files - can an ASP page post to itself?
All I am trying to to is have a form on my web site where a person will provide their email address and maybe some other info, click Submit, and have the page automatically send them an emai with a link. I think I have the right code here to do this but can't get it to work. I know the email addresses specifified in the code are not real, but I have real addresses in them on my page.
HERE IS THE ERROR I GET WHEN I HIT THE SUBMIT BUTTON
"error '80040211' /myasp.asp, line 77 objMessage.Send"
FYI: Line 77 is the line that contain this: "objMessage.Send"
HERE IS THE CODE I AM USING
<!-------------begin form------------>
<%
Dim strFrom, strSubject, strBody 'Strings for fromaddress, subject, body
Dim objCDOMail 'The CDO object
sch = "
http://schemas.microsoft.com/cdo/configuration/"
Set cdoConfig = CreateObject("CDO.Configur
ation")
With cdoConfig.Fields
'cdoSendUsingPort
.Item(sch & "sendusing") = 2
'Email Server
.Item(sch & "smtpserver") = "pro44.abac.com"
'Basic authentication
.Item(sch & "smtpauthenticate") = 1
'Type your email account below
.Item(sch & "sendusername") = "email@somewhere.com"
'Type your email password below
.Item(sch & "sendpassword") = "xxxxx"
.Item(sch & "smtpserverport") = 465
'SSL connection enabled
.Item(sch & "smtpusessl") = true
.update
End With
'First we'll read in the values entered
strFrom = Request.Form("from")
'These would read the message subject and body if we let you enter it
strSubject = Request.Form("subject")
strBody = Request.Form("body")
' Some spacing
strBody = strBody & vbCrLf & vbCrLf
' Initiate Is email valid sub function
If strFrom = "" Or Not IsValidEmail(strFrom) Then
' Create Form
%>
<FORM ACTION="myasp.asp" METHOD="post">
Enter your e-mail address:<BR>
<INPUT TYPE="text" NAME="from" SIZE="30"></INPUT><BR><BR>
Subject:<BR>
<INPUT TYPE="text" NAME="subject" SIZE="30"></INPUT><BR><BR>
Message:<BR>
<TEXTAREA NAME="body" ROWS="10" COLS="40" WRAP="virtual"></TEXTAREA>
<BR>
<INPUT TYPE="submit" VALUE="Send Mail"></INPUT>
</FORM>
<%
Else
' Create an instance of the NewMail object.
Set objMessage = Server.CreateObject("CDO.M
essage")
Set objMessage.Configuration = cdoConfig
' Set the properties of the object
objMessage.From = strFrom
objMessage.To = "email@somewhere.com" 'The recipient of the form data
objMessage.Subject = strSubject
objMessage.TextBody = strBody
' Some useful extra variables
'objMessage.Cc = ""
'objMessage.Bcc = ""
' Send the message!
objMessage.Send
' Set the object to nothing because it immediately becomes
' invalid after calling the Send method.
Set objMessage = Nothing
' Set your Response after the Send Mail button is pushed.
Response.Write "Your Message was sent!"
End if
' End page logic
%>
<% ' Only functions and subs follow!
' A quick email syntax checker.
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
%>
<!-------------end form------------>
Start Free Trial