Realization of mailing list function in ASP environment (II.) (recommended)

Source: Internet
Author: User
Tags insert email account
The functionality provided by the mailing list 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:

"Figure 1 Aspmailinglist_1.gif"



' 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 ("txtID")
Sguestemail = Request.Form ("Txtemail")
If Iguestid < > "" and Sguestemail < > "" Then
' Update the user record in the database
Strsql_unsubs = "UPDATE Guests SET guests.mail_list=" & 0 & _
"WHERE guests.guest_id=" & Iguestid & _
"and Guests.guest_email= '" & Sguestemail & "';"
Set oconn = Server.CreateObject ("ADODB. Connection ")
oConn.Open Strdsnpath
Oconn.execute Strsql_unsubs, Iupdates
On Error Resume Next
Oconn.close
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
&nb



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.