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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

emailing a form via asp

Status
Not open for further replies.

jason12776

Technical User
Nov 15, 2001
93
US
Hello. My boss told me that I need to be able to email a form to a specific email address coding it with html, then using a CBO in ASP to handle the emailing portion. Could someone explain this to me and explain how I can find this code and incorporate it into my html code? I have never worked with ASP before.

thanks
 
The first thing that you have to do is make sure that smtp service was installed on the server. Then you can use the CDONTS object to send the mail.

Here are the basics for using CDONTS.
create the object
set shortmail = CreateObject("CDONTS.NewMail")

shortmail.From = "address@somwhere.com"
shortmail.To = "Toaddress@there.com"
shortmail.Subject = "Subject of email"
shortmail.BodyFormat = 0
shortmail.MailFormat = 0
shortmail.Importance = 2
shortmail.Body = "email text"
shortmail.Send
ending mail object
set shortmail = Nothing

You can replace the text in any of the fields with variables to make it more dynamic.

I hope that helps
Roj
 
Sounds great Roj, but not to ask a stupid question or anything, how do I tie this in with my html form? Where I have the action property in the form, would I use this asp page, or put a mailto: name@company.com? How could I do all this?
 
In your action you put the name of the asp page using the post method. Then in the asp page you need to set variables for your form fields.

Lets say that your form has name and email as fields. Then on your asp page you would do this.

<%@ language=vbscript%>
<%dim name,email
set name = Request.form(&quot;name&quot;)
set email = Request.form(&quot;email&quot;)

then in your mail script you can use these variables.

shortmail.To = email
shortmail.Subject = &quot;An Email for &quot;&name

Then afer you have all the email stuff you will want to either show the user a message.
<html>
<body>
<h1>Message sent</h1>
</body>
</html>
or you could send them to another page like this

Response.Redirect(&quot;new_page.html&quot;)

Roj
 
Great, now let me ask you this...I just set it up as action=&quot;mailto: name@company.com&quot; method=&quot;post&quot; and it works. Is that there a problem with that way?
 
No. You have to set it up as action=&quot;page.asp&quot; method=&quot;post&quot; using mailto: would just open there email program.
 
Ok, I see. What I want to do is send the link in an email, so then it shouldn't be a problem then since they already have their email open correct? It will be part of a web page, but only accessible with the link included from the email.
 
I don't know if I am understanding exactly what you are doing however, the CDONTS object does not use the users email it uses your email server to send the mail out. So it does not even matter if the person has email.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top