Tech or Treat! Write an article about your scariest tech disaster to win gadgets!Learn more

x
?
Solved

Based on responses, send form data to two different emails

Posted on 2013-02-04
12
Medium Priority
?
466 Views
Last Modified: 2013-02-10
I have a form with 5 headings. Each heading has multiple check boxes for uses to select.
The majority of the data needs to be emailed to ONE email address. BUT, there is ONE heading (Heading 4 data) that I need to send to a different email. I do want to keep the selections from Headings 1, 2, 3, and 5 in one email.

How do I add a 2nd email for just heading 4 data.

Code is attached.
eAlertEE.txt
0
Comment
Question by:Malloy1446
[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
  • 4
  • 3
  • 2
  • +1
12 Comments
 
LVL 54

Expert Comment

by:Scott Fell, EE MVE
ID: 38853800
Can't see how you are sending your mail. But where you have

txtBody = txtBody & "<p><b>Heading 4</b><br>"
      If request("Flowers")=1 then
            txtBody = txtBody & "Flowers<br>
      End If

You can change to

txtBody = txtBody & "<p><b>Heading 4</b><br>"
    flowerMail=0  ' set 2nd email flag to 0
      If request("Flowers")=1 then
            txtBody = txtBody & "Flowers<br>"
            flowerMail=1  'if checked, set 2nd email flat to 1
      End If

Then where you have your include file <!-- #INCLUDE VIRTUAL="CodeReuse/Mailer.asp" --> is probably where you are sending out mail and where you have your code to send the mail you can have

if flowerMail=1 then
     ' code to send 2nd meail
end if
0
 

Author Comment

by:Malloy1446
ID: 38856795
I am missing something. I am attaching copies of my MAILER.asp and my new code.

The only mail being sent is for the last section (FLOWERMAIL)
Mailer.txt
eAlertEE-2.txt
0
 
LVL 54

Accepted Solution

by:
Scott Fell,  EE MVE earned 2000 total points
ID: 38871535
Change your mail code to a function
    <%
	function sendMail(txtTo,txtSub,xttBody)
	
        'Create instances of our CDOSYS objects.
        Set mailObj = Server.CreateObject("CDO.Message")
        Set confObj = Server.CreateObject("CDO.Configuration")

        'Configure our information.
        Set fields = confObj.Fields
        fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
        fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.##.###"
        fields.Update

        'Configure our test email.
        Set mailObj.Configuration = confObj
        mailObj.From = "####@##.###"
        
        
        mailObj.Subject = txtSub
        mailObj.HTMLBody = txtBody

        'Add a recipient address.
        mailObj.To = txtTo

        'We need to catch the error.
        On Error Resume Next
        mailObj.Send
        If (Err <> 0) Then
            Response.Write "There was an error sending the email: " & Err.Description
        End If
		
		end function
    %>

Open in new window


Your vb in your main page would call the function once, then a 2nd time if flowers=1

<%
step = request.querystring("step")

If step = 1 then

txtTo = "XXXXXX2@XX.XXX"
txtSub = "e-Alert Request"
txtBody = "<b>Name:</b> " & request.form("Name")
txtBody = txtBody & "<p><b>Email:</b> " & request.form("Email")
txtBody = txtBody & "<p>Please add this user to the following distribution lists:"

txtBody = txtBody & "<p><b>Heading 1</b><br>"

	If request("One")=1 then
		txtBody = txtBody & "One<br>"
	End If
	
	If request("Two")=1 then
		txtBody = txtBody & "Two<br>"
	End If


txtBody = txtBody & "<p><b>Heading 2</b><br>"

	If request("Apples")=1 then
		txtBody = txtBody & "Apples<br>"
	End If
	
	If request("Bananas")=1 then
		txtBody = txtBody & "Bananas<br>"
	End If
	
	If request("Cantaloupe")=1 then
		txtBody = txtBody & "Cantaloupe<br>"
	End If
	
	If request("Fig")=1 then
		txtBody = txtBody & "Fig<br>"
	End If
	
	

txtBody = txtBody & "<p><b>Heading 3</b><br>"

	If request("Elephant")=1 then
		txtBody = txtBody & "Elephant<br>"
	End If
	
	If request("Rhino")=1 then
		txtBody = txtBody & "Rhino<br>"
	End If
	
	If request("Zebra")=1 then
		txtBody = txtBody & "Zebra<br>"
	End If
	
	      
txtBody = txtBody & "<p><b>Heading 5</b><br>"

	If request("Aspen")=1 then
		txtBody = txtBody & "Aspen<br>"
	End If
	
	If request("Birch")=1 then
		txtBody = txtBody & "Birch<br>"
	End If
	
	If request("Oak")=1 then
		txtBody = txtBody & "Oak<br>"
	End If
	
	If request("Pine")=1 then
		txtBody = txtBody & "Pine<br>"
	End If
	

sendMail(xtxTo,txtSub,xttBody)

	
dim FlowerMail

txtBody = txtBody & "<p><b>Heading 4</b><br>"
flowerMail=0  
' set 2nd email flag to 0

      If request("Flowers")=1 then
            txtBody = txtBody & "Flowers<br>"
            flowerMail=1  
            'if checked, set 2nd email flag to 1
			txtTo = "XXXXX@###.com"
			txtSub = "e-Alert Request"
			txtBody = "<b>Name:</b> " & request.form("Name")
			txtBody = txtBody & "<p><b>Email:</b> " & request.form("Email")
			txtBody = txtBody & "<p>Please add this user to the following distribution lists:"

			txtBody = txtBody & "<p><b>Heading 4: Flowers</b><br>"
			
			sendMail(xtxTo,txtSub,xttBody)
			
      End If
      
%>      
      

Open in new window

0
Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

 
LVL 54

Expert Comment

by:Scott Fell, EE MVE
ID: 38871539
On a side note, make sure you are scrubbing your input for things like request.form("Name")
0
 
LVL 18

Expert Comment

by:Gary Davis
ID: 38871543
Looks like you are only calling the send-email once, at the end.  You set up the variables for the first email and then for the second email and then you do the send. You need to send the first email before you set up the variables for the 2nd, perhaps with a second "include" at the right point.
0
 

Author Comment

by:Malloy1446
ID: 38872033
I am sorry I am still unable to get this code to work. My code is now generating "The website cannot display the page" error.

I am attaching my most recent.
eAlertEE-Feb9.txt
0
 
LVL 18

Expert Comment

by:Gary Davis
ID: 38872164
There are many reasons for that error - including being unable to reach the web server. Try using the browser debugger (F12) and going to the network tab. Click the Start Captturing button and then re-attempt the page request and see if any clues are displayed in the debugger.
0
 
LVL 12

Expert Comment

by:jagssidurala
ID: 38872357
Take two variables for body text.

txtBody for Headings other than 5,
txtBody1 for Heading 4.

Based on the value presence send a mail to the respective email address.

i.e., if txtBody not equql to empty sent to abc@abc.com and if txtBody1 not equql to empty sent to xyz@abc.com.
0
 
LVL 54

Expert Comment

by:Scott Fell, EE MVE
ID: 38872372
0
 

Author Closing Comment

by:Malloy1446
ID: 38873688
Code is working. THe problem was I had the function routine in the wrong spot.

Thanks
0

Featured Post

Independent Software Vendors: 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

When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to dynamically set the form action using jQuery.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

648 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