Forum Moderators: open
I have a form that I need to simply send via e-mail to my clients inbox when the submit button is clicked. His form resides on a IIS server with ASP.
How hard is it to script this on the page and where can I find the simplest tutorial for this?
Thanks
Most NT servers will have either CDonts, ASPMail, ASPEmail or similar installed.
Once you've found out from the host which mail component they support, a quick search on Google should see you heading in the right direction.
There are quite a few email components like aspemail. Find out what you've got. You should have CDONTs but some of the others allow better html integration into the email, newsletters, and other things. Sending email with asp s very easy.
here's an example [brainjar.com...]
change the var - mailComp = "ASPMail" to "CDONTS"
DaveN
I actually looked at this earlier. I just don't understand how to define the body of the message:
Her is Xoc's (I have seen other example that are very similar):
Dim cdonts
Set cdonts = Server.CreateObject("CDONTS.NewMail")
Call cdonts.Send("from@domain.com","to@domain.com", "this is a subject", "this is a body", 1)
Set cdonts = Nothing
The part that says "this is a body" needs to contain a lot of info from the form. The "to@domain.com" I guess I can just type in my client's e-mail address. The subject I can just type in too.
For the body I seems I would need to created variables for all the fields and combine them in some way to say "Hey, we are all a part of the body of this e-mail!" Trust me I am so nuts that my code is now animated and it talks to me
[edited by: Xoc at 11:39 pm (utc) on Aug. 15, 2002]
[edit reason] fixed line break in code [/edit]
Dim BodyContent
BodyContent = Request.Form("Body")
Dim cdonts
Set cdonts = Server.CreateObject("CDONTS.NewMail")
Call cdonts.Send("from@domain.com","to@domain.com", "this is a subject", BodyContent, 1)
Set cdonts = Nothing
<added>Nice little loop aspdaddy :)</added>
[edited by: Xoc at 11:41 pm (utc) on Aug. 15, 2002]
[edit reason] Fixed line break in code [/edit]
List of Email Components [aspfaq.com]
aspdaddy you say to use the following for each field:
strBody = strBody & item & ": " & request(item) & vbcrLf
Next
I am assuming that item is to be replaced with the name of the field. Could you please demostrate how the code with look with two fields like FirstName and LastName? Once I get this down I should be good to go.
The form is a collection and using the for..each you dont need to worry about the form field names
art all, it gets everything by looping thru the form.
This is a quick & dirty method, If you plan to do responders for visitors/shoppers etc. you will probably want to format & exclude some fields ( like the submit button at least !)
and will be be writing a line of code for each field :
body=body & "First Name: " & request("First Name") & vbCrLf etc..
<%@ language="VBSCRIPT" %>
<html>
<head>
<title>Form Sent</title>
</head>
<body>
<%
strSubject = strSubject & request("FirstName") & " " & request("LastName") & "'s Adventure Form"
strBody = strBody & item & ": " & request(item) & vbcrLf
Next
Set MailObject = Server.CreateObject("CDONTS.NewMail")
MailObject.To = "dtaylor@phelpsdodge.com"
MailObject.Subject = strSubject
MailObject.Body = strBody
MailObject.Send
Set MailObject = Nothing
Write "Your Form has been sent."
Write "Subject:" & strSubject
Write "Message:" & strBody
%>
</body>
</html>
'assign variables
strSubject = strSubject & request.form("FirstName") & " " & request.form("LastName") & "'s Adventure Form"
'for each loop
For each item in request.form
strBody = strBody & item & ": " & request(item) & vbcrLf
Next
'set mail objects
Set MailObject = Server.CreateObject("CDONTS.NewMail")
MailObject.To = "dtaylor@phelpsdodge.com"
MailObject.Subject = strSubject
MailObject.Body = strBody
MailObject.Send
Set MailObject = Nothing
'write to the page
response.write("Your Form has been sent.<br>")
response.write("Subject:" & strSubject & "<br>")
response.write("Message:" & strBody)
%>
I am getting nowhere with the Support Desk on my Host. They don't have a clue what components are installed on their IIS server.
<added>Just got of eternal hold and I was told that the IIS server supports all standard .dll's except for 'file system'. Mean anything to you?</added>
Its NOT an Email component like JMail etc. It passes the message to Exchange server, which sends it, you may need to define the SMTP server, though usually not, it defaults.
check for err.Number after the create object line.
filesyetm object is used for manipulating drives/folders/files etc. It sucks if its not available.
Search google groups for the ASP script that lists all installed components on your server.
If they have anything else it will be aspemail. try this.
<%
Set Mail = Server.CreateObject("Persits.MailSender")
Mail.Host = "smtp.smtp-server.com" ' Specify a valid SMTP server
Mail.From = "sales@veryhotcakes.com" ' Specify sender's address
Mail.FromName = "VeryHotCakes Sales" ' Specify sender's name
Mail.AddAddress "andy@andrewscompany.net", "Andrew Johnson, Jr."
Mail.AddReplyTo "info@veryhotcakes.com"
Mail.Subject = "Thanks for ordering our hot cakes!"
Mail.Body = "Dear Sir:" & Chr(13) & Chr(10) & _
"Thank you for your business."
On Error Resume Next
Mail.Send
If Err <> 0 Then
Response.Write "Error encountered: " & Err.Description
End If
%>
Set all emails to you and make any additional changes like mail server. If it doesn't work no aspemail.