allbird79
asked on
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("SMTPs vg.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("literat ure.asp")
%>
Thanks in advance for any help.
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("SMTPs
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("literat
%>
Thanks in advance for any help.
ASKER
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.
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.
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.
ASKER
Do you just set it up to write from:
<%
'Send mail
Set Mailer = Server.CreateObject("SMTPs vg.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("literat ure.asp")
%>
and repeat the same tag with the extra line added? Or create a variable as you suggested but still write the tag twice?
<%
'Send mail
Set Mailer = Server.CreateObject("SMTPs
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("literat
%>
and repeat the same tag with the extra line added? Or create a variable as you suggested but still write the tag twice?
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.
ASKER
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("SMTPs vg.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("literat ure.asp")
%>
Here is the code I am trying:
<%
'Send mail
Set Mailer = Server.CreateObject("SMTPs
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("literat
%>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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("literat ure.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.
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("literat
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.
ASKER
I worked it out by removing the last
Mailer.SendMail
set Mailer=nothing
Thanks for all your help.
Mailer.SendMail
set Mailer=nothing
Thanks for all your help.
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