Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Sep 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Email with ASP and HTML form

    I'm trying to figure out what I'm doing wronig in getting the form fields to be sent via email.

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,103
    Thanks
    80
    Thanked 4,554 Times in 4,518 Posts
    No code, no help. This is especially true of sending email from ASP, as there are at least 5 major ways to do so, and I have no clue which one you are using, so I'm not going to try to give 5 answers. Show your code, please.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    New to the CF scene
    Join Date
    Sep 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    This is a dumbed down version of what I use....

    sendmail.asp


    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <html>
    <head>
    <title>Contact</title>

    <%
    'If the form has not been submitted execute the following code
    If Request.Form="" Then %>
    <form name="form1" method="post" action="sendmail.asp">
    <br><br>
    <div align="center">
    <table width="75%" border="0" cellpadding="0" cellspacing="0">
    <tr bgcolor="#603318">
    <td bgcolor="#BB642F"><b>e-mail address</b></td>
    <td bgcolor="#BB642F">
    <input type="text" name="txtName">
    </td>
    </tr>
    <tr bgcolor="#603318">
    <td bgcolor="#9B5226"><b>subject</b></td>
    <td bgcolor="#9B5226">
    <input type="text" name="txtEmail">
    </td>
    </tr>
    <tr bgcolor="#603318">
    <td bgcolor="#BB642F"><b>comment</b></td>
    <td bgcolor="#BB642F">
    <textarea name="txtFeedback" cols="40" rows="7"></textarea>
    </td>
    </tr>
    <tr bgcolor="#603318">
    <td bgcolor="#9B5226">
    <input type="submit" name="Submit" value="Submit">
    </td>
    </tr>
    </table>
    </div>
    </form>

    <%
    'If the form has been submitted execute the following code
    Else

    'receive the form values
    Dim sName, sEmail, sFeedback
    sName=Request.Form("txtName")
    sEmail=Request.Form("txtEmail")
    sFeedback=Request.Form("txtFeedback")

    if sname = "" then
    response.write "<br><br><center><h4>You didn't enter your e-mail address."
    response.end
    end if

    if InStr(sname, "@") = 0 or InStr(sname, ".") = 0 then
    response.write "<br><br><center><h4>Impropertly formatted email address"
    response.end
    end if

    if semail = "" then
    response.write "<br><br><center><h4>You didn't enter a subject."
    response.end
    end if

    if sfeedback = "" then
    response.write "<br><br><center><h4>You did not enter any message."
    response.end
    end if


    ' create the HTML formatted email text
    Dim sEmailText
    sEmailText = sEmailText & "<html>"
    sEmailText = sEmailText & "<head>"
    sEmailText = sEmailText & "<title>HTML Email</title>"
    sEmailText = sEmailText & "</head>"
    sEmailText = sEmailText & "<body>"
    sEmailText = sEmailText & "Subject: " & semail & "<br>"
    sEmailText = sEmailText & "Message from: " & sName & "<br>"
    sEmailText = sEmailText & "Message:" & sFeedback & "<br>"
    sEmailText = sEmailText & "Date & Time:" & Now() & "<br>"
    sEmailText = sEmailText & "IP :" & Request.ServerVariables("REMOTE_ADDR")
    sEmailText = sEmailText & "</body>"
    sEmailText = sEmailText & "</html>"

    'create the mail object
    Set ObjSendMail = CreateObject( "CDO.Message" )

    ObjSendMail.Configuration.Fields.Item ( "http://schemas.microsoft.com/cdo/configuration/sendusing" ) = 2 'Send the message using the network (SMTP over the network).
    ObjSendMail.Configuration.Fields.Item ( "http://schemas.microsoft.com/cdo/configuration/smtpserver" ) = "mail.reliablesite.net"
    ObjSendMail.Configuration.Fields.Item ( "http://schemas.microsoft.com/cdo/configuration/smtpserverport" ) = 25
    ObjSendMail.Configuration.Fields.Item ( "http://schemas.microsoft.com/cdo/configuration/smtpusessl" ) = False
    ObjSendMail.Configuration.Fields.Item ( "http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout" ) = 60

    ObjSendMail.Configuration.Fields.Item ( "http://schemas.microsoft.com/cdo/configuration/smtpauthenticate" ) = 1 'basic (clear-text) authentication
    ObjSendMail.Configuration.Fields.Item ( "http://schemas.microsoft.com/cdo/configuration/sendusername" ) ="noreply@ontarioabandonedplaces.com"
    ObjSendMail.Configuration.Fields.Item ( "http://schemas.microsoft.com/cdo/configuration/sendpassword" ) = "password1"
    ObjSendMail.Configuration.Fields.Update

    ObjSendMail.To = "YOUR_ADDRESS_HERE@hotmail.ca"
    ObjSendMail.Subject = semail
    ObjSendMail.From = "RETURNEMAIL@YOURADDRESS.com"

    ' we are sending a text email.. simply switch the comments around to send an html email instead

    ObjSendMail.HTMLBody = sEmailtext
    ObjSendMail.Send
    Set ObjSendMail = Nothing


    Response.write "<div align='center'><br><br><font size=3>Thank you for sending your feedback.<br>"

    <% End If %> </font>

    </html>

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,103
    Thanks
    80
    Thanked 4,554 Times in 4,518 Posts
    Looks okay to me.

    About the only thing I would change is this line:
    Code:
    If Request.Form="" Then
    I would, instead, specifically use the suibmit button:
    Code:
    If Trim( Request.Form("Submit") ) = "" Then
    But I doubt that really matters.

    ************

    To check that the HTML you are creating is correct, you should add in one DEBUG line:
    Code:
    ...
    sEmailText = sEmailText & "</html>"
    
    Response.Write "DEBUG sEmailText:<hr/>" & Replace(sEmailText,"<","&lt;") & "<hr/>"
    ...
    If that debug looks okay, then it must be a problem in the Configuration. And the only people who can help with that would be those at "mail.reliablesite.net", the email service you are trying to use.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #5
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,103
    Thanks
    80
    Thanked 4,554 Times in 4,518 Posts
    You know, there MIGHT be something wrong there, more I look at it.

    You never actually create the configuration *OBJECT*.

    I usually do the two steps separately, like this:
    Code:
    ' first create the configuration object:
    Set ObjConfig=CreateObject("CDO.Configuration")
    ObjConfig.Fields.Item ( "http://schemas.microsoft.com/cdo/configuration/sendusing" ) = 2 'Send the message using the network (SMTP over the network).
    ObjConfig.Fields.Item ( "http://schemas.microsoft.com/cdo/configuration/smtpserver" ) = "mail.reliablesite.net"
    ObjConfig.Fields.Item ( "http://schemas.microsoft.com/cdo/configuration/smtpserverport" ) = 25
    ObjConfig.Fields.Item ( "http://schemas.microsoft.com/cdo/configuration/smtpusessl" ) = False 
    ObjConfig.Fields.Item ( "http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout" ) = 60
    
    ObjConfig.Fields.Item ( "http://schemas.microsoft.com/cdo/configuration/smtpauthenticate" ) = 1 'basic (clear-text) authentication
    ObjConfig.Fields.Item ( "http://schemas.microsoft.com/cdo/configuration/sendusername" ) ="noreply@ontarioabandonedplaces.com"
    ObjConfig.Fields.Item ( "http://schemas.microsoft.com/cdo/configuration/sendpassword" ) = "password1"
    ObjConfig.Fields.Update
    
    
    ' then create the mail object 
    Set ObjSendMail = CreateObject( "CDO.Message" ) 
    ' and then set the configuration in the message object
    Set objSendMail.Configuration=objConfig
    
    ...
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

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