SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Oct 2010
    0 Post(s)
    0 Thread(s)

    Question Hassles with ASP Contact form using CDO.Message

    Having never had to use ASP for a contact form before, i'm struggling. Hopefully some kind soul will be able to give me some advice on the following:

    I found code here in these forums, and modified it to suit my form. Here is the result:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "">
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>Contact - Executive Project Management</title>
    ' Website Contact Form Generator 
    ' 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 Company
    Dim Title
    Dim Telephone
    Dim Mobile
    Dim Email
    Dim Referral
    Dim Enquiry
    ' get posted data into variables
    EmailFrom = Trim(Request.Form("EmailFrom")) 
    EmailTo = ""
    Subject = "Web Enquiry"
    Name = Trim(Request.Form("Name")) 
    Company = Trim(Request.Form("Company")) 
    Title = Trim(Request.Form("Title")) 
    Telephone = Trim(Request.Form("Telephone")) 
    Mobile = Trim(Request.Form("Mobile")) 
    Email = Trim(Request.Form("Email")) 
    Referral = Trim(Request.Form("Referral")) 
    Enquiry = Trim(Request.Form("Enquiry")) 
    ' validation
    Dim validationOK
    If (Trim(Name)="") Then validationOK=false
    If (Trim(Company)="") Then validationOK=false
    If (Trim(Email)="") Then validationOK=false
    If (validationOK=false) Then Response.Redirect("error.html?" & EmailFrom)
    ' prepare email body text
    Dim Body
    Body = Body & "Name: " & Name & VbCrLf
    Body = Body & "Company: " & Company & VbCrLf
    Body = Body & "Title: " & Title & VbCrLf
    Body = Body & "Telephone: " & Telephone & VbCrLf
    Body = Body & "Mobile: " & Mobile & VbCrLf
    Body = Body & "Email: " & Email & VbCrLf
    Body = Body & "Referral: " & Referral & VbCrLf
    Body = Body & "Enquiry: " & Enquiry & VbCrLf
    ' send email 
    Dim mail
    Set mail = Server.CreateObject("CDO.Message") 
    mail.To = EmailTo
    mail.From = EmailFrom
    mail.Subject = Subject
    mail.TextBody = Body
    if validationOK = true then
    response.redirect "ok.html" 'your redirect page goes here'
    end if
    However when I tried to submit the form I get the following error:

    CDO.Message.1 error '8004020d'

    At least one of the From or Sender fields is required, and neither was found.

    /contact.asp, line 70
    I've tried going through these forums and searching using google but i just feel like i'm going round in circles. Can anyone point me in the right direction for what i need to do to get this happening?

    Thanks in advance

  2. #2
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    2 Post(s)
    0 Thread(s)
    That seems a little - incomplete. (There is no Configuration defined). Check out these links for more info:

    Ian Anderson

  3. #3
    SitePoint Wizard bronze trophy
    Join Date
    Oct 2001
    Vancouver BC Canada
    5 Post(s)
    0 Thread(s)
    Yeah, I noticed things have changed a bit over the last few years, probably for more secure SMTP but none-the-less it can get confusing when things work on one server and not another.

    For CDO on the server I always add this line at the very top of the script:
    <!--METADATA TYPE="typelib"  UUID="CD000000-8B95-11D1-82DB-00C04FB1625D" NAME="CDO for Windows 2000 Library" -->
    Also recently I found that I had to add some configuration code to make things work on Win 2008 Server that I didn't need to use with Win 2003.

    My forms look a bit like this:
    Dim ObjMail
    Set ObjMail = Server.CreateObject("CDO.Message")
    sch = ""
    Set objConfig = CreateObject("CDO.Configuration")
    With objConfig.Fields
        .Item(sch & "sendusing") = 2
        .Item(sch & "smtpserver") = "domain-name or ip-address"
    End With
    Set objMail.Configuration = objConfig
    objMail.From = ""
    objMail.To = ""
    objMail.CC = ""
    objMail.Subject = "Your subject"
    mailbody = "<p>This is HTML, so put in your tags and apply fonts, etc... so your message looks good.</p>"
    objMail.HTMLBody = mailbody
    Set objMail = Nothing
    Andrew Wasson |
    Principal / Internet Development

  4. #4
    SitePoint Guru
    Join Date
    Jun 2007
    0 Post(s)
    0 Thread(s)
    Have you verified that "EmailFrom" and "EmailTo" actually have values ?

    The sample code uses these variable names but do they match the names of the corresponding fields in your form ?

Tags for this Thread


Posting Permissions

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