Forum Moderators: open

Message Too Old, No Replies

cdo email script not sending

         

tjones

10:09 pm on Mar 9, 2004 (gmt 0)

10+ Year Member



Hi there,

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>

TheDave

11:53 pm on Mar 9, 2004 (gmt 0)

10+ Year Member



I'm no expert, but heres a couple of ideas

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)

wackal

3:46 am on Mar 10, 2004 (gmt 0)

10+ Year Member



try changing objCDO.TextBody

to just objCDO.Body

mattglet

12:40 pm on Mar 10, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



TheDave-
vbCrLf has the ability to be used without defining it. No worries there.

tjones-

Try:

if not objCDO.Send then
'throw error
else
response.redirect("responsepage.htm")
end if

-Matt

tjones

8:52 pm on Mar 10, 2004 (gmt 0)

10+ Year Member



Thanks for all the ideas! Mattglet - i was missing that piece of code -- i've put "If Email <> "" THEN
sendMail " and it sends fine now... the only thing is that the variables are not getting passed into the email i'm receiving? It sends fine, inserts the text that I have specified in this section but doesn't pass the variables ... anyone have any idea what might be stopping that? thanks in advance for advice anyone may have!

objCDO.TextBody = "Name: " & Name & vbCrLf & _
" Address: " & Address & vbCrLf & _
" Address2: " & Address2 & vbCrLf & _
" Email: " & Email & vbCrLf & _
" Profession: " & Profession & vbCrLf & _
" Speciality: " & Speciality & vbCrLf & _
" License #: " & License & vbCrLf & "."

mattglet

11:16 pm on Mar 10, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



response.write the vars, to make sure they are actually getting passed. are they getting into your sub?

-Matt