Solved

Sending Mail Script

Posted on 2001-08-09
9
340 Views
Last Modified: 2012-05-04
I am using the folloiwng script to send results from an email form. What I would like to do is:

 - have the email sent to more then one address
 - have the email sent to a third address using the CC email field

<%

Set Mailer = Server.CreateObject("SMTPsvg.Mailer")
Mailer.RemoteHost = "relay.mysite.com"
Mailer.FromAddress = Request.Form("FromAddress")
Mailer.AddRecipient"Info","info@mysite.com"
Mailer.Subject    = Request.Form("Subject")
strMsgHeader = "Form Information Follows: " & vbCrLf
for i = 1 to Request.Form.Count
  strMsgInfo = strMsgInfo & Request.Form.Key(i) & " - " &  Request.Form.Item(i) & vbCrLf
next
strMsgFooter = vbCrLf & "End of form information"
Mailer.BodyText = strMsgHeader & strMsgInfo & strMsgFooter


if Mailer.SendMail then
Response.Redirect("thankyou.asp")

else
Response.Redirect("error.asp")

end if
%>
0
Comment
Question by:ASCAN
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 3

Expert Comment

by:CyberSoft
ID: 6368016
ASCAN,

Is there any reason why you've opted to use a third party mailer instead of using built in CDO in IIS because CDO supports the multiple email addresses in the TO and CC fields

See: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cdo/html/_denali_newmail_object_cdonts_library_.asp

CyberSoft

PS: Respond here if you want some example code using CDO.
0
 
LVL 7

Accepted Solution

by:
John844 earned 100 total points
ID: 6368337
to add multiple recipients I believe that you can just repeat the next line changing the name and email for each new person.
Mailer.AddRecipient"Info","info@mysite.com"

to add the cc recipient, there should be a method similar to the one above, maybe AddCCRecipient.  I don't have that component for reference currently.

John
0
 
LVL 7

Expert Comment

by:John844
ID: 6368359
to add a CC recipient just add a line like

Mailer.AddCC "somename", "someemail.email.com"
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 33

Expert Comment

by:hongjun
ID: 6368593
John844 is correct.

hongjun
0
 
LVL 7

Expert Comment

by:John844
ID: 6368612
thanks for the confirmation hongjun
John
0
 
LVL 33

Expert Comment

by:hongjun
ID: 6368724
For me I am not sure about the component used but for most of the components in the market I know, the algorithm is like that. So I presume that should also be like this. Perhaps, your user manual will tell you more.

hongjun
0
 
LVL 1

Expert Comment

by:bahu_m
ID: 6370306
To send email to multiple users you have to keep adding the users using AddRecipient method. For CC use AddCC method. Check the following code:


Set Mailer = Server.CreateObject("SMTPsvg.Mailer")
Mailer.RemoteHost = "relay.mysite.com"
Mailer.FromAddress = Request.Form("FromAddress")

Mailer.AddRecipient "Info","info@mysite.com"
Mailer.AddRecipient "Info1","info1@mysite.com"
Mailer.AddRecipient "Info2","info2@mysite.com"
Mailer.AddCC "ccname", "ccname@mysite.com"

Mailer.Subject    = Request.Form("Subject")
strMsgHeader = "Form Information Follows: " & vbCrLf
for i = 1 to Request.Form.Count
     strMsgInfo = strMsgInfo & Request.Form.Key(i) & " - " &  Request.Form.Item(i) & vbCrLf
next
strMsgFooter = vbCrLf & "End of form information"
Mailer.BodyText = strMsgHeader & strMsgInfo & strMsgFooter
if Mailer.SendMail then
     Response.Redirect("thankyou.asp")
else
     Response.Redirect("error.asp")
end if
0
 
LVL 33

Expert Comment

by:hongjun
ID: 6370720
bahu_m, that's what John had commented.

hongjun
0
 

Expert Comment

by:pinkstonm
ID: 13212889
Are these statements for CDO?

Mailer.AddRecipient "Info","info@mysite.com"
Mailer.AddRecipient "Info1","info1@mysite.com"
Mailer.AddRecipient "Info2","info2@mysite.com"
Mailer.AddCC "ccname", "ccname@mysite.com"
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question