ASP to send users a lot of mailboxes

Source: Internet
Author: User
Tags access database

<title> Collection Attribute Application </title>
<body>
<p> Select the item you want to work with, and the item you selected will be displayed when you submit the data.
<form method= "POST" action= "set.asp" >
<br>1, <input type= "checkbox" Name= "MyCheckBox" value= "1" >
<br>2, <input type= "checkbox" Name= "MyCheckBox" value= "2" >
<br>3, <input type= "checkbox" Name= "MyCheckBox" value= "3" >
<br>4, <input type= "checkbox" Name= "MyCheckBox" value= "4" >
<br>5, <input type= "checkbox" Name= "MyCheckBox" value= "5" >
<br>6, <input type= "checkbox" Name= "MyCheckBox" value= "6" >
<br><input type= "Submit" value= "submitted data" Name= "B1" >
</form>
</body>

When the client selects the item to display, the following ASP page (set.asp) gives the number of items selected by the client and their values.

<!--set.asp-->
<%@ LANGUAGE = VBScript%>
<body>
<%
Response.Write "<br> you have selected the &request (" MyCheckBox ") .count&" Item, "
Response.Write "<br> Your selected items are:" &request ("MyCheckBox")
%>
</body>

If the client selects the 第二、三、五 item and submits the data, you will see the following results:
You have selected 3 items altogether,
The items you have selected are: 2, 3, 5
It should be noted that the form of "2, 3, 5" is consistent with the form required by the SQL statement, and we can take advantage of this form of results directly or indirectly, such as "select * from ATable where afiled in (" & Request ("MyCheckBox ") &") "The actual
The SQL query statement is "SELECT * from ATable where afiled in (2, 3, 5)".

Second, the application of the set attribute of HTML

Here's a practical example of how to use the collection properties of HTML in an ASP page to bulk manipulate a database. Now we have an Access database email that records the customer's e-mail, one of which has a datasheet emaillist, including CustomerID, CustomerName, Customeremail Three fields, representing the customer number, customer name, Customer email. In the ASP page selectid.asp, we use the checkbox to list all the customer's customer names (each checkbox's value is the corresponding customer number), and let the user choose which customers to send e-mail. When the user selects the customer and submits the data, sendmail.asp retrieves the e-mail messages for these customers and sends them an email. For specific information, see the following ASP program code and comment information.
<!--selectid.asp: List the customer names of all customers-->

<title> all customer's customer name </title>
<body>
<p align=center><font style= "font-family: Song Body; font-size:9pt" >
Please select the e-mail message that you want to send the new year greeting to which customers
<form method= "POST" action= "sendmail.asp" >
<% ' Establish a connection with an Access database
Set dbconnection = Server.CreateObject ("ADODB. Connection ")
Dbconnection.open "Driver={microsoft Access Driver (*.mdb)};" &_
"Dbq=c:/inetpub/wwwroot/test/email.mdb"
' Get customer number, customer name of all customers
Set rscustomers = Server.CreateObject ("ADODB. RecordSet ")
rsCustomers.Open "Select Customerid,customername,customeremail from Emaillist", _
dbconnection,1,3,1
' Show customer names for all customers
While not rscustomers.eof
%>
<br><input type= "checkbox" Name= "CustomerId" value= "<%=rscustomers (" CustomerId ")%>" >
<a href= "Mailto:<%=rscustomers (" Customeremail ")%>" >
<%=rscustomers ("CustomerName")%></a>
<%rscustomers.movenext
Wend
Rscustomers.close
Set rscustomers = Nothing
Dbconnection.close
Set dbconnection = Nothing
%>
<br><input type= "Submit" value= "send email to Customer" name= "B1"
Style= "font-family: XXFarEastFont-Font-size:9pt" >
</form></body><!--sendmail.asp: Email the selected customer-->
<p align=center><font style= "font-family: Song Body; font-size:9pt" >
Sending e-mail to the following customers
<% ' Establish a connection with an Access database
Set dbconnection = Server.CreateObject ("ADODB. Connection ")
Dbconnection.open "Driver={microsoft Access Driver (*.mdb)};" &_
"Dbq=c:/inetpub/wwwroot/test/email.mdb"
' Get the email address of the selected customer
Set rscustomers = Server.CreateObject ("ADODB. RecordSet ")
rsCustomers.Open "Select customername,customeremail from Emaillist where CustomerId in (" &_
Request ("CustomerId") & ")", dbconnection,1,3,1
While not rscustomers.eof
' Send an email to a client
Set MyMail = CreateObject ("CDONTS. NewMail ")
Mymail.from = "Sales@test.com"
Mymail.value ("reply-to") = "sales@test.com"
Mymail.to = rscustomers ("Customeremail")
Mymail.subject = "New Year's Greetings from Wang Fajun"
Mymail.bodyformat = 1
Mymail.mailformat = 1
Mymail.body = "Wang Fajun to" &rscustomers ("CustomerName") & "Hello!" "
Mymail.send
Set MyMail = Nothing
%>
<br> to <a href= "" >mailto:<%=rscustomers ("Customeremail")%> "><%=rscustomers" ("CustomerName" )%></a>
Send email successfully!
<%
Rscustomers.movenext
Wend
Rscustomers.close
Set rscustomers = Nothing
Dbconnection.close
Set dbconnection = Nothing
%>
<br> send email to the selected customer complete!
</body>

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.