• Notice regarding image hosts and attachments. See here.

(Classic) ASP Email Form?

Associate
Joined
12 Aug 2004
Posts
1,009
Location
Glasgow, Scotland
Hi folks,

I'm wondering if someone can give me a bit of a hand with sending an email via ASP?

I have my form as follows:

Code:
<form action="index.asp?pg=11" method="POST">

<input type="hidden" name="subject" value="Inquiry">
<input size=40 name="fullName">
<input size=40 name="email">
<input type="text" name="country" size="20">
<input type="text" name="partySize" size="20">
<input type="text" name="arrivalDate" size="20">
<input type="text" name="departureDate" size="20">
<textarea name="comments" rows=6 cols=40>
<input type="submit" value="Submit" name="Submit">

</form>

...but i'm not sure how to turn that into the ASP code for actually sending out the email to a fixed address. I've looked at a few tutorial sites but they looked extremely complicated compared to the php one i already have.

Cheers,

Steven.
 
It's not complex - I wonder what sites google threw up that look complicated...

The code to send the mail should be in the target of the form (naturally):

Code:
Set ObjMail = Server.CreateObject("CDONTS.NewMail")
objMail.From = varName & " <" & varEmail & ">"
objMail.To = "[email protected]"
objMail.Subject = "Contact from Your Website"
objMail.Body = varBody
objMail.Send
Set objMail = Nothing

Hardly rocket science.

:)
 
Cheers mate :)

So, should the following code work? (based on the form fields i posted originally)

Code:
<%
	fullName = Request.QueryString("fullName")
	email = Request.QueryString("email")
	country = Request.QueryString("country")
	partySize = Request.QueryString("partySize")
	arrivalDate = Request.QueryString("arrivalDate")
	departureDate = Request.QueryString("departureDate")
	comments = Request.QueryString("comments")

	varBody = country & partySize & arrivalDate & departureDate & comments

	Set ObjMail = Server.CreateObject("CDONTS.NewMail")
	objMail.From = fullName & " <" & email & ">"
	objMail.To = "[email protected]"
	objMail.Subject = "Enquiry"
	objMail.Body = varBody
	objMail.Send
	Set objMail = Nothing

	Response.Write "Thanks, your enquiry has been sent and we will get back to you shortly"
%>
 
Yup, that should work fine - assuming that CDONTS is working OK (works off of the local IIS SMTP server, which can either act as a server or as a relay).

You'll have to stick a newline (vbCrLf) in-between the parts of the body to make sure they end up on separate lines in the mail. There's other CDONTS properties to set to send an HTML email, but I am again assuming that you are happy with text-only mails.

HTH!
 
Back
Top Bottom