0

我有一个推荐表格,用户可以推荐朋友成为会员。表单操作必须指向一个 asp 文件。(我从 php 开始,让它在不同的服务器上工作,但它需要的服务器必须是 asp)。我已经搜索和搜索,但我遇到了一些问题。(我是一个asp新手)

  1. 表单必须向用户发送电子邮件。我在这里的一个 asp 文件中工作(email.asp):

    <%
    Dim senderName, senderEmail, senderMessage
    Dim name1, name2, name3, name4, name5, name6, name7, name8, name9, name10
    Dim email1, email2, email3, email4, email5, email6, email7, email8, email9, email10
    senderName = Request.Form("senderName")
    senderEmail = Request.Form("senderEmail")
    senderMessage = Request.Form("senderMessage")
    name1 = Request.Form("name1")
    name2 = Request.Form("name2")
    name3 = Request.Form("name3")
    name4 = Request.Form("name4")
    name5 = Request.Form("name5")
    name6 = Request.Form("name6")
    name7 = Request.Form("name7")
    name8 = Request.Form("name8")
    name9 = Request.Form("name9")
    name10 = Request.Form("name10")
    email1 = Request.Form("email1")
    email2 = Request.Form("email2")
    email3 = Request.Form("email3")
    email4 = Request.Form("email4")
    email5 = Request.Form("email5")
    email6 = Request.Form("email6")
    email7 = Request.Form("email7")
    email8 = Request.Form("email8")
    email9 = Request.Form("email9")
    email10 = Request.Form("email10")   
    
    'Sends an email
    Dim mail
    Set mail = Server.CreateObject("CDO.Message")
    'for testing i am only sending to the first email
    mail.To = email1
    mail.From = senderEmail
    mail.Subject = "Join Dallas Cowboys True Blue Fan Club with me!"
    mail.TextBody = "Join Dallas Cowboys True Blue Fan Club with me!"
    mail.Send()
    Response.Write("Mail Sent!")
    'Destroy the mail object!
    Set mail = nothing
    %>
    
  2. 最后,我有一个可以工作的 aspx 文件 ( append.aspx ),它将表单数据附加到 csv 文件中。我遇到的真正问题是将两个文件合并为一个工作文件。

    <%@ Import Namespace="System.IO" %>
    <script type="text/javascript">
    window.onload = window.close();
    </script>
    <script language="vb" runat="server">
    sub Page_Load(sender as Object, e as EventArgs)
    'Open a file for writing
    Dim FILENAME as String = Server.MapPath("Output.csv")
    
    Dim senderName, senderEmail, senderMessage
    Dim name1, name2, name3, name4, name5, name6, name7, name8, name9, name10
    Dim email1, email2, email3, email4, email5, email6, email7, email8, email9, email10
    senderName = Request.Form("senderName")
    senderEmail = Request.Form("senderEmail")
    senderMessage = Request.Form("senderMessage")
    name1 = Request.Form("name1")
    name2 = Request.Form("name2")
    name3 = Request.Form("name3")
    name4 = Request.Form("name4")
    name5 = Request.Form("name5")
    name6 = Request.Form("name6")
    name7 = Request.Form("name7")
    name8 = Request.Form("name8")
    name9 = Request.Form("name9")
    name10 = Request.Form("name10")
    email1 = Request.Form("email1")
    email2 = Request.Form("email2")
    email3 = Request.Form("email3")
    email4 = Request.Form("email4")
    email5 = Request.Form("email5")
    email6 = Request.Form("email6")
    email7 = Request.Form("email7")
    email8 = Request.Form("email8")
    email9 = Request.Form("email9")
    email10 = Request.Form("email10")   
    
    'Get a StreamWriter class that can be used to write to the file
    Dim objStreamWriter as StreamWriter
    objStreamWriter = File.AppEndText(FILENAME)
    
    'AppEnd the the End of the string, "A user viewed this demo at: "
    'followed by the current date and time
    objStreamWriter.WriteLine(sEnderName & "," & sEnderEmail & "," & name1 & "," & email1 & "," & senderMessage & "," & DateTime.Now.ToString())
    If name2 <> "" then
    objStreamWriter.WriteLine("," & "," & name2 & "," & email2)
    End If
    If name3 <> "" then
    objStreamWriter.WriteLine("," & "," & name3 & "," & email3)
    End If
    If name4 <> "" then
    objStreamWriter.WriteLine("," & "," & name4 & "," & email4)
    End If
    If name5 <> "" then
    objStreamWriter.WriteLine("," & "," & name5 & "," & email5)
    End If
    If name6 <> "" then
    objStreamWriter.WriteLine("," & "," & name6 & "," & email6)
    End If
    If name7 <> "" then
    objStreamWriter.WriteLine("," & "," & name7 & "," & email7)
    End If
    If name8 <> "" then
    objStreamWriter.WriteLine("," & "," & name8 & "," & email8)
    End If
    If name9 <> "" then
    objStreamWriter.WriteLine("," & "," & name9 & "," & email9)
    End If
    If name10 <> "" then
    objStreamWriter.WriteLine("," & "," & name10 & "," & email10)
    End If
    'Close the stream
    objStreamWriter.Close()
    End sub
    </script>
    
4

1 回答 1

1

您需要使用 System.Net.Mailmessage 和 SmtpClient。

http://msdn.microsoft.com/en-us/library/system.net.mail.mailmessage.aspx

于 2012-05-24T17:04:07.753 回答