Solved

Based on responses, send form data to two different emails

Posted on 2013-02-04
12
437 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
  • 4
  • 3
  • 2
  • +1
12 Comments
 
LVL 52

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 52

Accepted Solution

by:
Scott Fell,  EE MVE earned 500 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
Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

 
LVL 52

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 52

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

"In order to have an organized way for empathy mapping, we rely on a psychological model and trying to model it in a simple way, so we will split the board to three section for each persona and a scenario and try to see what those personas would Do,…
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.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

839 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