Form Mailto Email Response Formatter

On my site, am using a Form (with mailto me). When I get the emails, the text is unformatted with &'s where returns should be and +'s between words. Comes to me as as an email attachment "postdata.att".  Any code out there that formats Form mailto responses?  Really only need format, save as, and print... but extras are good!!  Thanks Folks.

Jay
jkeehnAsked:
Who is Participating?
 
mcriderConnect With a Mentor Commented:
The text you are getting is in URL format...

Add the following code to a MODULE in your program then you can use the following function:

   Dim MyString As String
   MyString = URLdecode(EncodedString)

Cheers!



THE CODE:

    Function ReplaceInString(Source As String, TheString As String, TheReplaceString As String) As String
        Dim iVal As Integer
        Dim Workspace As String
        Workspace = Source
        iVal = 1
        Do
            iVal = InStr(iVal, Workspace, TheString, 1)
            If iVal = 0 Then Exit Do
            Workspace = Left$(Workspace, iVal - 1) + TheReplaceString + Mid$(Workspace, iVal + Len(TheString))
            iVal = iVal + 1
        Loop
        ReplaceInString = Workspace
    End Function
    Function URLdecode(Source As String) As String
        Dim lBuf As String
        Dim iVal As Long
        lBuf = ReplaceInString(Source, "+", " ")
        iVal = 1
        Do
            iVal = InStr(iVal, lBuf, "%")
            If iVal = 0 Then Exit Do
            lBuf = Left$(lBuf, iVal - 1) _
                + Chr$(CLng("&H" + Mid$(lBuf, iVal + 1, 2))) _
                + Mid$(lBuf, iVal + 3)
            iVal = iVal + 1
        Loop
        URLdecode = lBuf
    End Function
    Function URLencode(Source As String) As String
        Dim iVal As Long
        Dim lBuf As String
        Dim lArray As Variant
        lBuf = Source
        For Each lArray In Array("%", "&", "+", "~", "`", "!", "@", "#", "$", "^", "*" _
            , "(", ")", "-", "_", "=", "{", "[", "}", "]", "|", "\", ":", ";", "'", "<" _
            , ">", "?", ",", ".", "/", Chr$(34))
            lBuf = ReplaceInString(lBuf, CStr(lArray), "%" + Right$("0" + Hex(Asc(lArray)), 2))
        Next
        lBuf = ReplaceInString(lBuf, " ", "+")
        iVal = 0
        Do
            iVal = iVal + 1
            If iVal > Len(lBuf) Then Exit Do
            lArray = Mid$(lBuf, iVal, 1)
            If Asc(lArray) <= 31 Or Asc(lArray) >= 127 Then
                lBuf = ReplaceInString(lBuf, CStr(lArray), "%" + Right$("0" + Hex(Asc(lArray)), 2))
            End If
        Loop
        URLencode = lBuf
    End Function

0
All Courses

From novice to tech pro — start learning today.