打印本文 打印本文  关闭窗口 关闭窗口
使用ASPMail组件发送数字卡片
作者:采集员 文章来源:来源于网络 点击数: 更新时间:2005/9/10 13:49:32
 %>
              <br><br><br>
              <a href="makin.htm" target="_self" >
                 <img border="0" height="72" src="images/replybotton.gif"
                       width="176">
              </a>
           <%
            end if

' This else will only be reached if there is no card
' (i.e. the password was incorrect)  We need to show
' an error message.
else
%>  

<br><br>
<center>
  <img src="images/error.gif" width="322" height="53"
     border="0">
</center>
<br>

<%
end if    


' This is where i remove all the postcards  
' in the DB with more than 30 days old.

' I do not want to make a huge DB, so I clean  
' it just to have the messages of the last 30 days.

' You can now ask.. "-So, why did you put this code here?"
' My response is:
' "- Because this is the place where you fill the DB,
' so if you are going to put another record
' at the DB, lets clean some old stuff."

' That being said, let's clean the db!  :)

' Here we will get the system date (yes, the server date)
d = now()  

' We will decrease 30 days at the date we have
d = DateAdd("d",-30,d)

Set Conn = Server.CreateObject("ADODB.Connection")  
conn.open "DSN=postal;"

Set rs = Server.CreateObject("ADODB.Recordset")  

' Run a SQL query that will remove all out of date records
SQLStmt = "DELETE FROM postal WHERE data < #" & d & "#" '

'Run the query
rs.Open SQLstmt,Conn,1,2  
%>

</body>    
</html>


FILE: enviado.asp
At this time, we will validate all the information that it is supposed to sent as well as the data that we
will put in the DB. If everything is well we will send the information to the receiver by e-mail. I will
explain later how to get the free e-mail component, how to register it at the server, and how to use it.

<%

' This is the variable that I use to the ID  
' of the post card
Dim identifier

' goby is anotther  boolean to  
' see if there is an error in the data
Dim goby

goby = 1    'lets start it with True

%>

<html>
<body
     marginheight="0"
     marginwidth="0"
     topmargin="0"
     leftmargin="0"
     background="images/something.gif"
      bgcolor="#002400"
     text="#FCC403"
>

<font face=3D"Arial">
<small><strong>

<%
' Let's validate the name; the length of the
' name must be at least 2 characters long
if len(session("nameto")) < 2 then  
     ' So if there is any problem there will be an error  
     goby = 0  
end if


if len(session("namefrom")) < 2 then
     goby = 0
end if


' Validate the e-mail, I have written
' an arthicle about this, take a look at it
If Len(session("emailfrom")) <= 5 Then  
     goby = 0
Else
     If InStr(1, session("emailfrom"), "@", 1) < 2 Then
         goby = 0
     Else
         If InStr(1,session("emailfrom"), ".", 1) < 4 Then
            goby = 0
         End If
     End If
End If

If Len(session("emailto")) <= 5 Then
     goby = 0  
Else
     If InStr(1, session("emailto"), "@", 1) < 2 Then
         goby = 0
     Else
         If InStr(1,session("emailto"), ".", 1) < 4 Then
             goby = 0
         End If
     End If
End If


' Make sure the message is less than 500 characters.
If len(session("message")) >= 500 Then  
     goby = 0
End If


' If there are errors, then let the user know
' And make him/her correct the data
if goby = 0 then %>

   <br><br><br><br><br>
   <center>
      <img src="images/error.gif" width="322"  
           height="53" border="0">
   </center>
   <br>
<%
end if


' There are no errors.  Put the data in the DB
' and send the link to the receiver via email.
If goby = 1 then  
    Set Conn = Server.CreateObject("ADODB.Connection")
    conn.open"DSN=postal;"

    Set rs = Server.CreateObject("ADODB.Recordset")


    'We need to insert a record into the database
    SQLStmt = "INSERT INTO Postcard (" & _
              "passw, postal, nameto, namefrom, " & _
              "emailfrom, emailto, message, data) " & _
           "VALUES ("

     ' We need a random number for our password, so
     ' use randomize/rnd to make a random number.
     randomize()
     passw = Int((9999-1)*Rnd + 1)

     SQLStmt = SQLStmt & passw & ",'" & session("postal") & _
               "','" & session("nameto") & "','" & _
               session("namefrom") & "','" & _
               session("emailfrom") & "','" & _
               session("emailto") & "','" & _
               session("message") & "','" & session("data") & "')"

     ' Write information to database
     rs.Open SQLStmt, Conn


     ' Now you will see how to use the Free Persits
     ' E-Mail component

     ' First, Create the Mail object
     Set Mail = Server.CreateObject("Persits.MailSender")  

     ' Put the mail server you are using
     Mail.Host = "mail.mailserver.com"

     ' Send the information of the
     ' person that is sending the e-mail
     Mail.From = session("emailfrom")

     ' Who you're sending the email to.
     Mail.FromName = session("namefrom")

     ' Put the email to send to, as well as the name of the person  
     Mail.AddAddress session("emailto"), session("nameto")  

     ' Subject of the email
     Mail.Subject = "Digital PostCard to " & session("

上一页  [1] [2] [3] [4]  下一页



打印本文 打印本文  关闭窗口 关闭窗口