SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Jul 2005
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Contact form using ASP

    Hi,

    Im a complete asp newbie,

    Im trying to make a contact form from my local pc so that you can enter in your details and it will send an email to my account. Ive tried the code i got off a generator and i cant get it too work, i dont want anything special at all, it just needs to be able to work from my local pc. Can anyone help? its driving me insane...

    contact.htm

    Code:
    <form method="POST" action="contact.asp">
    Fields marked (*) are required
    
    <p>Email From:* <br>
    <input type="text" name="EmailFrom">
    <p>Name:<br>
    <input type="text" name="Name">
    <p>TelephoneNumber:* <br>
    <input type="text" name="TelephoneNumber">
    <p>Street1:<br>
    <input type="text" name="Street1">
    <p>Street2:<br>
    <input type="text" name="Street2">
    <p>City:<br>
    <input type="text" name="City">
    <p>County:<br>
    <input type="text" name="County">
    <p>YourMessage:<br>
    <textarea name="YourMessage"></textarea>
    <p><input type="submit" name="submit" value="Submit">
    </form>
    <p>
    Contact.asp

    Code:
    <%
    ' Website Contact Form Generator 
    ' http://www.tele-pro.co.uk/scripts/contact_form/ 
    ' This script is free to use as long as you  
    ' retain the credit link  
    
    ' declare variables
    Dim EmailFrom
    Dim EmailTo
    Dim Subject
    Dim Name
    Dim TelephoneNumber
    Dim Street1
    Dim Street2
    Dim City
    Dim County
    Dim YourMessage
    
    
    ' get posted data into variables
    EmailFrom = Trim(Request.Form("EmailFrom")) 
    EmailTo = "daniel.obrien12@btinternet.com"
    Subject = "Contact"
    Name = Trim(Request.Form("Name")) 
    TelephoneNumber = Trim(Request.Form("TelephoneNumber")) 
    Street1 = Trim(Request.Form("Street1")) 
    Street2 = Trim(Request.Form("Street2")) 
    City = Trim(Request.Form("City")) 
    County = Trim(Request.Form("County")) 
    YourMessage = Trim(Request.Form("YourMessage")) 
    
    
    ' validation
    Dim validationOK
    validationOK=true
    If (Trim(EmailFrom)="") Then validationOK=false
    If (Trim(TelephoneNumber)="") Then validationOK=false
    If Not (IsNumeric(TelephoneNumber)) Then validationOK=false
    If (validationOK=false) Then Response.Redirect("error.htm?" & EmailFrom)
    
    ' prepare email body text
    Dim Body
    Body = Body & "Name: " & Name & VbCrLf
    Body = Body & "TelephoneNumber: " & TelephoneNumber & VbCrLf
    Body = Body & "Street1: " & Street1 & VbCrLf
    Body = Body & "Street2: " & Street2 & VbCrLf
    Body = Body & "City: " & City & VbCrLf
    Body = Body & "County: " & County & VbCrLf
    Body = Body & "YourMessage: " & YourMessage & VbCrLf
    
    
    ' send email 
    Dim mail
    Set mail = Server.CreateObject("CDONTS.NewMail") 
    mail.To = EmailTo
    mail.From = EmailFrom
    mail.Subject = Subject
    mail.Body = Body
    mail.Send 
    
    ' redirect to success page 
    Response.Redirect("ok.htm?" & EmailFrom)
    %>
    This is the error i get -

    Error Type:
    Server object, ASP 0177 (0x800401F3)
    Invalid class string
    /MyWeb/contact.asp, line 54

    thankyou

  2. #2
    SitePoint Member
    Join Date
    Mar 2006
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try the following asp code. I used CDO.Message instead of CDONT.NewMail. CDONTS still works but may cause issues down the road for you.

    <%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>Untitled Document</title>
    </head>
    <body>
    <%
    ' Website Contact Form Generator
    ' http://www.tele-pro.co.uk/scripts/contact_form/
    ' This script is free to use as long as you
    ' retain the credit link

    ' declare variables
    Dim EmailFrom
    Dim EmailTo
    Dim Subject
    Dim Name
    Dim TelephoneNumber
    Dim Street1
    Dim Street2
    Dim City
    Dim County
    Dim YourMessage


    ' get posted data into variables
    EmailFrom = Trim(Request.Form("EmailFrom"))
    EmailTo = "jmartin@gcc.vccs.edu"
    Subject = "Contact"
    Name = Trim(Request.Form("Name"))
    TelephoneNumber = Trim(Request.Form("TelephoneNumber"))
    Street1 = Trim(Request.Form("Street1"))
    Street2 = Trim(Request.Form("Street2"))
    City = Trim(Request.Form("City"))
    County = Trim(Request.Form("County"))
    YourMessage = Trim(Request.Form("YourMessage"))


    ' validation
    Dim validationOK
    validationOK=true
    If (Trim(EmailFrom)="") Then validationOK=false
    If (Trim(TelephoneNumber)="") Then validationOK=false
    If Not (IsNumeric(TelephoneNumber)) Then validationOK=false
    If (validationOK=false) Then Response.Redirect("error.htm?" & EmailFrom)

    ' prepare email body text
    Dim Body
    Body = Body & "Name: " & Name & VbCrLf
    Body = Body & "TelephoneNumber: " & TelephoneNumber & VbCrLf
    Body = Body & "Street1: " & Street1 & VbCrLf
    Body = Body & "Street2: " & Street2 & VbCrLf
    Body = Body & "City: " & City & VbCrLf
    Body = Body & "County: " & County & VbCrLf
    Body = Body & "YourMessage: " & YourMessage & VbCrLf


    ' send email
    Dim mail
    Set mail = Server.CreateObject("CDO.Message")
    mail.To = EmailTo
    mail.From = EmailFrom
    mail.Subject = Subject
    mail.TextBody = Body
    mail.Send

    if validationOK = true then
    response.redirect "untitled-5.htm" 'your redirect page goes here'
    end if

    %>

    </body>
    </html>

  3. #3
    SitePoint Member
    Join Date
    Jul 2005
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thankyou thankyou thankyou.... i honestly thought it would never work...


Bookmarks

Posting Permissions

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