不幸的是,我被迫使用ASP来完成这项特殊任务。我需要我的表单将其数据发布到CSV,然后发送通知客户端的电子邮件。现在我已经开始工作的第一位(将数据发布到CSV文件),但它的电子邮件通知正在向我发送,因为我不知道如何或将什么内容合并到我当前的代码中以便实现此目的。
以下是相关表单的链接: http://dev.brandspank.co.za/form/index.html
以下是我的ASP代码:
<% option explicit
dim objFSO, objTXT, lines, newRecord, filePath, fieldNames, x, fullText, nLine %>
<h1>Form inputs posted:</h1>
<%
for each x in request.form
response.write x & ": " & Replace(request.form(x), ",","-") & "<br />" & vbNewLine
next
'set filepath for plain text db. This neds to be the absolute path of file
filePath = "\form\myCSVdb.csv"
set objFSO = server.createobject("Scripting.FileSystemObject")
if (objFSO.fileExists(filePath))=true then
set objTXT = objFSO.openTextFile(filePath, 1) 'opens a text file for
' reading, true means it will create the file if not already there
fullText = trim(objTXT.readall)
lines = split(fullText, vbNewLine) 'lines is now an array, each item is
' one line of the db file.this could now be used to list the entire db
' table, notice next 3 commented out lines
' for each x in lines
' response.write lines(x)
' next
objTXT.close
set objTXT = nothing
if trim(lines(0)) = "" then fullText = ""
else
fullText = ""
end if %>
<h1>added to the db:</h1>
<%
if fullText <> "" then 'there are already field names in the db,
' so put the new line in the same order
set objTXT = objFSO.openTextFile(filePath, 8, True) 'opens the text file for
' appending
response.write "(fields in the database: " & lines(0) & ")<br />" & vbNewLine
'split the first line, which had field names into an array -fieldNames-
fieldNames = split(lines(0), ",")
response.write "field values entered:<br />" & vbNewLine
for each x in fieldNames
if x <> "" then
nLine = nLine & Replace(request.form(x), ",","-") & ","
'adds each form input to a string
response.write x & ": " & Replace(request.form(x), ",","-") & "<br />" & vbNewLine
end if
next
nLine = left(nLine, len(nLine)-1)
'removes trailing comma
objTXT.writeLine nLine
else 'there isn't anything in the textfile yet, so put in the field names first
set objTXT = objFSO.openTextFile(filePath, 2, True) 'opens the text file for
' writing
response.write "field names enterd:<br />" & vbNewLine
for each x in request.form
if Replace(lcase(x), ","," ") <> "submit" then 'or you will have a "submit" field in your db
'of course, if your submit button is named something else, that should
'be the name xcluded here
nLine = nLine & x & ","
'adds each form input name to a string which will become th first line of
'the db, the line which shows field names
response.write x & "<br />" & vbNewLine
end if
next
nLine = left(nLine, len(nLine)-1)
'remove trailing comma
objTXT.write nLine
objTXT.write vbNewLine
nLine = ""
response.write "field values entered:<br />" & vbNewLine
for each x in request.form
if lcase(x) <> "submit" then
nLine = nLine & Replace(request.form(x), ",","-") & ","
'adds each form input to a string
response.write Replace(request.form(x), ",","-") & "<br />" & vbNewLine
end if
next
nLine = left(nLine, len(nLine)-1)
'remove trailing comma
objTXT.write nLine
objTXT.write vbNewLine
end if
objTXT.close
%>
<% response.redirect "thankyou.html" %>
非常感谢任何帮助!
答案 0 :(得分:0)
抱歉,我还没有评论权限,所以这将是一个伪装成答案的评论:细节将取决于您的网络服务器如何配置电子邮件,但假设它有点当前,你可能会使用CDOSYS这样做,这里有一个非常基本的介绍的链接:http://www.w3schools.com/asp/asp_send_email.asp
您已经导航了FileSystemObject,因此一旦您在邮件服务器上获得详细信息,您就可能会发现这一点非常简单。
答案 1 :(得分:0)
我把你需要的一切都放在这里: www.oceanmedia.net/files/2014-06-form-process.zip 包括:
- form_process。 ASP
- i_fn_email_cdo.asp
- i_check_security.asp
- i_odbc.asp
- i_fn_clean.asp
- i_fn_dirty.asp
哦,文本文件部分:
<%
Dim fso, f
Set fso = CreateObject("Scripting.FileSystemObject")
'Open the file for reading
Set f = fso.CreateTextFile(s_path & "/" & s_file_being_created, True)
f.Write(m)
f.Close
Set f = Nothing
Set fso = Nothing
%>