Solved

Based on responses, send form data to two different emails

Posted on 2013-02-04
12
430 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
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.

 
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Get to know the ins and outs of building a web-based ERP system for your enterprise. Development timeline, technology, and costs outlined.
Developer portfolios can be a bit of an enigma—how do you present yourself to employers without burying them in lines of code?  A modern portfolio is more than just work samples, it’s also a statement of how you work.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…

813 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now