Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 216
  • Last Modified:

1 form to generate 2 different emails

What I need to do is take the results of a form and generate 2 different emails.
I have the form emailing the form to multiple people but I don't know how to create the different text in each.
This is the code I am working with:

<%
'Send mail

   Set Mailer = Server.CreateObject("SMTPsvg.Mailer")
         Mailer.RemoteHost = "12.111.235.156"

'The from name and from e-mail address

   'Enter name you want the mail to be listed as sent from      
      Mailer.FromName = Literature Form"
   'Enter email address you want the mail to be from
      Mailer.FromAddress = "forms@email.com"

'Add the delivery name and address here
      Mailer.AddBCC "copy@email"
      Mailer.AddRecipient "recipient@email.com"
   
      
     
      Mailer.Subject = " Lighting Literature Request"
   
      Mailer.BodyText = "Name: "  + Request.Form("uName")
      Mailer.BodyText = "Address: "  + Request.Form("Address")
      Mailer.BodyText = "City: "  + Request.Form("City")
      Mailer.BodyText = "Province: "  + Request.Form("Prov")
      Mailer.BodyText = "Postal Code: "  + Request.Form("pCode")
      Mailer.BodyText = " "
      Mailer.BodyText = "Phone: " + Request.Form("Phone")
      Mailer.BodyText = "Fax: " + Request.Form("Fax")
      Mailer.BodyText = "Email: " + Request.Form("Email")
      Mailer.BodyText = " "
      Mailer.BodyText = "Remarks: " + Request.Form("remarks")
      Mailer.BodyText = " "
      Mailer.BodyText = " "
      Mailer.BodyText = MsgBody
      
            
      if Mailer.SendMail then
     'Can put page html here or below
        Response.Write " "
      else
     'If you want the error displayed to the user else just use Response.Write " " like above
        Response.Write "Mail send failure. Error was/is " & Mailer.Response
      end if      
      
      'redirect to a sucessful submit...
      Response.Redirect("literature.asp")
%>

Thanks in advance for any help.
0
allbird79
Asked:
allbird79
  • 5
  • 3
1 Solution
 
danataylorCommented:
Couple of issues here.
First, you missed a quote
    Mailer.FromName = Literature Form"
 Should be:
    Mailer.FromName = "Literature Form"
 
Second, you need to successively build the body by concatenation:
     Mailer.BodyText = "Name: "  + Request.Form("uName")
     Mailer.BodyText = Mailer.BodyText  & "Address: "  + Request.Form("Address")
     Mailer.BodyText = Mailer.BodyText  & "City: "  + Request.Form("City")
     Mailer.BodyText = Mailer.BodyText  & "Province: "  + Request.Form("Prov")
     Mailer.BodyText = Mailer.BodyText  & "Postal Code: "  + Request.Form("pCode")
     Mailer.BodyText = Mailer.BodyText  & " "
     Mailer.BodyText = Mailer.BodyText  & "Phone: " + Request.Form("Phone")
     Mailer.BodyText = Mailer.BodyText  & "Fax: " + Request.Form("Fax")
     Mailer.BodyText = Mailer.BodyText  & "Email: " + Request.Form("Email")
     Mailer.BodyText = Mailer.BodyText  & " "
     Mailer.BodyText = Mailer.BodyText  & "Remarks: " + Request.Form("remarks")
     Mailer.BodyText = Mailer.BodyText  & " "
     Mailer.BodyText = Mailer.BodyText  & " "
     Mailer.BodyText = Mailer.BodyText  & MsgBody
(Not sure where MsgBody comes from - I assume it is from some code not listed here)
You might also need to append a cr/lf or vbcrlf at the end of each line.

Also, if "if Mailer.SendMail then" doesn't work try this:
     if Mailer.Send then


0
 
allbird79Author Commented:
Thanks danataylor.
I do already have the code I provided working, I'm just looking for help on an adition. What I am trying to do is generate one email with all the form information and a second email with all the form information and one account number that can't be seen by the people in the first email.
I don't know if there is a way to do this by generating two emails or just sending that one line to only people who are CC'd. or particular email addresses.
0
 
danataylorCommented:
Since that would involve different bodies you probably need to generate two different e-mails with different distribution lists. If there is only a single line that is different you could build a body without that line and save it in a variable.  Then send the first e-mail.  Then append the line to the variable and send it again to the other list.   I don't know any other way to do it.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
allbird79Author Commented:
Do you just set it up to write from:

<%
'Send mail

   Set Mailer = Server.CreateObject("SMTPsvg.Mailer")
        Mailer.RemoteHost = "12.111.235.156"

     Mailer.FromName = "Literature Form"
     Mailer.FromAddress = "forms@email.com"

     Mailer.AddBCC "copy@email"
     Mailer.AddRecipient "recipient@email.com"
   
     
     Mailer.Subject = " Lighting Literature Request"
   
     Mailer.BodyText = "Name: "  + Request.Form("uName")
     .....
     .....
     .....
Response.Redirect("literature.asp")
%>

and repeat the same tag with the extra line added? Or create a variable as you suggested but still write the tag twice?
0
 
danataylorCommented:
You could probably reuse the BodyText value and, after the first send just append the additional line, create new To/CC/BCC fields and resend.

0
 
allbird79Author Commented:
I've tried that and the second email is overwriting the first email's subject line and both body texts are in each email.

Here is the code I am trying:

<%
'Send mail

   Set Mailer = Server.CreateObject("SMTPsvg.Mailer")
 
      Mailer.RemoteHost = "12.111.345.576"

'The from name and from e-mail address

   'Enter name you want the mail to be listed as sent from      
      Mailer.FromName = "literature request"
   'Enter email address you want the mail to be from
      Mailer.FromAddress = "forms@email.com"

'Add the delivery name and address here
      Mailer.AddBCC "copy@email.com"
      Mailer.AddRecipient "Information", "information@email.com"
   
        
      Mailer.Subject = " Lighting Literature Request"
   
      Mailer.BodyText = "Name: "  + Request.Form("uName")
      Mailer.BodyText = "Address: "  + Request.Form("Address")
      Mailer.BodyText = "City: "  + Request.Form("City")
      Mailer.BodyText = "Province: "  + Request.Form("Prov")
      Mailer.BodyText = "Postal Code: "  + Request.Form("pCode")
      Mailer.BodyText = " "
      Mailer.BodyText = "Phone: " + Request.Form("Phone")
      Mailer.BodyText = "Fax: " + Request.Form("Fax")
      Mailer.BodyText = "Email: " + Request.Form("Email")
      Mailer.BodyText = " "
      Mailer.BodyText = "Remarks: " + Request.Form("remarks")
      Mailer.BodyText = " "
      Mailer.BodyText = " "
      Mailer.BodyText = MsgBody
%>
<%
'This Code MUST go in between the header tags
'Send mail

'The from name and from e-mail address

   'Enter name you want the mail to be listed as sent from      
      Mailer.FromName = "literature Form"
   'Enter email address you want the mail to be from
      Mailer.FromAddress = "forms@literature.com"

'Add the delivery name and address here
      Mailer.AddBCC "copy@email.com"
      Mailer.AddRecipient "Webmaster", "webmaster@email.com"
          
      
     
      Mailer.Subject = " Lighting Literature Request2"
   
      Mailer.BodyText = "Account #: 1234"  
      Mailer.BodyText = " "
      Mailer.BodyText = "Name: "  + Request.Form("uName")
      Mailer.BodyText = "Address: "  + Request.Form("Address")
      Mailer.BodyText = "City: "  + Request.Form("City")
      Mailer.BodyText = "Province: "  + Request.Form("Prov")
      Mailer.BodyText = "Postal Code: "  + Request.Form("pCode")
      Mailer.BodyText = " "
      Mailer.BodyText = "Phone: " + Request.Form("Phone")
      Mailer.BodyText = "Fax: " + Request.Form("Fax")
      Mailer.BodyText = "Email: " + Request.Form("Email")
      Mailer.BodyText = " "
      Mailer.BodyText = "Remarks: " + Request.Form("remarks")
      Mailer.BodyText = " "
      Mailer.BodyText = " "
      Mailer.BodyText = MsgBody
      
            
      if Mailer.SendMail then
     'Can put page html here or below
        Response.Write " "
      else
     'If you want the error displayed to the user else just use Response.Write " " like above
        Response.Write "Mail send failure. Error was/is " & Mailer.Response
      end if      
      
      'redirect to a sucessful submit...
      Response.Redirect("literature.asp")
%>
0
 
frrfCommented:
can you try this

<%
'send first mail
Set Mailer = Server.CreateObject("SMTPsvg.Mailer")
 
     Mailer.RemoteHost = "12.111.345.576"
...................
...................
     Mailer.Subject = "Subject 1"
...................  
     Mailer.Send
set Mailer=nothing
%>

<%
'send second mail
Set Mailer = Server.CreateObject("SMTPsvg.Mailer")
 
     Mailer.RemoteHost = "12.111.345.576"
...................
...................
     Mailer.Subject = "Subject 2"
...................  
     Mailer.Send
set Mailer=nothing
%>
0
 
allbird79Author Commented:
Thank you frrf.
What you have given me does create two different email...well, actually 3! Somehow, it send the second email twice. I believe it has something to do with the last bit of code I have:

if Mailer.SendMail then
     'Can put page html here or below
       Response.Write " "
     else
     'If you want the error displayed to the user else just use Response.Write " " like above
       Response.Write "Mail send failure. Error was/is " & Mailer.Response
     end if    
     
    Mailer.SendMail
    set Mailer=nothing

     'redirect to a sucessful submit...
     Response.Redirect("literature.asp")

Can you give me a suggestion as to how I could fix this? I moved the set Mailer=nothing above the other code and I got a different error:

Microsoft VBScript runtime error '800a01a8'
Object required

The emails do get through and there are only two this way but I don't know how to fix this error.

Thanks.


0
 
allbird79Author Commented:
I worked it out by removing the last
    Mailer.SendMail
    set Mailer=nothing

Thanks for all your help.
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!

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now