SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    SitePoint Zealot
    Join Date
    May 2005
    Location
    London
    Posts
    96
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Trouble with CDO

    Hi all
    I'm struggling with this one: I'm trying to set up a page for people to give their name and email so they can be added to a mailing list. Here's the code I'm using:


    <%
    if Request("Action")="SendEmail" then
    sFrom = Trim(Request.Form("txtName"))
    sEmail = Trim(Request.Form("txtEmail"))
    If sFrom = "" Or sEmail = "" then
    %>
    <script language="JavaScript" type="text/javascript">
    <!--
    window.alert("Your name and email address must both be supplied.");
    //-->
    </script>

    <%
    Else
    message = ""
    End If

    Set objMessage = CreateObject("CDO.Message")
    Set objConf = Server.CreateObject("CDO.Configuration")
    Set objFields = objConf.Fields
    With objFields
    .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
    .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "127.0.0.1"
    .Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 10
    .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
    .Update
    End With
    objMessage.To = "paul@thehill.org.uk"
    objMessage.From = sEmail
    objMessage.Subject = "Morphosen mailing list"
    objMessage.TextBody = "Please add me to Morphosen's mailing list. Thanks. " & sFrom & "."
    objMessage.Send

    Select Case Err.Number
    Case 0
    message = " Thank you (" + sFrom + "). We'll add you to our mailing list "
    Case 8004020d
    message = "No fields! " & Err.Description
    Case Else
    message = "Oops! " & Err.Description
    End Select
    %>
    <script language="JavaScript" type="text/javascript">
    <!--
    window.alert(message);
    window.history.go(-1);
    //-->
    </script>

    <%
    Set objFields = Nothing
    Set objConf = Nothing
    Set objMessage = Nothing
    End If
    %>

    The message telling you you haven't filled in the form comes up fine, but provided the information's there, I would expect a message to be sent and the message lower down to be displayed. Neither happens.

    If anyone can see what's wrong, I'd be really grateful.

    The page concerned is: Morphosen: contact.

    Many thanks.

    Paul
    Soft and Sound

  2. #2
    SitePoint Enthusiast
    Join Date
    Aug 2011
    Location
    OH, USA
    Posts
    72
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Please tell me what exact message you have and what part does not work.
    Did you recieved email?

  3. #3
    SitePoint Zealot
    Join Date
    May 2005
    Location
    London
    Posts
    96
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for replying.

    Nothing appears to be sent. I would expect the second Javascript message to display either with the 'Thank you' message or the 'Oops' one, but neither are displayed. I get no error either, so I don't know what, if anything, happened.

    Hope that helps.

    Paul
    Soft and Sound

  4. #4
    SitePoint Enthusiast
    Join Date
    Aug 2011
    Location
    OH, USA
    Posts
    72
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try tunt off buffering it is on by default

    insert very firs line in you script

    Code:
    response.buffer=false

  5. #5
    SitePoint Zealot
    Join Date
    May 2005
    Location
    London
    Posts
    96
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm afraid it didn't work. I got this message:

    Buffering cannot be turned off once it is already turned on.

    When I took it out and tried again, I got:

    The "SendUsing" configuration value is invalid.

    Oh dear!
    Soft and Sound

  6. #6
    SitePoint Enthusiast
    Join Date
    Aug 2011
    Location
    OH, USA
    Posts
    72
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Did you check values inside your code like sEmail and sFrom?

    you can insert inside your code in any place when you need to check values

    Code:
    response.write "sEmail=" & sEmail
    response.flush
    response.end
    That will print on your screen sEmail value and stop executing code.
    So. You need to check all values by placing that code in different parts of your script and will found where is the problem

  7. #7
    SitePoint Zealot
    Join Date
    May 2005
    Location
    London
    Posts
    96
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks. I'll give that a go.

    Paul
    Soft and Sound

  8. #8
    SitePoint Zealot
    Join Date
    May 2005
    Location
    London
    Posts
    96
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Right. I've tried that message at various points in the script, and commented out the objMessage.Send. This enabled me to work out why the Javascript was not being displayed (it was the way I was referencing the vbScript variable 'messgae'.

    However, that's a red herring. Once I bring back the Send instruction, I get 'The "SendUsing" configuration value is invalid'. This appears to be related to the outgoing server, but I've tried 127.0.0.1, localhost and an SMTP server I know I can use, and nothing has any effect.

    All very confusing. I thought CDO was supposed to be straightforward!

    Thanks again.

    Paul
    Soft and Sound

  9. #9
    SitePoint Addict
    Join Date
    Apr 2009
    Posts
    359
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Doug G
    =====
    "If you ain't the lead dog, the view is always the same - Anon

  10. #10
    SitePoint Zealot
    Join Date
    May 2005
    Location
    London
    Posts
    96
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    All is well, now, thanks. It turned out I'd managed to lose one very important line of code (the second line in this section):

    With objMessage
    Set .Configuration = objConf
    .To = "info@morphosen.com"
    .From = sEmail
    .Subject = "Morphosen mailing list"
    .TextBody = "Please add me to Morphosen's mailing list. Thanks. " & sFrom & "."
    .Send
    End With

    Thanks for the replies.
    Soft and Sound

  11. #11
    SitePoint Addict itHighway's Avatar
    Join Date
    Jan 2008
    Location
    GUJ
    Posts
    270
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Resolve the issue in steps

    1- Check if you email script is working fine and sends email back to you.
    2- Put a response.write to see which part of if-than-else is being executed.

    Important: You can not print ASP "message" variable in Javascript alert box. Instead use response.write


Tags for this Thread

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
  •