Link to home
Start Free TrialLog in
Avatar of stacee
stacee

asked on

ASP to send email w/form info

I need an ASP script that will send an email to a prescribed email address when a form is submitted.  I need the email to show some of the form info. ASPQMail is out of the question.  I am running an IIS server with full MS support.

Any of you cute experts wanna help me? =)
Avatar of stacee
stacee

ASKER

Edited text of question.
why not use a cgi script?  
Sure.  Do you have access to the server?  If so, Install JMail from http://www.dimac.net.  If not, what ASP mail components do you have avaliable there at your site?  

BUt, you can do this:

<%
For Each item in Request.Form
   MessageBody = MessageBody & Item & " " & Request(Item) & vbCrlf
Next

CreateMailObject
MailObject.Body = MessageBody
MailObject.Send
%>

This will send you every item in the form with the response.

I take down the address of JMail !

But, if you haven't got any mail component I suggest the following :

1°) A rough and plain solution, if there is no need to use Javascript
 <FORM METHOD="Post" ACTION="mailto: ... the email address
     ...?subject=..."  ENCTYPE="text/plain">
     <input type="hidden" name="Item1" value="Contact">
     <input type="text" name="Item2" value="">
     <input type="Checkbox" name="Item3" > etc.
     <input type="Submit" value="Send"></FORM>

2°) If some fields are required, or are to be checked, it's a bit more difficult, because Netscape doesn't run an action="mailto:" via JavaScript. I use a "two-form solution" :
MyPgm.asp :
...
MySwitch = Request("MySwitch")
If MySwitch = "2" Then
      Item11 = Request("Item1")
      Item12 = Request("Item2") etc.
...
SELECT CASE MySwitch
CASE "1" Proc_1
CASE "2" Proc_2 etc.
...
SUB Proc_1()
<FORM METHOD="Post" ACTION="MyPgm.asp">
<INPUT TYPE="Hidden" NAME="MySwitch" VALUE="2">
               - a usual form -
<INPUT TYPE = "Button" VALUE = "Confirm"
onClick = "MyChecking(this.form);">
End Sub

SUB Proc_2()
               - displaying of the various values -
<FORM METHOD="Post" ACTION="mailto:MyEmailAddress?subject=MySubject"
ENCTYPE="text/plain">
<INPUT TYPE="Hidden" NAME="MyFirstItem" VALUE="<%=Item1 %>">
<INPUT TYPE="Hidden" NAME="MySecondItem" VALUE="<%=Item2%>">etc.
     
<INPUT TYPE = "Submit" VALUE = "Send" ></FORM>
End Sub

The main asset of this setup is its ability to an easy additional database update.      ;)
In this case, don't forget to handle the apostrophes (' -> '').        







(the example quoted below is OK with Ie4, Ne4, Ne3, because it doesn't involve any
javascript. If some fields are compulsory, or are to be checked, it's a bit more difficult, because
Netscape doesn't run an action="mailto:" via JavaScript).
Please ignore the last 3 lines : I cut and paste, and whoops!
Avatar of stacee

ASKER

MasseyM,

How do I set the email address with your script?:

<%
      For Each item in Request.Form
         MessageBody = MessageBody & Item & " " & Request(Item) & vbCrlf
      Next

      CreateMailObject
      MailObject.Body = MessageBody
      MailObject.Send
      %>

Stacee
I will tell you as soon as you tell me what email component you are going to use :).  It will be different with each component.  So, which component?
I've been having the exact same problem:  try this:

msgObj = Server.CreateObject("CDONTS.NewMail")

msgObj.To = "someone@mail.com"

msgObj.From = Request.ServerVariables("Logon_User")
' this will be the blank string if the user has logged on
' anonymously, otherwise it will be their login id

msgObj.Subject = "Online Form Submission"

msgObj.Body = Request.Form("form_Field")

msgObj.Importance = 1 '1 - high, 3 - low priority

msgObj.Send


Notes:

The body property can be set to any string type variable, which can be about 2 billion characters long.  Use chr(10) or chr(13) for carriage returns within the message (thus you can format the email however you like)

Avatar of stacee

ASKER

MasseyM,

We have decided to use JMail.  Since this was provided by you, please answer.

Canadian5,

Your script may work, but since my boss has decided to use JMail, it is only fair to give the points to MassyM.

Thanks to all =)

Stacee
ASKER CERTIFIED SOLUTION
Avatar of MasseyM
MasseyM

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of stacee

ASKER

One more question...

What would be the correct syntax if I wanted to add another recipient to the email, something like the following?:

JMail.AddRecipient "theiremail@any.com"
JMail.AddRecipient "theiremail2@any.com"

Stacee
Correct!

Take a look at tech.dimac.net for a TON of examples and documentation for the JMail component.

Later,

Matt

P.S. if you need any more help on the matter, you can email at masseym@mrqcorp.com