Solved

web form email without a mail client

Posted on 2004-04-21
4
262 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
Envision that you are chipping away at another e-business site with a team of pundit developers and designers. Everything seems, by all accounts, to be going easily.
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…

707 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

15 Experts available now in Live!

Get 1:1 Help Now