sending form mail using CDO

Discussion in 'Site Programming, Development and Design' started by 0015100, Sep 21, 2011.

  1. I am an old html dinosaur trying to help a group out with an .asp site that was designed for them years ago and never used.

    I have the site up and running all except the "contact" form. I have read through all of the posts here on using form mail with CDO, and I am still having no luck. I copied the code provided at the win host website and put it in the form.

    I keep getting an error code pointing the to the line of code containing objMessage.Send

    It's a pretty simple form with only three fields. I was wondering if someone can point out where I have gone wrong. The code is below.

    Thank you,
    Glenn



    <%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <html>
    <head>
    <title>Florida Bipartisan Civic Affairs Group</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <link href="/ui/main.css" rel="stylesheet" type="text/css">
    <script language="JavaScript" type="text/JavaScript" src="/ui/functions.js"></script>
    <script type="text/javascript">
    function MM_validateForm() { //v4.0
    if (document.getElementById){
    var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
    for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=document.getElementById(args);
    if (val) { nm=val.name; if ((val=val.value)!="") {
    if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
    if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
    } else if (test!='R') { num = parseFloat(val);
    if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
    if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
    min=test.substring(8,p); max=test.substring(p+1);
    if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
    } if (errors) alert('The following error(s) occurred:\n'+errors);
    document.MM_returnValue = (errors == '');
    } }
    </script>
    </head>
    <body onLoad="MM_preloadImages('/ui/mission02.gif','/ui/history02.gif','/ui/what02.gif','/ui/current02.gif','/ui/meetings02.gif','/ui/signup02.gif','/ui/board02.gif','/ui/info02.gif','/ui/links02.gif','/ui/contact02.gif')">
    <div id="container">
    <!--#include virtual="/ui/top.asp"-->
    <!--#include virtual="/ui/banner.asp"-->
    <!--#include virtual="/ui/nav.asp"-->
    <div id="content">
    <h1>contact</h1>
    <form name="contact" method="post" action="">
    <label for="Name:">Name:</label>
    <br>
    <input type="text" name="Name:" id="Name:">
    <br>
    <label for="Email Address:">Email Address:</label>
    <br>
    <input type="text" name="Email Address:" id="Email Address:">
    <br>
    <label for="Comments:">Comments:</label>
    <br>
    <textarea name="Comments:" id="Comments:" cols="45" rows="5"></textarea>
    <br>
    <input name="Submit" type="submit" id="Submit" onClick="MM_validateForm('Name:','','R','Email Address:','','RisEmail','Comments:','','R');return document.MM_returnValue" value="Submit">
    <br>
    </form>
    <h2>&nbsp;</h2>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    </div>
    <!--#include virtual="/ui/footer.asp"-->
    </div>
    </body>
    <%
    set objMessage = createobject("cdo.message")
    set objConfig = createobject("cdo.configuration")
    Set Flds = objConfig.Fields

    Flds.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
    Flds.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") ="mail.floridabipartisan.com"

    ' ' Passing SMTP authentication
    Flds.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 'basic (clear-text) authentication
    Flds.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") ="[email protected]"
    Flds.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = myWinhost password"

    Flds.update
    Set objMessage.Configuration = objConfig
    objMessage.To = "[email protected]"
    objMessage.From = "[email protected]"
    objMessage.Subject = "New Task"
    objMessage.fields.update
    objMessage.HTMLBody = "body"
    objMessage.Send
    %>
    </html>
     
    Last edited by a moderator: Oct 14, 2015
  2. I hate to reply to my own post but I got this form to work by adding the following line of code:

    Set objCDO = Nothing

    What I don't understand is how to get it to send the data from the form fields. It sends me whatever I put after objMessage.HTMLBody =

    How do I get it to send me whatever is input by the user into the form fields?

    Thank you
     

Share This Page