Cannot send email from a form using ASP script and CDOSYS

Discussion in 'ASP.NET / ASP.NET Core' started by BobbyT, Jan 14, 2008.

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.
  1. Hi there, I am fairly new to web design and cannot figure out how to send emails using a simple asp script that is being called from an html page. Here is the code for the web page and the ASP script. When I hit the submit button, I am directed to an error page saying the page cannot be displayed. Could someone either try to assist me in getting this script working, or simply provide3 a script that will work. I GREATLY appreciate any help.

    Here is the HTML page script:

    <form method="post" action="cdosys.asp">
    Email address: <input type="text" name="email_address" />
    Question 1: <input type="text" name="question_1" />
    Question 2: <input type="text" name="question_2" />
    Question 3: <input type="text" name="question_3" />
    <input name="email_subject" type="hidden" value="Subject of email" />
    <input name="redirect_to" type="hidden" value="http://www.seymoredoolittle.com" />
    <input type="reset" name="Reset" value="Reset" />
    <input name="send" type="submit" value="Submit" />
    </form>

    Here is my ASP script:

    <%
    For Field = 1 to Request.Form.Count - 3
    FieldName = Replace(Request.Form.Key(Field),"_"," ")
    FieldValue = Request.Form.Item(Field)
    Body = Body &amp; FieldName &amp; ": " &amp; FieldValue &amp; VbCrLf
    Next
    'Dimension variables
    Dim objCDOSYSCon
    'Create the e-mail server object
    Set objCDOSYSMail = Server.CreateObject("CDO.Message")
    Set objCDOSYSCon = Server.CreateObject ("CDO.Configuration")
    'Set and update fields properties
    With objCDOSYSCon
    'Outgoing SMTP server
    .Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "SMTPSERVER"
    .Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
    'CDO Port
    .Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
    'Timeout
    .Fields("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
    .Fields.Update
    End With
    'Update the CDOSYS Configuration
    Set objCDOSYSMail.Configuration = objCDOSYSCon
    'Set and update email properties
    With objCDOSYSMail
    '0=Low, 1=Normal, 2=High
    .Fields("urn:schemas:httpmail:importance").Value = 1
    'Who the e-mail is from
    .From = Request.Form("email_address")
    'Who the e-mail is sent to
    .To = "[email protected]"
    'Who the e-mail is CC'd to
    .Cc = ""
    'The subject of the e-mail
    .Subject = Request.Form("email_subject")
    'Set the e-mail body format (HTMLBody=HTML TextBody=Plain)
    .TextBody = Body
    .Fields.Update
    'Send the e-mail
    .Send
    End With
    'Close the server mail object
    Set objCDOSYSMail = Nothing
    Set objCDOSYSCon = Nothing
    'Rederect after sending email
    Response.Redirect Request.Form("redirect_to")
    %>
     
Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.

Share This Page