Realization of mailing list function under ASP environment

Source: Internet
Author: User
Tags insert email account
Mailing list

The functionality provided to end users is primarily provided by an HTML file and two ASP files that accept the user's subscription request and exit the mailing list application.

The user's personal information is entered in the registration form shown in Figure 1, and its implementation file is homepage.htm. When the user submits the form, the system validates the user's input data and then saves it to the database and prompts for the registration success message. This feature can be found in the signbook.asp file, and the following code is used to save user input data to the database:

' Save it to the database if the user enters data validation through
If blnvalid = True Then
' Insert a new record in the database
Strsql_insert = "Insert into Guests (Guest_name, Guest_email," & _
"Mail_list, Guest_comment)" & _
"VALUES (' & StrName &" ', ' "& Stremail & _
"', '" & Blnmaillist & "', '" & strcomments & "];
Set oconn=server.createobject ("ADODB. Connection ")
oConn.Open Strdsnpath
On Error Resume Next
Oconn.execute Strsql_insert
Oconn.close
Set oconn = Nothing
' Log whether the insert was successful
If Err.Number < > 0 Then
' There was an error
Strvalid = ... Database operation error message, slightly ...
Else
' Record insert succeeded
Strvalid = ... Sign up for success message, slightly ...
End If ' Err.Number < > 0
Else ' user input data error
Strvalid = ... User input data error prompt, slightly ...
End If ' blnvalid = True

The code implements the first feature for end users: Registering personal information into the register and adding users to the mailing list.

Each user who receives a message from a mailing list can find a link (class such as http://www.mycompany.com/unsubscribe.asp) at the end of the message, as well as a user ID and email account prompt. Click this link to access the Unsubscribe unsubscribe.asp page, as shown in Figure 2. When the user provides the correct email address and ID number, the script in unsubscribe.asp modifies the mail_list tag of the user registration record so that the system no longer sends mail to the user. The following is the implementation code for this section of functionality:

"Figure 2 Aspmailinglist_2.gif"

<%
If Request.ServerVariables ("request_method") = "POST" then
Iguestid = Request.Form ("Txti D ")
Sguestemail = Request.Form (" Txtemail ")
If Iguestid < >" "and Sguestemail < >" "then
' in database Update user record
Strsql_unsubs = "Update Guests SET guests.mail_list=" & 0 & _
"WHERE guests.guest_id=" & IG Uestid & _
"and Guests.guest_email= '" & Sguestemail & "';"
Set oconn = Server.CreateObject ("ADODB. Connection ")
oConn.Open strdsnpath
Oconn.execute strsql_unsubs, iupdates
On Error Resume Next
oconn.cl OSE
Set oconn = Nothing
If Err.Number < > 0 then
serror = ... SQL statement execution failure prompt message, slightly ...
Else
If iupdates < > 0 then
serror = ... Unsubscribe success message, slightly ...
Else
Serror = ... Could not find the database record prompt information, slightly ...
End If ' Iupdates < > 0
End If ' Err.Number < > 0
Else
Response.Redirect ("homepage.htm") End If ' Iguestid < > '
End If 'Request_method = "POST"
%>

The iupdates variable provided when executing the SQL command reflects the number of records affected by the SQL statement. If the value is 0, you can assume that the user did not enter the ID or email address correctly. The code above implements a user-oriented second function, and the next thing we want to accomplish is the management of the registry.







Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.