View Single Post
Old 02-08-2013, 07:41 PM   PM User | #4
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,172
Thanks: 59
Thanked 3,995 Times in 3,964 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Using the CSV file is by far the easiest.

Just before the Response.Redirect line at the end, add this code:
Code:
CONST QT = """" ' creates a single quote mark

' put the items into the array in whatever order you prefer:
csvItems = Array( UserIPAddress, strFeedTitle, strFeedName, strFeedEmail, _
                strFeedCell, strFeedCompany, strFeedSubject, strFeedMessage )

Set FSO = Server.CreateObject("Scripting.FileSystemObject")
Set csv = FSO.OpenTextFile( Server.MapPath("emailLog.csv"), 8, True )
csv.WriteLine QT & Join( csvItems, QT & "," & QT ) & QT
csv.Close
Set FSO = Nothing

response.redirect("../thankyou.html")

%>
The only thing to watch out for is here:
Code:
         Server.MapPath("emailLog.csv")
Aside from the fact that you can use any file name of your choice, though it should end in ".csv", that code as written probably won't work. That says "find the CSV text file in the same directory as this code." Almost surely the directory with the code will *NOT* be writable.

Typically, you will have a writable "data" directory that is either a subdirectory of the code directory or is "besided" the code subdirectory. So you will likely need something such as
Code:
    Server.MapPath("data/emailLog.csv")
or
    Server.MapPath("/data/emailLog.csv")
or 
    Server.MapPath("../data/emailLog.csv")
You will have to figure that part out based on the directory structure on your machine.

This code should write out a CSV file that looks like
Code:
"68.128.3.7","Amalgamated Widgets","Today's Widget Report","...", etc.
TWO CAUTIONS: In a ".csv" file like this, *NONE* of the field may contain *EITHER* quote marks or new line characters.

If you are unsure if they might, you could use a "cleaner" function something like:
Code:
Function clean( txt )
    clean = Replace( Replace( Replace( txt, """","'" ), vbCR, " ", vbLF, " " )
End Function
And then construct the array using that function:
Code:
csvItems = Array( UserIPAddress, clean(strFeedTitle), clean(strFeedName), _
                clean(strFeedEmail), clean(strFeedCell), clean(strFeedCompany), _
                clean(strFeedSubject), clean(strFeedMessage) )
Give it a shot!
__________________
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.
Old Pedant is offline   Reply With Quote