I have a form.asp page that 'POST's data into a result.asp. After the result.asp page loads, I want to send an exact copy of that page in an email. Suggestions?
Well that would most likely involve putting the page into a string then mailing it.
But I would suggest sending a link of the results, and save the results in a database you could easily make one design for your results, and access it via id number
Do you want to be able to send a copy of the results by email when the user clicks something or automatically?
if it is automatically then what you need to do is nip to do is get your self a copy of formmail.asp and add your domain name in the top section of the code as this is the only line you need to change and then save this file anywhere you want on your site and you should renmae the formmail.asp, then all you need to do is add 5 hidden fields to your form to hold the email address the email is to sent too. one for the subject of the email, one for the redirect which is to be the results page and one for the order of the the way you want the fileds in the email to look. then you simply teel your orignal form to post to the formmail.asp and this page will send the email and then show the results page.
logical progression: form > formmail > results
let me know and i can give you the code for the formmails.asp page so that you simply hace to copy it and make a new file and i can give you a example form in code so that you can see the principle.
if you want the results to be sent if the user clicks a button on the results page it is a very similar proccess.
logical progression: form > results > formmail > confirmation of emial > results
for this doing it this way you simply put a form on the results page with all the hidden fields for the form and the ones formmail needs to send the email and then when they click the button and submit the form the form will send the page to the formmail and sen the email and the redirect caneither take them to a tconfirmation of results being sent page or simply straight back to the results page it is your choice i allway think a simple thank you page is nice.
here is the code for formmail.asp so copy this and save it as a page.
########## THERE ARE NO HTML OR BODY TAGS OK ###########
<%@ LANGUAGE="VBScript" %>
<%
'Change the referers line only to reflect your domain name
'- End required customization section. -------------------------------------
fromAddr = Request("email"
Response.Buffer = true
errorMsgs = Array()
'Check for form data.
if Request.ServerVariables("Content_Length" = 0 then
call AddErrorMsg("No form data submitted."
end if
'Check if referer is allowed.
validReferer = false
referer = GetHost(Request.ServerVariables("HTTP_REFERER")
for each host in referers
if host = referer then
validReferer = true
end if
next
if not validReferer then
if referer = "" then
call AddErrorMsg("No referer."
else
call AddErrorMsg("Invalid referer: '" & referer & "'."
end if
end if
'Check for the recipients field.
if Request.Form("_recipients" = "" then
call AddErrorMsg("Missing email recipient."
end if
'Check all recipient email addresses.
recipients = Split(Request.Form("_recipients", ","
for each name in recipients
name = Trim(name)
if not IsValidEmail(name) then
call AddErrorMsg("Invalid email address in recipient list: " & name & "."
end if
next
recipients = Join(recipients, ","
'Get replyTo email address from specified field if given and check it.
name = Trim(Request.Form("_replyToField")
if name <> "" then
replyTo = Request.Form(name)
else
replyTo = Request.Form("_replyTo"
end if
if replyTo <> "" then
if not IsValidEmail(replyTo) then
call AddErrorMsg("Invalid email address in reply-to field: " & replyTo & "."
end if
end if
'Get subject text.
subject = Request.Form("_subject"
'If required fields are specified, check for them.
if Request.Form("_requiredFields" <> "" then
required = Split(Request.Form("_requiredFields", ","
for each name in required
name = Trim(name)
if Left(name, 1) <> "_" and Request.Form(name) = "" then
call AddErrorMsg("Missing value for " & name)
end if
next
end if
'If a field order was given, use it. Otherwise use the order the fields were
'received in.
str = ""
if Request.Form("_fieldOrder" <> "" then
fieldOrder = Split(Request.Form("_fieldOrder", ","
for each name in fieldOrder
if str <> "" then
str = str & ","
end if
str = str & Trim(name)
next
fieldOrder = Split(str, ","
else
fieldOrder = FormFieldList()
end if
'If there were no errors, build the email note and send it.
if UBound(errorMsgs) < 0 then
'Build table of form fields and values.
body = "<table border=0 cellpadding=2 cellspacing=0>" & vbCrLf
for each name in fieldOrder
body = body _
& "<tr valign=top>" _
& "<td><b>" _
& name _
& ": </b></font></td>" _
& "<td>" _
& Request.Form(name) _
& "</td>" _
& "</tr>" & vbCrLf
next
body = body & "</table>" & vbCrLf
'Add a table with any environmental variables.
if Request.Form("_envars" <> "" then
body = body _
& "<p>" _
& "<table border=0 cellpadding=2 cellspacing=0>" & vbCrLf
envars = Split(Request.Form("_envars", ","
for each name in envars
name = Trim(name)
body = body _
& "<tr valign=top>" _
& "<td><b>" _
& name _
& ": </b></td>" _
& "<td>" _
& Request.ServerVariables(name) _
& "</td>" _
& "</tr>" & vbCrLf
next
body = body & "</table>" & vbCrLf
end if
'Send it.
str = SendMail()
if str <> "" then
AddErrorMsg(str)
end if
'Redirect if a URL was given.
if Request.Form("_redirect" <> "" then
Response.Redirect(Request.Form("_redirect")
end if
<% if UBound(errorMsgs) >= 0 then %>
<p class="error">Form could not be processed due to the following errors:</p>
<ul>
<% for each msg in errorMsgs %>
<li class="error"><% = msg %>
<% next %>
</ul>
</td></tr></table>
<% else %>
<table cellpadding=0 cellspacing=0 width=450>
<tr style="background-color:#c0c0c0;">
<th colspan=2 valign=bottom>
Thank you, the following information has been sent:
</th>
</tr>
<% for each name in fieldOrder %>
<tr style="background-color:#ffffff;" valign=top>
<td><b><% = name %></b> </td>
<td><% = Request.Form(name) %> </td>
</tr>
<% next %>
</table>
<% end if %>
</body>
</html>
<% '---------------------------------------------------------------------------
' Subroutines and functions.
'---------------------------------------------------------------------------
then
s = Mid(url, 9)
end if
i = InStr(s, "/"
if i > 1 then
s = Mid(s, 1, i - 1)
end if
getHost = s
end function
function IsValidEmail(email)
dim names, name, i, c
'Check for valid syntax in an email address.
IsValidEmail = true
names = Split(email, "@"
if UBound(names) <> 1 then
IsValidEmail = false
exit function
end if
for each name in names
if Len(name) <= 0 then
IsValidEmail = false
exit function
end if
for i = 1 to Len(name)
c = Lcase(Mid(name, i, 1))
if InStr("abcdefghijklmnopqrstuvwxyz_-.", c) <= 0 and not IsNumeric(c) then
IsValidEmail = false
exit function
end if
next
if Left(name, 1) = "." or Right(name, 1) = "." then
IsValidEmail = false
exit function
end if
next
if InStr(names(1), "." <= 0 then
IsValidEmail = false
exit function
end if
i = Len(names(1)) - InStrRev(names(1), "."
if i <> 2 and i <> 3 then
IsValidEmail = false
exit function
end if
if InStr(email, ".." > 0 then
IsValidEmail = false
end if
end function
function FormFieldList()
dim str, i, name
'Build an array of form field names ordered as they were received.
str = ""
for i = 1 to Request.Form.Count
for each name in Request.Form
if Left(name, 1) <> "_" and Request.Form(name) is Request.Form(i) then
if str <> "" then
str = str & ","
end if
str = str & name
exit for
end if
next
next
FormFieldList = Split(str, ","
end function
function SendMail()
dim mailObj
dim addrList
'Send email based on mail component. Uses global variables for parameters
'because there are so many.
SendMail = ""
'Send email
set mailObj = Server.CreateObject("CDONTS.NewMail"
mailObj.BodyFormat = 0
mailObj.MailFormat = 0
mailObj.From = fromAddr
mailObj.To = recipients
mailObj.Subject = subject
mailObj.Body = body
mailObj.Send
set mailobj=nothing
end function %>
######### END OF CODE ######################
here is an example of a basic form that you can customise to your needs.
########### EXAMPLE OF FORM TO SEND EMAIL ###############
<! Example Script for use with Formmail.ASP>
<html><center>
<! The forms action must match the name of the formail script>
<! If you rename the formmail script you must change this here >
<! This is the From: address>
From:
<input type = text name="email" value="websiteform@yourdomainname.com"><br>
<! Example fields which will be sent in the email>
Name: <input type = text name="name" ><br>
Your email: <input type = text name="email" ><br>
Phone number: <input type = text name="phone_number" ><br>
Comments: <input type = text name="comments" ><br>
<! Display the submit button>
<input type = submit value ="Send Message">
</form>
</center></html>
########### END OF CODE #######################
this is a simply comments page. if you have a smtp server on your machine it will send emails if not you will have to upload it onto a web server to send the emails but it is som simple to use and their a because it collects the fields from your form it doesn't matter how many you have or how give it will send them in the order you put in the form. this means that you can have lots of different forms on your site using one formmail.asp page.
I thought of both of these options (refering to Jason's reply) and I was trying to avoid the string (unless given a simple way to make a string out of a whole page) and the database won't work because its an intranet and the email is going external.
I am converting a ton of forms to an online intranet and most of them they simply want emailed here or there.
Something I thought of, but can't figure out, is to take the results.asp page after it loads from the server and save it, then attach it to my email. (Basically emulating the File > Save As, but automatically and saving to the server).
<%=reqeust.form("variable"%>
if it's copy pasted straight out of your page there's a typo in there.
has to be <%reqUEst.form("variable" %>
I've found code that works like this; but the "POST" information is written out after the 'xml.send' manually.
If the user fills out the form information, how can I have the 'xml.send' use that form for the 'POST' ?
hi dustin -
we're trying to do exactly this -
did you manage to get it working? -
we can use the object to open another page - yahoo for example - immediately after our results.asp page and can use cdosys to scrape yahoo and send via email, but when we try to scrape off a page from our domain the browser just hangs, then gives a dns error....
we're thinking that maybe you can't use the object to suck out a page from the same server/domain let alone the exact same one....
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.