Forum Moderators: open
I've been working on an asp email form script using CDO - I can get the script to send the email when I had only one field for the body - once I tried to string the multiple variables together and have them display in the body of the email the function doesn't send the mail. I'm not getting any errors in the browser and am still being redirected to my Response.redirect page. If anyone could please shed some light on why this could be happening I'd really appreciate it!
If it helps this is my code in full --- I checked the smtp mailbox for bounced messages and there weren't any.
<%
SUB sendmail
Dim objCDO
Dim iConf
Dim Flds
Dim Name
Dim Email
Dim Address
Dim Address2
Dim Profession
Dim Speciality
Dim License
Const cdoSendUsingPort = 2
Set objCDO = Server.CreateObject("CDO.Message")
Set iConf = Server.CreateObject("CDO.Configuration")
Set Flds = iConf.Fields
With Flds
.Item(cdoSendUsingMethod) = cdoSendUsingPort
.Item(cdoSMTPServer) = "mail-fwd"
.Item(cdoSMTPServerPort) = 25
.Item(cdoSMTPconnectiontimeout) = 10
.Update
End With
Set objCDO.Configuration = iConf
Name = TRIM( Request.Form( "name") )
Address = TRIM( Request.Form( "address") )
Address2 = TRIM( Request.Form( "address2" ) )
Email = TRIM( Request.Form( "email") )
Profession = TRIM( Request.Form( "profession") )
Speciality = TRIM( Request.Form( "speciality") )
License = TRIM( Request.Form( "license") )
objCDO.From = "someuser@somedomain.com"
objCDO.To = "someuser@somedomain.com"
objCDO.Subject = "Form Test"
objCDO.TextBody = "Name: " & Name & vbCrLf & _
" Address: " & Address & vbCrLf & _
" Address2: " & Address2 & vbCrLf & _
" Email: " & Email & vbCrLf & _
" Profession: " & Profession & vbCrLf & _
" Speciality: " & Speciality & vbCrLf & _
" License #: " & License & vbCrLf & "."
objCDO.Send
END SUB
'Cleanup
Set ObjCDO = Nothing
Set iConf = Nothing
Set Flds = Nothing
Response.redirect "responsepage.htm"
' Any existing page can be used for the response redirect method
%>
<HTML>
<HEAD><TITLE>Email Form</TITLE></HEAD>
<FORM METHOD="POST" ACTION="<%=Request.ServerVariables("SCRIPT_NAME")%>">
<BR>Name: <INPUT NAME="name" TYPE="text" SIZE=40>
<BR>Address: <INPUT NAME="address" TYPE="text" SIZE=40>
<BR>Address2: <INPUT NAME="address2" TYPE="text" SIZE=40>
<BR>Email: <INPUT NAME="email" TYPE="text" SIZE=40>
<BR>Profession: <INPUT NAME="profession" TYPE="text" SIZE=40>
<BR>Speciality: <INPUT NAME="speciality" TYPE="text" SIZE=40>
<BR>License #: <INPUT NAME="license" TYPE="text" SIZE=40>
<BR><INPUT TYPE="SUBMIT" VALUE="Send Mail">
</FORM>
</HTML>
Have you tried setting the content type to "text/plain"
You could also try creating the body string in a new variable and passing that to the cdo object, ie:
newVar = "Name:" & name & vbCrLf & "Address:" & ....
objCDO.TextBody = newVar
I could be wrong about this but I didn't think any vb constants worked in asp? Wouldn't you need to define vbCrLf or include a header with it defined, ie:
vbCrLf = Chr(13) & Chr(10)
objCDO.TextBody = "Name: " & Name & vbCrLf & _
" Address: " & Address & vbCrLf & _
" Address2: " & Address2 & vbCrLf & _
" Email: " & Email & vbCrLf & _
" Profession: " & Profession & vbCrLf & _
" Speciality: " & Speciality & vbCrLf & _
" License #: " & License & vbCrLf & "."