Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

ASP to send email w/form info

Posted on 1999-07-23
12
Medium Priority
?
200 Views
Last Modified: 2013-12-25
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? =)
0
Comment
Question by:stacee
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
  • 2
  • +2
12 Comments
 

Author Comment

by:stacee
ID: 1864331
Edited text of question.
0
 
LVL 3

Expert Comment

by:messentary
ID: 1864332
why not use a cgi script?  
0
 
LVL 10

Expert Comment

by:MasseyM
ID: 1864333
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.

0
Looking for a new Web Host?

Lunarpages' assortment of hosting products and solutions ensure a perfect fit for anyone looking to get their vision or products to market. Our award winning customer support and 30-day money back guarantee show the pride we take in being the industry's premier MSP.

 

Expert Comment

by:sayasenh
ID: 1864334
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).
0
 

Expert Comment

by:sayasenh
ID: 1864335
Please ignore the last 3 lines : I cut and paste, and whoops!
0
 

Author Comment

by:stacee
ID: 1864336
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
0
 
LVL 10

Expert Comment

by:MasseyM
ID: 1864337
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?
0
 

Expert Comment

by:canadian5
ID: 1864338
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)

0
 

Author Comment

by:stacee
ID: 1864339
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
0
 
LVL 10

Accepted Solution

by:
MasseyM earned 1800 total points
ID: 1864340
Do you need to know how to implement JMail with my script?  If so, here it is:

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

Set JMail = Server.CreateObject("JMail.SMTPMail")

' This is my local SMTP server
JMail.ServerAddress = "mail.yourdomain.com:25"

' This is you....
JMail.Sender = "youremail@yourdomain.net"
JMail.Subject = "Here you go..."

' The recipients mailbox note the lack of a equal sign).
JMail.AddRecipient "theiremail@any.com"

JMail.Body = MessageBody

' 1 - highest priority (Urgent)
' 3 - normal
' 5 - lowest

JMail.Priority = 3

If JMail.Execute then
  response.Write "Message has been sent."
Else
  Response.Write "Mail was not sent.  There has been an error.<BR>" & vbCrlf
Response.Write "ERROR MESSAGE: " & JMail.ErrorMessage & "<BR>" & vbcrlf
    Response.Write "ERROR SOURCE: " & JMail.ErrorSource & "<BR>" & vbcrlf

End If
%>


0
 

Author Comment

by:stacee
ID: 1864341
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
0
 
LVL 10

Expert Comment

by:MasseyM
ID: 1864342
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

0

Featured Post

Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When the s#!t hits the fan, you don’t have time to look up who’s on call, draft emails, call collaborators, or send text messages. An instant chat window is definitely the way to go, especially one like HipChat. HipChat is a true business app. An…
Without even knowing it, most of us are using web applications on a daily basis.  In fact, Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We generally confuse these web applications to…
The viewer will learn how to count occurrences of each item in an array.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Suggested Courses

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question