Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sending form information using a CDO email object

Status
Not open for further replies.

funkyspirit

Programmer
Oct 6, 2011
12
GB
Hello,

I have an ASP page that contains a form. Once the user submits the form, the information is sent to an email address using a CDO email object and a popup message appears saying that the information has been sent.

What I would like to do is to create an onclick event on the submit button that will trigger the creation of the email and the sending of the information. Since the email generation code is in the same page as the form that would prevent the email from being sent if the form is empty.

The submit button is an image and so far I haven't been able to get it to work.

Code:
<input type="image" name="submit" src="images/submit.png" width="115" height="39"/>

if request.Form("submit")<>"" then
                
                
                Set myMail=Server.CreateObject("CDO.Message")
   		myMail.Subject="Contact Request"
   		myMail.From = Request.Form("email")
    		myMail.To= "xxx@xxx.com"
    		'myMail.CC="xxx@xxx.com"
    		myMail.TextBody = "Name:"& Request.Form("name")& vbcrlf & vbcrlf & _
                "Email:" & Request.Form("email") & vbcrlf & vbcrlf &  _
                 "Telephone:" & Request.Form("telephone") & vbcrlf & vbcrlf & _
                 "Length of separation:" & Request.Form("separation") & vbcrlf & vbcrlf & _
                 "Location:" & Request.Form("location") & vbcrlf & vbcrlf & _
	         "Other location:" & Request.Form("other_location") & vbcrlf & vbcrlf 
                 "Divorce Agreed:" & Request.Form("divorce_agreement") & vbcrlf & vbcrlf & _
	         "Comments:" & Request.Form("comments")
	         myMail.Configuration.Fields.Item _
    		 ("[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/sendusing")=2[/URL]
    		 'Name or IP of remote SMTP server
    		 myMail.Configuration.Fields.Item _
    		 ("[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/smtpserver")[/URL] _
    	         ="127.0.0.1"
    		 'Server port
    		  myMail.Configuration.Fields.Item _
    		  ("[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/smtpserverport")[/URL] _
    		  =25 
    		  myMail.Configuration.Fields.Update
    		  myMail.Send
    		  set myMail=nothing
    		  %>
    		<script language="javascript"type="text/javascript">
	        alert("Thank you! Your request has been sent. One of our team members will be in touch with you shortly")
		</script>
    		<%end if%>
 
CDO is server side, javascript is clientside.

ASP code has completed before javascript even STARTS to run, and ASP code will not run again until an HTTP request is sent to the server.





Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum
 
Hi Chris,

Thank you for your answer.

How could I write this for it to work?

Thanks.
 
Check the error message returned from obj.send() if it is 0 show the success message.

an article I did many moons ago.

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top