Solved

Based on responses, send form data to two different emails

Posted on 2013-02-04
12
410 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
Comment Utility
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
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:Malloy1446
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
0
 

Author Closing Comment

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

Thanks
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Why do we like using grid based layouts in website design? Let's look at the live examples of websites and compare them to grid based WordPress themes.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

771 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

10 Experts available now in Live!

Get 1:1 Help Now