Solved

Help with Form submission using ASP and the CDOSYS object.

Posted on 2004-10-27
152 Views
Last Modified: 2010-04-06
Hi, I am having a nightmare.  I have a website and I am trying to submit forms details to my email using ASP with the CDOSYS object.

I have the following code

<%

If request("submit") <> "" THEN
Set objEMail = Server.CreateObject("CDO.Message")
Set objConfig = Server.CreateObject("CDO.Configuration")
Set Confi = objConfig.Fields
Confi("http://schemas.microsoft.com/cdo/configuration/sendusing") = 1
Confi("http://schemas.microsoft.com/cdo/configuration/smtpserverpickupdirectory") = "C:\inetpub\mailroot\pickup"
Confi.Update
Set objEMail.Configuration = objConfig
objEMail.To = "myemail@blah,blah,blah.co.uk"
objEMail.From = Request("from")
objEMail.Subject = Request("subject")
objEMail.TextBody = Request("message")  
objEMail.Send
Set objEMail = Nothing

Response.Write("Message Sent")
Else

%>

<form method="post" action="this.asp">
From Email: <INPUT type=text name="from"><br />
Subject: <INPUT type=text name="subject"><br />
Message: <TEXTAREA name="message" rows=10 cols=40></TEXTAREA><br />
<INPUT type="submit" value="Send" name="submit">
</form>

<%
End If
%>

I get no errors and my page reloads again as requested, but know information is sent to my email address why????

Hope someone can help......bye the way have changed my email address in the code and replaced it with a made up address...hence "myemail@blah,blah,blah.co.uk".

It sending me around the bend...please help.Cheers



0
Question by:dthomas31uk
    9 Comments
     
    LVL 13

    Expert Comment

    by:davidlars99
    what do you mean by this?
    > I get no errors and my page reloads again as requested
    0
     
    LVL 2

    Expert Comment

    by:MGrassman
    Is this a server you own or a hosting company.

    If its a hosting company make sure
        Confi("http://schemas.microsoft.com/cdo/configuration/smtpserverpickupdirectory") = "C:\inetpub\mailroot\pickup"
    is the correct setting.

    If it's your machine are you able to send emails through your smpt server any other way.

    0
     

    Author Comment

    by:dthomas31uk
    The page this.asp is the name of the actual page that the code is in.  I get no errors but no data is sent to the mail address in question
    0
     
    LVL 2

    Expert Comment

    by:MGrassman
    I'm sure you have done this but have you checked your spam mail or anything like that to see if it's getting re-routed.
    0
     
    LVL 13

    Expert Comment

    by:nurbek
    objEMail.From = Request("from")

    should be a valid email

    0
     

    Author Comment

    by:dthomas31uk
    Dear nurbek...have just discovered that...thank you was ...entering anything in the form field while I was testing it...it works fine now.  Thanks

    One other question for you how do I send information if I have more than four form fields on my web page because have discovered the objEMail. only has four parameters that allow you to store form data which are objEMail.To, objEMail.From , objEMail.Subject, objEMail.TextBody.  Are there any other objEmail parameters or do you have to write code differently.

    Thank you
    0
     
    LVL 13

    Expert Comment

    by:nurbek
    'add to show the from name
     objCDOMail.From = "Sender<sender@sender.com>"

    'to send in html format
    objCDOMail.MailFormat = 0
    objCDOMail.BodyFormat = 0
    objCDOMail.Body = "line 1<br> Line 2"

    0
     

    Author Comment

    by:dthomas31uk
    Dear Nurbek How does that work then...can you explain please..... say I have got 7 forms
    one called To,
    one called from,
    one called subject
    one called comments,
    one called dateofstart
    one called dateoffinish
    one called telephone

    Cheers
    0
     
    LVL 13

    Accepted Solution

    by:
    you have to organize it according to your code, make the desired message and then send it
    msg = "hi, <br>" & Request("name") ....

    here how to send the whole form elements

    Dim myMessage  

    'to get form elements
     
     For Each Field In Request.Form
              myMessage = myMessage & "<b>" &  Field & "</b>: " & Request.Form(Field) & "<BR>" & vbCrLf
         Next 'Field

    Set objEMail = Server.CreateObject("CDO.Message")
    Set objConfig = Server.CreateObject("CDO.Configuration")
    Set Confi = objConfig.Fields
    Confi("http://schemas.microsoft.com/cdo/configuration/sendusing") = 1
    Confi("http://schemas.microsoft.com/cdo/configuration/smtpserverpickupdirectory") = "C:\inetpub\mailroot\pickup"
    Confi.Update
    Set objEMail.Configuration = objConfig
    objEMail.To = "myemail@blah,blah,blah.co.uk"
    objEMail.From = Request("from")
    objEMail.Subject = Request("subject")
    objEMail.MailFormat = 0
    objEMail.BodyFormat = 0
    objEMail.TextBody = myMessage  
    objEMail.Send
    Set objEMail = Nothing
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Anonabox PRO Tor & VPN Router

    PRO is the most advanced way to fortify your privacy and online anonymity by layering the Tor network with VPN services. Use both together or separately, and without needing to download software onto your devices.

    Article by: Matthew
    I am a very big proponent of technology compliance standards and strive to meet such criteria in all of my work. That includes my site, which is 100% XHTML 1.0 compliant as determined by the World Wide Web Consortium. https://www.matthewstevenkel…
    I will show you how to create a ASP.NET Captcha control without using any HTTP HANDELRS or what so ever. you can easily plug it into your web pages. For Example a = 2 + 3 (where 2 and 3 are 2 random numbers) Session("Answer") = 5 then we…
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

    856 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

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now