Forum Moderators: open

Message Too Old, No Replies

ASP newbie

         

pcguru333

1:39 pm on Aug 14, 2002 (gmt 0)

10+ Year Member



I am an HTML/CSS guru but I am clueless when it comes to most scripting.

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

JuDDer

1:45 pm on Aug 14, 2002 (gmt 0)

10+ Year Member



It's very easy to do, but you'll need a component on the server for sending the mail.

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.

korkus2000

1:47 pm on Aug 14, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Here is the tutorial that taught me using CDONTs.
[asp101.com...]

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.

pcguru333

2:05 pm on Aug 14, 2002 (gmt 0)

10+ Year Member



Thanks for the help I have some experience with VB SCripting but not enough, I see how most of the asp is setup using the CDONTS but how do I get the form data into the body of the message?

Sorry but I feel really disconnected right now. And my google searches are leading to a lot of dead ends.

korkus2000

2:13 pm on Aug 14, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



'strSubject or any other variable you dim out to be the subject variable.
objCDOMail.Subject = strSubject

DaveN

2:15 pm on Aug 14, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



pcguru333

here's an example [brainjar.com...]

change the var - mailComp = "ASPMail" to "CDONTS"

DaveN

korkus2000

2:16 pm on Aug 14, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Here is xoc's short and sweet. look at message 4.
[webmasterworld.com...]

Sinner_G

2:17 pm on Aug 14, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



On this subject, does anyone know of a free ASPMail-like tool?

korkus2000

2:19 pm on Aug 14, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What do mean? Component. Both cdonts and aspemail are free. To code them are quite easy so no programs really delve into it. I think dreamweaver does have cdonts capability.

DaveN

2:19 pm on Aug 14, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Sinner_G

aspemail is free www.aspemail.com

DaveN

Sinner_G

2:32 pm on Aug 14, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes, meant components. I had ASPMail evaluation, but it ran out. I guess there won't be much to change in the code for other components to work, if anything.

Thanks for the fast answers.

Sinner

pcguru333

2:37 pm on Aug 14, 2002 (gmt 0)

10+ Year Member



korkus

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]

pcguru333

2:40 pm on Aug 14, 2002 (gmt 0)

10+ Year Member



To answer Sinner_G, ASPMail and ASPEmail are two different things. I know that ASPMail has an evaluation copy but ASPEMail is free. At www.aspemail.com

aspdaddy

2:45 pm on Aug 14, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member




I just don't understand how to define the body of the message

Easy way , without formatting etc..

For each item in request.form
strBody = strBody & item & ": " & request(item) & vbcrLf
Next

korkus2000

2:48 pm on Aug 14, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This should work. Duplicate body for the subject if you want user input on that too. The page is expecting a form feild with the name Body (hopefully a string).

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]

aspdaddy

2:52 pm on Aug 14, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



fyi

List of Email Components [aspfaq.com]

pcguru333

2:56 pm on Aug 14, 2002 (gmt 0)

10+ Year Member



OK korkus I understand how to put the object in the Send line, thanks for helping there.

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.

korkus2000

2:58 pm on Aug 14, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



item is calling all form fields and looping through them with a <br> after each in the body. Should work as seen. It is making the assumption that all form fields are for the body though.

aspdaddy

3:07 pm on Aug 14, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



pcguru333,

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..

korkus2000

3:08 pm on Aug 14, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



To clarify a first name last name scenerio would look like this in the body of the email using aspdaddy's for each loop.

fname: Joe
lname: Schmoe
submit: Submit

I am having my daily episode :)

aspdaddy

3:12 pm on Aug 14, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



My favorite :
JMail.Subject = "Wow I just sold another - " & request("product") & " via " & request("first_referrer") & "!"

:-)

korkus2000

3:16 pm on Aug 14, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I give some of my clients that stuff.

body = "Hi my name is " & request.form("name") & " and I want to sign up for your newsletter with my email address" & request.form("email") & "!" & vbCrLf

emails with just name and email are so boring. You got to add a little spice ;)

pcguru333

3:18 pm on Aug 14, 2002 (gmt 0)

10+ Year Member



OK I understand how the loop works and I understand how to code a line for each field If I want more formatting.

So I just have to write my script and test it. Trust me I'll be back if I have more questions

8^)

Once I get this down I will become an ASP guru, kinda fun!

pcguru333

3:49 pm on Aug 14, 2002 (gmt 0)

10+ Year Member



OK I screwed up somewhere I know it is probably syntax or I scripted it wrong. I just get page cannot be displayed when I submit the form. Here is the code in the asp page:

<%@ 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>

korkus2000

3:55 pm on Aug 14, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



try this
<%
'declare variables
dim strSubject
dim strBody

'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)
%>

pcguru333

4:13 pm on Aug 14, 2002 (gmt 0)

10+ Year Member



Progress has been made.

The script is pulling the data and writes it to the page YEAH!

but it doesn't send an e-mail. Thanks to korkus I was missing a very important line in my code.

pcguru333

4:32 pm on Aug 14, 2002 (gmt 0)

10+ Year Member



Is it possible that I need to define the SMTP server?

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>

aspdaddy

4:54 pm on Aug 14, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Are you using NT4 or Win 2K ?
I had a lot of probs with CDO on NT4.

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.

pcguru333

5:15 pm on Aug 14, 2002 (gmt 0)

10+ Year Member



I guess I am screwed. I will have to hold eternally to find out the Windows OS.

What is the full statement for checking the err.Number? Is it just a Write err.Number or something along those lines?

korkus2000

5:20 pm on Aug 14, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



No filesystem! That sucks. No saving files to your drive.

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.

This 38 message thread spans 2 pages: 38