Solved

web form email without a mail client

Posted on 2004-04-21
4
264 Views
Last Modified: 2009-02-11
I would like to build a web form and then allow them to submit this application. but i am confused on how the information would get sent to an email address, even though the machine it would be browsed on would not have an email client on it.   thank you
0
Comment
Question by:nexcool
  • 2
4 Comments
 
LVL 6

Expert Comment

by:pkaleda
ID: 10880681
You can create a form that passes the form data to a page on your server.  You can then create a script in asp, php, perl to send the email from your server.  There are many ways to do this.

I can provide an example if I know your server OS and webserver software.  I use ASP to compile the form data and send it to CDONTs on an IIS machine.

PK
0
 

Author Comment

by:nexcool
ID: 10881626
It would be windows 2000 server or 2003
0
 
LVL 6

Expert Comment

by:pkaleda
ID: 10881714
OK.  Here is your collection page in a simple form.  I have built this using cdonts that is on all windows 2000 systems.  This can be modified to use cdosys for 2003 server, or you can just copy the cdonts.dll from the 2000 to the 2003 box and register it.  

Form.asp

<HTML>
<FORM method='post' action='sendmail.asp'>
Email:<INPUT TYPE="text" NAME="email">
Name:<INPUT TYPE="text" NAME="Name">
<INPUT TYPE="submit">
</FORM>
</HTML>


SendMail.asp

<%
  Dim MyBody
  Dim MyCDONTSMail
  Dim email
  Dim name

name=Trim(Request.Form("Name"))
email=Trim(Request.Form("email"))

Set MyCDONTSMail = CreateObject("CDONTS.NewMail")
MyCDONTSMail.From="webmaster@yourdomain.com"
MyCDONTSMail.To= email
MyCDONTSMail.Bcc="webmaster@yourdomain.com"
MyCDONTSMail.Subject="Email Subject"
MyBody = "Dear " &Name&"," &VbCrLf
MyBody = MyBody & " " &VbCrLf
MyBody = MyBody & "Here is line one of the body."&VbCrLf
MyBody = MyBody & " " &VbCrLf
MyBody = MyBody & "Your email is: " & email &VbCrLf
MyBody = MyBody & " " &VbCrLf
MyBody = MyBody & "Sincerely," &VbCrLf
MyBody = MyBody & " " &VbCrLf
MyBody = MyBody & "Webmaster " &VbCrLf
MyCDONTSMail.body= MyBody
MyCDONTSMail.send
set MyCDONTSMail=nothing
%>

That is it.  You can add html code to the sendmail.asp page, or code to write info to a database as well.  

PK
0
 
LVL 6

Accepted Solution

by:
Lord_McFly earned 250 total points
ID: 10884815
The following example uses just a single page and has minor validation on the To, From, Subject & Meesage fields - once the email is sent it returns to the form with a message 'Message sent'

The page can be copied and pasted and works 'as is'

==========================================================================================================================
<%@ Language=VBScript %>
<%Option Explicit%>
<%
Dim objMail
Dim sForm(3), sErrMsg, sBody
Dim iLp

If Request.Form("Button") = "Send" then
      sErrMsg = ""
      
      For iLp = 0 to 3
            sForm(iLp) = Trim(Request.Form("f_"&iLp))
      Next
      
      If sForm(0) = "" then
            sErrMsg = "ERROR: To - required."
      Else
            If sForm(1) = "" then
                  sErrMsg = "ERROR: From - required."
            Else
                  If sForm(2) = "" then
                        sErrMsg = "ERROR: Subject - required."
                  Else
                        If sForm(3) = "" then
                              sErrMsg = "ERROR: Message - required."
                        End If
                  End If
            End If
      End If
      
      If sErrMsg = "" then
            sBody = ""
            sBody = sBody & "<!DOCTYPE HTML PUBLIC '-//IETF//DTD HTML//EN'>"
            sBody = sBody & "<html>"
            sBody = sBody & "<head>"
            sBody = sBody & "<title>Message...</title>"
            sBody = sBody & "<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'>"
            sBody = sBody & "</head>"
            sBody = sBody & "<body>"
            sBody = sBody & "<font face='Verdana' size='2' color='#000000'>"
            sBody = sBody & "You have received a message:<br><br>"
            sBody = sBody & "The Message:<br>"
            sBody = sBody & "================================================<br>"
            sBody = sBody & "<b>" & sForm(3) & "</b>"
            sBody = sBody & "</font>"
            sBody = sBody & "</body>"
            sBody = sBody & "</html>"
            
            'If using CDONTS to send emails then uncomment
            '================================================================
            Set objMail = Server.CreateObject("CDONTS.NewMail")
            objMail.BodyFormat = 0
            objMail.MailFormat = 0
            objMail.Body = sBody
            
            'If using CDOSYS to send emails then uncomment
            '================================================================
            'Set objMail = Server.CreateObject("CDO.Message")
            'objMail.HTMLBody = sBody
            
            'Common for both CDONTS & CDOSYS...
            '================================================================
            objMail.To = sForm(0)
            objMail.From = sForm(1)
            objMail.Subject = sForm(2)
            objMail.Send
            
            For iLp = 0 to 3
                  sForm(iLp) = ""
            Next
            
            sErrMsg = "NOTICE: Message sent."
      End If
End If

%>
<html>
<head>
<title>Email</title>
</head>
<body>
<form name="Email" method="post" action="">
<table  width="400" cellspacing="0" cellpadding="2" border="1">
      <tr>
            <td colspan="3" height="30" align="center"><b>MESSAGE CENTRE</b></td>
      </tr>
      <%If sErrMsg <> "" then%>
            <tr>
                  <td colspan="3" height="25"><%=sErrMsg%></td>
            </tr>
      <%End If%>
      <tr>
            <td width="100" height="25">To:&nbsp;</td>
            <td colspan="2">
                  <input type="text" name="f_0" size="29" value="<%=sForm(0)%>">
            </td>
      </tr>
      <tr>
            <td height="25">From:&nbsp;</td>
            <td colspan="2">
                  <input type="text" name="f_1" size="29" value="<%=sForm(1)%>">
            </td>
      </tr>
      <tr>
            <td height="25">Subject:&nbsp;</td>
            <td colspan="2">
                  <input type="text" name="f_2" size="33" value="<%=sForm(2)%>">
            </td>
      </tr>
      <tr>
            <td colspan="3" height="25">Message:</td>
      </tr>
      <tr>
            <td colspan="3">
                  <textarea rows="6" name="f_3" style="WIDTH: 400; HEIGHT: 100"><%=sForm(3)%></textarea>
            </td>
      </tr>
      <tr>
            <td colspan="3" height="25" align="center">
                  <input type="submit" name="Button" value="Send">
            </td>
      </tr>
</table>
</form>
</body>
</html>
===========================================================================================================================
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
MySQL database data submission 7 60
Using MS Code on my Mac 6 66
How can I split the array as 4 rows per line? 5 82
When should I use a controller? 3 22
Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
This video teaches users how to migrate an existing Wordpress website to a new domain.
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.

867 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now