www.webdeveloper.com
Results 1 to 2 of 2

Thread: email.asp web form

  1. #1
    Join Date
    Jul 2008
    Location
    Norwich
    Posts
    27

    Thumbs up email.asp web form

    ok i had created a perl email form, but my hosts gave me this today

    http://www.custardface.co.uk/email.asp

    but i have no idea as to what ive got to do or change im going crazy haha

    Code:
    <%
    Dim strFrom, strTo, strSubject, strBody 'Strings for recipient, subject, boby
    Dim objCDOMail 'The CDO object
    
    
    'First we'll read in the values entered
    strFrom = Request.Form("From")
    strTo = Request.Form("to")
    
    
    'These would read the message subject and body if we let you enter it
    'strSubject = Request.Form("subject")
    'strBody = Request.Form("body")
    
    ' Both of these should be changed before you run this script.
    strSubject = Request.Form("subject")
    
    ' This is multi-lined simply for readability
    strBody = Request.Form("body")
    
    'We just check to see if someone has entered anything into the to field.
    'If it's equal to nothing we show the form, otherwise we send the message.
    'If you were doing this for real you might want to check other fields too
    'and do a little entry validation like checking for valid syntax etc.
    
    ' Note: I was getting so many bad addresses being entered and bounced
    ' back to me by mailservers that I've added a quick validation routine.
    If strTo = "" Or Not IsValidEmail(strTo) Then
    	%>
    	<FORM ACTION="./email.asp" METHOD="post">
    		From:&nbsp;
    		<INPUT TYPE="text" NAME="from" SIZE="30"></INPUT><BR>
    		
    		To:&nbsp;
    		<INPUT TYPE="text" NAME="to" SIZE="30"></INPUT><BR>
    
    		Subject:&nbsp;
    		<INPUT TYPE="text" NAME="subject" SIZE="30"></INPUT><BR>
    		
    		Message:&nbsp;
    		<TEXTAREA NAME="body" ROWS="10" COLS="40" WRAP="virtual"></TEXTAREA><BR>
    
    		<INPUT TYPE="submit" VALUE="Send Mail!"></INPUT>
    	</FORM>
    	<%
    Else
    	' Create an instance of the NewMail object.
    
    	Set objCDOMail = Server.CreateObject("CDO.Message")
    '	Set objCDOMail = Server.CreateObject("CDONTS.NewMail")
    	
    	' Set the properties of the object
    	
    	'***********************************************************
    	' PLEASE CHANGE THESE SO WE DON'T APPEAR TO BE SENDING YOUR
    	' EMAIL. WE ALSO DON'T WANT THE EMAILS TO GET SENT TO US
    	' WHEN SOMETHING GOES WRONG WITH YOUR SCRIPT... THANKS
    	'***********************************************************
    	
    	' This syntax works fine
    	'objCDOMail.From = "user@domain.com"
    	' But this gets you the appearance of a real name!
    	objCDOMail.From    = strFrom
    	objCDOMail.To      = strTo
    	objCDOMail.Subject = strSubject
    	objCDOMail.TextBody = strBody
    
    	' There are lots of other properties you can use.
    	' You can send HTML e-mail, attachments, etc...
    	' You can also modify most aspects of the message
    	' like importance, custom headers, ...
    	' Check the documentation for a full list as well
    	' as the correct syntax.
    
    	' Some of the more useful ones I've included samples of here:
    	'objCDOMail.Cc         = "user@domain.com;user@domain.com"
    	'objCDOMail.Bcc        = "user@domain.com;user@domain.com"
    	'objCDOMail.Importance = 1 '(0=Low, 1=Normal, 2=High)
    	'objCDOMail.AttachFile "c:\path\filename.txt", "filename.txt"
    
    	' I've had several requests for how to send HTML email.
    	' To do so simply set the body format to HTML and then
    	' compose your body using standard HTML tags.
    '	  objCDOMail.BodyFormat = 0 ' CdoBodyFormatHTML
    	
    	'Outlook gives you grief unless you also set:
    '	  objCDOMail.MailFormat = 0 ' CdoMailFormatMime
    
    	' THIS LINE SHOULD BE UNCOMMENTED TO ACTUALLY SEND THE
    	' MESSAGE.  PLEASE BE SURE YOU HAVE APPROPRIATE VALUES
    	' FOR TO AND FROM ADDRESSES AND HAVE CHANGED THE MESSAGE
    	' SUBJECT AND BODY BEFORE UNCOMMENTING THIS.
    	' Send the message!
    	objCDOMail.Send
    	
    	' Set the object to nothing because it immediately becomes
    	' invalid after calling the Send method.
    	Set objCDOMail = Nothing
    
    	Response.Write "Message sent to " & strTo & "!"
    	'Response.Write "Message ARE NO LONGER BEING SENT because of all the abuse the system was receiving!"
    End If
    ' End page logic
    %>
    
    <% ' Only functions and subs follow!
    
    ' A quick email syntax checker.  It's not perfect,
    ' but it's quick and easy and will catch most of
    ' the bad addresses than people type in.
    Function IsValidEmail(strEmail)
    	Dim bIsValid
    	bIsValid = True
    	
    	If Len(strEmail) < 5 Then
    		bIsValid = False
    	Else
    		If Instr(1, strEmail, " ") <> 0 Then
    			bIsValid = False
    		Else
    			If InStr(1, strEmail, "@", 1) < 2 Then
    				bIsValid = False
    			Else
    				If InStrRev(strEmail, ".") < InStr(1, strEmail, "@", 1) + 2 Then
    					bIsValid = False
    				End If
    			End If
    		End If
    	End If
    
    	IsValidEmail = bIsValid
    End Function
    %>
    
    <br>
    <br>
    Source Code: <a href="email.asp">email.asp</a>
    What do i change in the code and howdo i encorporate it into

    www.custardface.co.uk/details.html

    Thank you so much in advance

  2. #2
    Join Date
    Jan 2003
    Location
    USA
    Posts
    688
    So you were given the email.asp page to work on and I assume that the code you posted was from a sample e-mail page that actually works.

    Seems like one of the first things you'd want to do is change the field names to be name, email, and comment.

    And actually maybe to start with you might want to create another shorter sample page that e-mails with just the bare basics.

    Then add that code and a little more (i.e. the part with the posted fields info) into the details.asp page (i.e. page name extension changed from .html to be .asp)...

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles