Print Page | Close Window

send email to selected users in DB

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=5746
Printed Date: 30 March 2026 at 11:40pm
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: send email to selected users in DB
Posted By: dizzyfunk
Subject: send email to selected users in DB
Date Posted: 14 September 2003 at 2:52pm

i want to be able to search a database of users on a variety of criteria, then send an email (using cdonts or jmail) to only the users that the search brought back.

eg... i will search the DB for all surname of 'smith' then send them an email. next i will search for surname 'johnson' AND city of 'london' and then send them an email...

i want to see the search results displayed on a page first so i can look at it.. that i can do... i then want a button on the results page that will send the email to all users on that page...

you see, the search criteria can vary each time.

hope some one can help me from pulling my hair out...

many thanks.. an asp newbie ;)

 

 




Replies:
Posted By: mapnapkin
Date Posted: 14 September 2003 at 4:45pm

i use access db and aspEmail but you can rearrange this for your use

---------------------------------------
<%
Dim Mail, customer

set conn=Server.CreateObject("ADODB.Connection")
conn.provider="Microsoft.Jet.OLEDB.4.0"
conn.open(server.mappath("database.mdb"))
set rs = Server.CreateObject("ADODB.Recordset")
rs.Open "SELECT customers.custemail FROM customers, orders WHERE orders.cust_id=customers.cust_id AND orders.lottostate='" & Request.Form("lottostate") & "' AND orders.order_status='active' AND orders.expire_date>= date() ", conn
%>
<%
do until rs.EOF
%>
<%
customer=rs("custemail")
%>
<%
Set Mail = Server.CreateObject("Persits.MailSender")
Mail.Host = "smtp.domain.com" ' Specify a valid SMTP server
Mail.From = " mailto:email@website.com - email@website.com " ' Specify sender's address
Mail.FromName = "Your From Name" ' Specify sender's name
Mail.AddAddress customer
Mail.AddReplyTo " mailto:email@website.com - email@website.com "
Mail.Subject = "..Your Subject.."
Mail.isHTML = True
Mail.Body = request.form("body")

On Error Resume Next
Mail.Send

IF Err <> 0 THEN
Response.Write "Ah man.. you messed it up!! <font color=""#ff0000"">""" & Err.Description & """</font>"
END IF
%>

<%
rs.MoveNext
loop
%>

<%
rs.close
conn.close
Set Mail = Nothing
Set rs = Nothing
set conn = Nothing
%>

<%
Response.Write "Your message has been successfully sent.<br /><br /><strong><font color=""#FF0000""><a href=""page.asp"">BACK</a></font></strong& gt;</font>"
%>
----------------------------------------------------

hope that helps



Posted By: dizzyfunk
Date Posted: 14 September 2003 at 5:04pm

no.. i can do this....

maybe it isn't clear!

this is ok when i know what the search criteria is.. but this will differ each time.. imagine an advanced search form.. you only use a couple of the search fields, but one search will use different fields from the last.. therefore i won't know what SQL string to write out eachtime to send the email?

(please read my original post clearly - I DO NOT NEED TO KNOW HOW TO SEND EMAIL USING ASP - that i can do)



Posted By: mapnapkin
Date Posted: 14 September 2003 at 5:17pm

ok cap lock

what is your submit form code



Posted By: dizzyfunk
Date Posted: 14 September 2003 at 5:26pm

SORRY!

no.. today i may wish to search the db for people in london then email them... (1 criteria)

2moro i'll need all the 'smiths' from manchester and email them.. (2 criteria)

then i might need to be more specific and search for people from london, with birthday in september, and surname of jones (3 criteria)

so ya see it's always different!

if it was always the same one it'd be easy, but it's not



Posted By: mapnapkin
Date Posted: 14 September 2003 at 5:41pm

you can put an "if then" statment in your SELECT string.... to check if a text field is empty if its not then then response.write it into your SELECT string
-----------------------------

sqlselect ="SELECT * FROM emails WHERE " "

<% if Requst.form("surname")="" then  %><%else%>
sqlselect = sqlselect & " surname=' " & Request.Form("surname") &" ' "
<%end if%>

<% if Requst.form("city")="" then  %><%else%>
sqlselect = sqlselect & " AND city=' " & Request.Form("city") &" ' "
<%end if%>

---------------------------
something like that



Posted By: dizzyfunk
Date Posted: 14 September 2003 at 5:49pm

yup.. thanks.. i can see that workin!

thanks for your time.




Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net