Sending multiple personalized emails from form on asp page

Someone has asked me to make a webform with the following functionality:
Input text boxes for customer name, customer email address.

 10 Input boxes for 5 names and 5 email addresses of friends

Ability to send an email to those 5 friends, where the content is the same, but the emails say Dear Jane, ..... From Julie, another with Dear Alice, ......from Julie

I can send the email by picking up the 5 email addresses and putting them in a BCC list separated by commas. But I have to send one email personalized for each of the 5 people. I'm having trouble knowing how to start iterating thru the email addresses. (I think I can pick up the names once I learn what procedure to use)

I've created each of the 5 email address fields like this:
   <input type="text" name="txtToAddress" size="40" value="" id="1">
and given them an id of 1-5.
The software sends one email like the following and I can get it to work when I send to all the BCCs, but I need send up to 5 separate emails with one submit button:
cbNotifier.SendMail(objToken, sValidAddresses, txtFromAddress, txtToAddress, txtCCList, txtBCCList, txtSubject, txtBody, false)
            
jmestepAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

chisholmdCommented:
like this?

<%
n = request.form("txtToAddress").count
for counter = 1 to n
     txtToAddress = request.form("txtToAddress")(counter)
    txtBody = "Dear " & request.form("txtName")(counter)
    ....
    cbNotifier.SendMail(objToken, sValidAddresses, txtFromAddress, txtToAddress, txtCCList, txtBCCList, txtSubject, txtBody, false)
next

%>
0
jmestepAuthor Commented:
I can see you are sending me in the right direction. I put the code in and got this error message:


n = request.form("txtToAddress").count---------------Error message is:
 BC30456: 'count' is not a member of 'String'

I probably need to add that the page is .aspx instead of .asp, if that makes any different. There is no "true" .net code on it- it's a combination of asp, javascript and vbscript.
0
jmestepAuthor Commented:
0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

chisholmdCommented:
You have  5 inputs called txtToAddress right?  or did you name each uniquely?  txtToAddress1, txtToAddress2 etc.

If you have more then one "txtToAddress" on the form then it should work.
0
kelvinwkwCommented:
try this one


<%

dim splitedEmail
dim splitedName
dim splitCount
splitedEmail = split(request.form("txtToAddress"), ", ")
splitedName = split(request.form("txtName"), ", ")
splitCount = ubound(splitedEmail)

for i = 0 to splitCount
     if len(splitedEmail(i)) > 0  and len(splitedName(i)) > 0 then
       txtToAddress = splitedEmail(i)
       txtBody = "Dear " & splitedName(i)
       ....
       cbNotifier.SendMail(objToken, sValidAddresses, txtFromAddress, txtToAddress, txtCCList, txtBCCList, txtSubject, txtBody, false)
     else
       exit for
     end if
next
%>


Regards
Kelvin
0
chisholmdCommented:
Just  note that you really shouldn't have to do the split manually. ASP will treat multiple inputs with the same name as a collection*

0
jmestepAuthor Commented:
You have  5 inputs called txtToAddress right?
Yes, I do.

Maybe the problem is that the existing code on the page is in the <head> of the page.
Here's a part of it:
if Len(txtToAddress) > 0 then
arrToAddress = Split(txtToAddress, ",")
for i = 0 to ubound(arrToAddress)
if RegEx.Matches(arrToAddress(i), "^([-!#\$%&'*+./0-9=?A-Z^_`a-z{|}~ ])+@[-!#\$%&'*+/0-9=?A-Z^_`a-z{|}~ ]+(\.[-!#\$%&'*+/0-9=?A-Z^_`a-z{|}~ ]+)?\.([a-zA-Z]{2,5})$").Count = 0 then
strMessage = strMessage & "Email address rejected: " & arrToAddress(i) & "<BR>"
else
sValidAddresses = sValidAddresses & arrToAddress(i) & ","
end if
next i
strMessage = strMessage & "Thank you for your submission. Messages were sent to your friends." & "<BR>"
if len(sValidAddresses) > 0 then
sValidAddresses = Left(sValidAddresses, Len(sValidAddresses) - 1)
cbNotifier.SendMail(objToken, sValidAddresses, txtFromAddress, "", "", txtBCCList, txtSubject, txtBody, false)
end if

Searching on the web, I did see a couple of code snippets like:
for each formitem in Request.Form  strBody=strBody & formitem & " = " & request(formitem) & vbcrlf next

but I don't think I used them correctly. Should I sayFor each txtToAddress?
0
jmestepAuthor Commented:
This is almost working now. I couldn't get the code from chisolmd to work, but the code from kelvinwkw almost works. It sends the email to each recipient, but in the body it starts out like:
Dear Amy1,Amy2,,,
This is when I put in two names and email addresses, not the full five. I need to to not concatenate them and for the code to work whether someone puts in 1 up to 5 email addresses. Here's the code I'm using.
dim splitedEmail
dim splitedName
dim splitCount
splitedEmail = split(request.form("txtToAddress"), ", ")
splitedName = split(request.form("txtFriendName"), ", ")
splitCount = ubound(splitedEmail)

for i = 0 to splitCount
    if len(splitedEmail(i)) > 0  and len(splitedName(i)) > 0 then
       txtToAddress = splitedEmail(i)
       txtBody = "Dear " & splitedName(i) & vbcrlf & txtBody & txtSenderName

       cbNotifier.SendMail(objToken, txtToAddress, txtFromAddress, "", "", txtBCCList, txtSubject, txtBody, false)
     else
       exit for
     end if
next
0
chisholmdCommented:
I can't imagine why it does not work for you.

Check out:
 http://lonecrow.net/splittest.asp

 Full example and source.  Works fine

<html>
<head>
      <title>Untitled</title>
</head>

<body>
<%

n = request.form("txtToAddress").count
for counter = 1 to n
    txtToAddress = request.form("txtToAddress")(counter)
    txtBody = "Dear " & request.form("txtToName")(counter)
      response.write "send to " & request.form("txtToAddress")(counter) & "... Dear, " & txtBody & "<br/>"
    'cbNotifier.SendMail(objToken, sValidAddresses, txtFromAddress, txtToAddress, txtCCList, txtBCCList, txtSubject, txtBody, false)
next
%>

<form action='splittest.asp' method='post' >
<input type='text' name='txtToName' value='Bob' />&nbsp;&nbsp;<input type='text' name='txtToAddress' value='Bob@somewhere.com' /><br/>
<input type='text' name='txtToName' value='Sue' />&nbsp;&nbsp;<input type='text' name='txtToAddress' value='Sue@somewhere.com' /><br/>
<input type='text' name='txtToName' value='Ted' />&nbsp;&nbsp;<input type='text' name='txtToAddress' value='Ted@somewhere.com' /><br/>
<input type='text' name='txtToName' value='Eve' />&nbsp;&nbsp;<input type='text' name='txtToAddress' value='Eve@somewhere.com' /><br/>
<input type='text' name='txtToName' value='Jim' />&nbsp;&nbsp;<input type='text' name='txtToAddress' value='Jim@somewhere.com' /><br/>
<input type='submit' name='submit' value='submit' />
</form>

</body></html>
0
jmestepAuthor Commented:
I'll look at it again. This is the error message I got
n = request.form("txtToAddress").count---------------Error message is:
 BC30456: 'count' is not a member of 'String'

maybe I need to  dim n as an integer?
0
chisholmdCommented:
What version of IIS are you using maybe thats it, you can see that the code works fine on my example page so either it is not supported on your iis or there is some other error in your code.  I am fairly sure that format is supported by IIS5 and 6

Dave
0
chisholmdCommented:
Although I don't think it should matter you can also try to remove the unique ID that you give each input.
 <input type="text" name="txtToAddress" size="40" value="" id="1">
0
kelvinwkwCommented:
So this is the problem right
Amy1,Amy2,,,

try change this one
splitedName = split(request.form("txtFriendName"), ", ")
to
splitedName = split(request.form("txtFriendName"), ",")


dim splitedEmail
dim splitedName
dim splitCount
splitedEmail = split(request.form("txtToAddress"), ", ")
splitedName = split(request.form("txtFriendName"), ",")
splitCount = ubound(splitedEmail)

for i = 0 to splitCount
    if len(splitedEmail(i)) > 0  and len(splitedName(i)) > 0 then
       txtToAddress = splitedEmail(i)
       txtBody = "Dear " & splitedName(i) & vbcrlf & txtBody & txtSenderName

       cbNotifier.SendMail(objToken, txtToAddress, txtFromAddress, "", "", txtBCCList, txtSubject, txtBody, false)
     else
       exit for
     end if
next

Regards
Kelvin
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jmestepAuthor Commented:
kelvinwkw
That correction took me a step further. (Taking out the space after the comma, wasn't it?) That gave me 2 emails, both of them saying Dear [same name] instead of two different names on two emails.  But both to: had 2 email address is in both.
So I took out the space after the comma on splitedEmail and that gave me two emails, one with the first name, one with both names , but it got rid of two email address is in the To: box
0
chisholmdCommented:
I just tried your link and received an error. it looks like your using asp.NET is that correct?

That might explain why your getting that error using my method.  I a curios what they do in .NET so I'll do a little research.
0
kelvinwkwCommented:
How bout this one

splitedEmail = split(request.form("txtToAddress"), ", ")
splitCount = ubound(splitedEmail)
for each element in request.form("txtToName")
      txtBody = ""
      if len(splitedEmail(i)) > 0  and len(element) > 0 then

         txtBody = "Dear " & element & vbcrlf & txtBody & txtSenderName
         cbNotifier.SendMail(objToken, splitedEmail(i), txtFromAddress, "", "", txtBCCList, txtSubject, txtBody, false)
        end if
next

Regards
Kelvin
0
kelvinwkwCommented:
Sorry

splitedEmail = split(request.form("txtToAddress"), ", ")
splitCount = ubound(splitedEmail)
i = 0
for each element in request.form("txtToName")
      txtBody = ""
      response.write element & "<br/>"
      if len(splitedEmail(i)) > 0  and len(element) > 0 then
    txtBody = "Dear " & element & vbcrlf & txtBody & txtSenderName

    'cbNotifier.SendMail(objToken, splitedEmail(i), txtFromAddress, "", "", txtBCCList, txtSubject, txtBody, false)
    response.write txtBody & "<br/>"
   
  end if
  i = i + 1
next

Regards
Kelvin
0
jmestepAuthor Commented:
Here's what I get with that:

BC30451: Name 'element' is not declared.

Source Error:

 

Line 82: splitCount = ubound(splitedEmail)
Line 83: i = 0
Line 84: for each element in request.form("txtToName")
 
0
jmestepAuthor Commented:
Here was something I ran across last night about the for each pulling the fields in random order
http://www.aspfaqs.com/aspfaqs/ShowFAQ.asp?FAQID=64

. I also experimented last night with the i=i+1, but I might have put it into the wrong line.
0
kelvinwkwCommented:
put an
dim element
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.