SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    Visible Ninja bronze trophy
    JeffWalden's Avatar
    Join Date
    Sep 2002
    Location
    Los Angeles
    Posts
    1,709
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)

    Cool Script to Email Form Contents

    Let me start out by saying that I'm not an ASP guy... I'd like to be - but haven't really had the time lately. I do however have a very small ASP problem that I can't understand.

    The script posted below is part of one of my clients websites that I'm going to be re-designing. For the time being, they have mentioned that they are not getting emails from their website contact form. This script (I believe) is what actually sends the email and then redirects the user to a landing page.

    The problem is that I can't figure a bit of this out! I'd like to put my email address in as the recipient so I can test the system. It looks like the recipent email is simply a variable in here being called from somplace else... where is it?

    This is probably pretty simple - but I can't seem to wrap my head around it.

    Thanks!

    <%
    Dim landing_page, host_url
    Dim fso, outfile, filename, dirname, myFolder
    Dim req_method, key, value
    Dim bErr, errStr, bEmpty
    On Error resume next
    bErr = false
    bEmpty = true
    errStr = ""
    Set fso = Server.CreateObject("Scripting.FileSystemObject")
    host_url = Request.ServerVariables("HTTP_HOST")
    req_method = Request.ServerVariables("REQUEST_METHOD")
    dtNow = Now()
    filename = Server.MapPath("ssfm")
    dirname = filename
    filename = filename & "/gdform_" & DatePart("M", dtNow) & DatePart("D", dtNow) & DatePart("YYYY", dtNow) & DatePart("N", dtNow) & DatePart("S", dtNow)
    Function FormatVariableLine(byval var_name, byVal var_value)
    Dim tmpStr
    tmpStr = tmpStr & "<GDFORM_VARIABLE NAME=" & var_name & " START>" & vbCRLF
    tmpStr = tmpStr & var_value & vbCRLF
    tmpStr = tmpStr & "<GDFORM_VARIABLE NAME=" & var_name & " END>"
    FormatVariableLine = tmpStr
    end function
    Sub OutputLine(byVal line)
    outfile.WriteLine(line)
    end sub
    if err.number = 0 then
    Set outfile = fso.CreateTextFile(filename, true, false)
    if err.number <> 0 then
    bErr = true
    errStr = "Error creating file! Directory may not be writable or may not exist.<br>Unable to process request."
    else
    if(req_method = "GET") then
    for each Item in request.QueryString
    if item <> "" then
    bEmpty = false
    key = item
    value = Request.QueryString(item)
    if(lcase(key) = "redirect") then
    landing_page = value
    else
    line = FormatVariableLine(key, value)
    Call OutputLine(line)
    end if
    end if
    next
    elseif (req_method = "POST") then
    for each Item in request.form
    if item <> "" then
    bEmpty = false
    key = item
    value = Request.form(item)
    if(lcase(key) = "redirect") then
    landing_page = value
    else
    line = FormatVariableLine(key, value)
    Call OutputLine(line)
    end if
    end if
    next
    end if
    outfile.close
    end if
    if(bEmpty = true) AND errStr = "" then
    bErr = true
    errStr = errStr & "<br>No variables sent to form! Unable to process request."
    end if
    if(bErr = false) then
    if (landing_page <> "") then
    response.Redirect "http://" & host_url & "/" & landing_page
    else
    response.Redirect "http://" & host_url
    end if
    else
    Response.Write errStr
    end if
    set fso = nothing
    else
    Response.Write " An Error Occurred creating mail message. Unable to process form request at this time."
    end if
    %>
    TAKE A WALK OUTSIDE YOUR MIND.

  2. #2
    SitePoint Wizard bronze trophy Tyssen's Avatar
    Join Date
    Oct 2005
    Location
    Brisbane, QLD
    Posts
    4,067
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You don't seem to have any ASP mailing object like JMail, CDONTS, ASPMail etc in that script.

  3. #3
    SitePoint Member
    Join Date
    Oct 2006
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It looks like you're using the old school pre-CDONTS mailroot (SMTP) send mail. I would suggest that you use CDONTS or CDO to send it out. The code you're using is a bit outdated.

    I'm sure you can find a bunch of scripts out there that are put together better than what I'm posting below, but I'll add it just to get you started. This example uses CDO.

    Public Function SendEmail(ByVal v_strTo, ByVal v_strFrom, ByVal v_strSubject, ByVal v_strMessage)
    Dim blnValue: blnValue = True
    Dim objMail

    If IsBlank(v_strTo) Then
    blnValue = False
    Else
    On Error Resume Next
    Set objMail = CreateObject("CDO.Message")
    objMail.To = v_strTo
    objMail.From = v_strFrom
    objMail.Subject = v_strSubject
    objMail.TextBody = v_strMessage
    objMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing")=2
    'Name or IP of remote SMTP server
    objMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") ="mail.hybrid-interactive.com"
    'Server port
    objMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
    objMail.Configuration.Fields.Update
    objMail.Send
    Set objMail = Nothing
    If Err.number <> 0 Then
    blnValue = False
    End If
    On Error Goto 0
    End If
    SendEmail = blnValue
    End Function

  4. #4
    Visible Ninja bronze trophy
    JeffWalden's Avatar
    Join Date
    Sep 2002
    Location
    Los Angeles
    Posts
    1,709
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    This is why I do PHP... so much easier!

    PHP Code:
    mail($email_address$subject$message$headers); 
    Thanks for your help though! I will google for an ASP sendmail script. I'm sure I can find something to band-aid the situation with.
    TAKE A WALK OUTSIDE YOUR MIND.


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
  •