Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

web form email without a mail client

Posted on 2004-04-21
4
Medium Priority
?
272 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 1000 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
Australian government abolished Visa 457 earlier this April and this article describes how this decision might affect Australian IT scene and IT experts.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…
Suggested Courses

916 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