Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Send to a friend with multiple email addresses

Status
Not open for further replies.

aamaker

Programmer
Jan 20, 2002
222
0
0
US
Im trying to figure out a way to develop a send to a friend page that will allow the user to enter (into separate input fields) up to 10 email addresses of their friends, then send an email message (using CDONTS) with a pre-defined message to each of the recipient addresses (with each being addressed individually to that user).

What would the asp for that need to look like...specifically, the idea of somehow looping through for each address entered.

Im trying to learn asp and this one has me stumped.

Can someone show me some rough example of this in ASP?


-- Thanks for any light you can shed on this for me
 
Ok, here is an already done tell a friend, you can make the present message as the text box just turn its type into a "hidden" and it won't show so they can't edit it, and i would loop it like your saying. If you need more help with it i can try making it for you.

 
I have the form submitting up to 10 text input fields (named FriendAddress_1 through FriendAddress_10)...

Im using an incremental integer to move from address to address... kind of like this:
while...
email_i=1
while email_i <=10

...wend




... then Im trying to say

if EMAILADDRESSVAR & email_i <> &quot;&quot; Then

<<CDONTS code to send email message here >>

End If

Somethings not working though... can you show me how you'd handle the loopint element? Thanks for your help!

 
You can name 10 textbox with samename, different id.
Then you go through the loop and assign each strTo with an address, then call the Send Mail function. Something like:

For i = 0 to 9
strTo = txtTo(i)
Call SendEmail(strTo,strSubject,strBody)
Next
 
I think I see what you mean, can you take your example a step further - the mailing routine, I have - dont worry about that, but the idea of same field names with diff variables and then looping through - can you illustrate that using the method you mention in your post?

Thanks for your help.
 
Ok, here you go:

'name the textbox like this:
<% For i = 0 to 2 %>
<tr>
<td>To: &nbsp;</td>
<td><input type=&quot;text&quot; name=&quot;strTo<%=i%>&quot;></td>
</tr>
<%Next%>

'and then send email like this:
<%
For i = 0 to 2
strTo = Request(&quot;strTo&quot;&i&&quot;&quot;)
Call SendMessage(strFrom, strTo, strSubject, strBody)
Next
%>
 
Im going mad trying to figure this out...

here is the code for the page im working on... can you use this to show me how/where the loop/sub elements go...

-- Thanks

<html>
<body>


<%
If request.querystring(&quot;state&quot;) = &quot;&quot; Then
%>
<form action=&quot;sendtofriends.asp?state=send&quot; method=&quot;post&quot;>
<TABLE width=&quot;516&quot; border=0 cellPadding=2 cellSpacing=3>
<TR>
<TD width=&quot;26%&quot;><FONT face=&quot;Arial, Helvetica, sans-serif&quot; size=2>Your
First Name* </FONT></TD>
<TD width=&quot;74%&quot; vAlign=top><INPUT name=FIRST_NAME size=&quot;30&quot;>
</TD>
</TR>
<TR>
<TD><FONT face=&quot;Arial, Helvetica, sans-serif&quot; size=2>Your
Last Name*</FONT></TD>
<TD><INPUT name=LAST_NAME size=&quot;30&quot;> </TD>
</TR>
<TR>
<TD><FONT face=&quot;Arial, Helvetica, sans-serif&quot; size=2>Your
eMail Address*</FONT></TD>
<TD><INPUT name=EMAIL_ADDRESS size=&quot;30&quot;> </TD>
</TR>
<TR>
<TD colSpan=2><BR> <B><FONT face=&quot;Arial, Helvetica, sans-serif&quot; size=3>eMail
To: </FONT></B><FONT face=&quot;Arial, Helvetica, sans-serif&quot; size=2><I>(Fill
in your friends' eMail addresses below.)</I></FONT></TD>
</TR>
<TR>
<TD colSpan=2>

<% For i = 0 to 9 %>
<TABLE cellSpacing=0 cellPadding=0 border=0>
<br />
<TR>
<TD width=&quot;16&quot; class=&quot;reflabel&quot;><div align=&quot;right&quot;>1</div></TD>
<TD width=&quot;192&quot;> <INPUT size=30 name=&quot;FRIEND_EMAIL&quot; id=&quot;1&quot;>
</TD>
<TD width=&quot;16&quot; class=&quot;reflabel&quot;><div align=&quot;right&quot;>6</div></TD>
<TD width=&quot;181&quot;> <DIV align=right>
<INPUT size=30 name=&quot;FRIEND_EMAIL&quot; id=&quot;6&quot;>
</DIV></TD>
</TR>
<TR>
<TD class=&quot;reflabel&quot;><div align=&quot;right&quot;>2</div></TD>
<TD> <INPUT size=30 name=&quot;FRIEND_EMAIL&quot; id=&quot;2&quot;> </TD>
<TD class=&quot;reflabel&quot;><div align=&quot;right&quot;>7</div></TD>
<TD> <DIV align=right>
<INPUT size=30 name=&quot;FRIEND_EMAIL&quot; id=&quot;7&quot;>
</DIV></TD>
</TR>
<TR>
<TD class=&quot;reflabel&quot;><div align=&quot;right&quot;>3</div></TD>
<TD> <INPUT size=30 name=&quot;FRIEND_EMAIL&quot; id=&quot;3&quot;> </TD>
<TD class=&quot;reflabel&quot;><div align=&quot;right&quot;>8</div></TD>
<TD> <DIV align=right>
<INPUT size=30 name=&quot;FRIEND_EMAIL&quot; id=&quot;8&quot;>
</DIV></TD>
</TR>
<TR>
<TD class=&quot;reflabel&quot;><div align=&quot;right&quot;>4</div></TD>
<TD> <INPUT size=30 name=&quot;FRIEND_EMAIL&quot; id=&quot;4&quot;> </TD>
<TD class=&quot;reflabel&quot;><div align=&quot;right&quot;>9</div></TD>
<TD> <DIV align=right>
<INPUT size=30 name=&quot;FRIEND_EMAIL&quot; id=&quot;9&quot;>
</DIV></TD>
</TR>
<TR>
<TD class=&quot;reflabel&quot;><div align=&quot;right&quot;>5</div></TD>
<TD> <INPUT size=30 name=&quot;FRIEND_EMAIL&quot; id=&quot;5&quot;> </TD>
<TD class=&quot;reflabel&quot;><div align=&quot;right&quot;>10</div></TD>
<TD> <DIV align=right>

<INPUT size=30 name=&quot;FRIEND_EMAIL&quot; id=&quot;10&quot;>
</DIV></TD>
</TR>
</TABLE>

<%Next%>


</TD>
</TR>
<TR>
<TD></TD>
<TD><input type=&quot;submit&quot; name=&quot;Sendtofriend&quot; value=&quot;Send This Message >>&quot;></TD>
</TR>
</TABLE>

</form>
<% End If %>


<%
If request.querystring(&quot;state&quot;) = &quot;send&quot; Then

Dim sendername, senderemail, theToAddress, sendermessage

sendername = request.form(&quot;First_Name&quot;) & request.form(&quot;Last_Name&quot;)
senderemail = request.form(&quot;Email_Address&quot;)
theToAddress = request.form(&quot;Friend_Email&quot;)
sendermessage = senderemail & &quot; enjoyed reading about Our Latest Projects,and thought you would like to receive a copy as well.&quot; &vbcrlf & vbcrlf & &quot;If you would like to continue to receive copies of our enewsletter, click the subscribe link below and you will receive these directly in your email box in the future!&quot;

Dim MyBody
Dim MyCDONTSMail

Set MyCDONTSMail = CreateObject(&quot;CDONTS.NewMail&quot;)
MyCDONTSMail.From= &quot;&quot; & senderemail
MyCDONTSMail.Subject= &quot;Thought you'd find this E-Newsletter Interesting! From &quot; & senderemail
MyBody = sendermessage & vbCrLf & vbCrLf
MyBody = MyBody & &quot;_______________________________________________________________&quot; & vbcrlf
MyCDONTSMail.Body= MyBody
MyCDONTSMail.Send
Response.write(&quot;All done now!&quot;)



End If %>

</body>
</html>
 
Hey aamaker,

When I said &quot;same name, different id&quot; I didn't mean:

<INPUT size=30 name=&quot;FRIEND_EMAIL&quot; id=&quot;1&quot;>

What I meant was :
<INPUT size=30 name=&quot;FRIEND_EMAIL&quot;&i&&quot;&quot;>

Sorry if I confused you. You need to put the email part in a function then call this function with theToAddress parameter.

Anyways, here is the code you need. I just tested it myself. It works great. Let me know how it work.

Good luck.

<%
If request.querystring(&quot;state&quot;) = &quot;&quot; Then
%>
<form action=&quot;emailafriend.asp&quot; method=&quot;post&quot;>
<TABLE width=&quot;516&quot; border=0 cellPadding=2 cellSpacing=3>
<TR>
<TD width=&quot;26%&quot;><FONT face=&quot;Arial, Helvetica, sans-serif&quot; size=2>Your
First Name* </FONT></TD>
<TD width=&quot;74%&quot; vAlign=top><INPUT name=FIRST_NAME size=&quot;30&quot;>
</TD>
</TR>
<TR>
<TD><FONT face=&quot;Arial, Helvetica, sans-serif&quot; size=2>Your
Last Name*</FONT></TD>
<TD><INPUT name=LAST_NAME size=&quot;30&quot;> </TD>
</TR>
<TR>
<TD><FONT face=&quot;Arial, Helvetica, sans-serif&quot; size=2>Your
eMail Address*</FONT></TD>
<TD><INPUT name=EMAIL_ADDRESS size=&quot;30&quot;> </TD>
</TR>
<TR>
<TD colSpan=2><BR> <B><FONT face=&quot;Arial, Helvetica, sans-serif&quot; size=3>eMail
To: </FONT></B><FONT face=&quot;Arial, Helvetica, sans-serif&quot; size=2><I>(Fill
in your friends' eMail addresses below.)</I></FONT></TD>
</TR>
<TR>
<TD colSpan=2>


<TABLE cellSpacing=0 cellPadding=0 border=0>
<br />
<% For i = 1 to 5 %>
<TR>
<TD width=&quot;16&quot; class=&quot;reflabel&quot;><div align=&quot;right&quot;><%=i%></div></TD>
<TD width=&quot;192&quot;> <INPUT size=30 name=&quot;FRIEND_EMAIL<%=i%>&quot;>
</TD>
<% k = i + 5 %>
<TD width=&quot;16&quot; class=&quot;reflabel&quot;><div align=&quot;right&quot;><%=k%></div></TD>
<TD width=&quot;181&quot;> <DIV align=right>
<INPUT size=30 name=&quot;FRIEND_EMAIL<%=k%>&quot;>
</DIV></TD>
</TR>
<%Next%>
</TABLE>




</TD>
</TR>
<TR>
<TD></TD>
<TD><input type=&quot;submit&quot; name=&quot;Sendtofriend&quot; value=&quot;Send This Message >>&quot;></TD>
</TR>
</TABLE>

</form>
<% End If %>


<%
If request.querystring(&quot;state&quot;) = &quot;send&quot; Then

Dim theToAddress
For i = 1 to 10
theToAddress = request.form(&quot;Friend_Email&quot;&i&&quot;&quot;)
Call SendEmail(sendername, senderemail, theToAddress, sendermessage)
Next

Function SendEmail(sendername, senderemail, theToAddress, sendermessage)
Dim MyBody
Dim MyCDONTSMail
sendername = request.form(&quot;First_Name&quot;) & request.form(&quot;Last_Name&quot;)
senderemail = request.form(&quot;Email_Address&quot;)
sendermessage = senderemail & &quot; enjoyed reading about Our Latest Projects,and thought you would like to receive a copy as well.&quot; &vbcrlf & vbcrlf & &quot;If you would like to continue to receive copies of our enewsletter, click the subscribe link below and you will receive these directly in your email box in the future!&quot;

Set MyCDONTSMail = CreateObject(&quot;CDONTS.NewMail&quot;)
MyCDONTSMail.From= senderemail
MyCDONTSMail.To = theToAddress
MyCDONTSMail.Subject= &quot;Thought you'd find this E-Newsletter Interesting! From &quot; & senderemail
MyBody = sendermessage & vbCrLf & vbCrLf
MyBody = MyBody & &quot;_______________________________________________________________&quot; & vbcrlf
MyCDONTSMail.Body= MyBody
MyCDONTSMail.Send
'Response.Write senderemail
'Response.Write sendername
'Response.Write sendermessage
Response.Write theToAddress
%><BR><%
End Function
 
Thanks... Now I see what you meant...

Quick question... while you were working on that I WAS able to get something to work on my end. Its nothing like the solution you put together (which I think is more solid)...

Can you take a look at the following and point out to me where, if any, any flaws exist that would make my version not the optimal solution?


...(I have the input fields named Friend_Email1 through Friend_Email10)...

And the routine like this:

<%
If request.querystring(&quot;state&quot;) = &quot;send&quot; Then
Dim sendername, senderemail, theToAddress, sendermessage

sendername = request.form(&quot;First_Name&quot;) &&quot; &quot;& request.form(&quot;Last_Name&quot;)
senderemail = request.form(&quot;Email_Address&quot;)
sendermessage = senderemail & &quot; enjoyed reading about Our Latest Projects,and thought you would like to receive a copy as well.&quot; &vbcrlf & vbcrlf & &quot;If you would like to continue to receive copies of our enewsletter, click the subscribe link below and you will receive these directly in your email box in the future!&quot;


For i = 0 to 9

if request.form(&quot;Friend_Email&quot;&(i)) <> &quot;&quot; Then
theToAddress = request.form(&quot;Friend_Email&quot;&(i))
call TheMailer
End If
Next

Response.end

Sub THEMAILER
' Dim MyBody
'Dim MyCDONTSMail

Set MyCDONTSMail = CreateObject(&quot;CDONTS.NewMail&quot;)
MyCDONTSMail.From= &quot;&quot; & senderemail
MyCDONTSMail.To= theToAddress
MyCDONTSMail.Subject= &quot;Thought you'd find this E-Newsletter Interesting! From &quot; & senderemail
MyBody = sendermessage
MyCDONTSMail.Body= MyBody
MyCDONTSMail.Send
Response.write(&quot;sent &quot;) & theToAddress & &quot;<br>&quot;
End Sub


End If %>
 
Well, yours is just fine. Using the loop to create the email textboxes will make your code shorter & easier to read. Oh, I didn't check if the email address is empty or not. Yourloop should go from 1 to 10 because you name ur controls from 1 to 10.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top