By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
460,034 Members | 1,028 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 460,034 IT Pros & Developers. It's quick & easy.

Web page, attach the form to the email

P: 44
Hi there.

I am looking for a way to generate a report from a web form and attached it to an email so that I could send it.

The form is retrieving data from a Microsoft SQL server and display them in a print out ASP page.

There is a print button and an email button in javascript in the form. However, nothing is attached to the email at this point.

Could any one herl?

Expand|Select|Wrap|Line Numbers
  1. <form>
  2. ....etc
  3.  
  4. <td><input type="button" value="Print this page " onclick="window.print();return false;" /></td>
  5. <td>&nbsp;<input type="button" value="Email" onclick="location.href='mailto:'" /></td>
  6.  
  7. </form>
  8.  
Aug 13 '08 #1
Share this Question
Share on Google+
6 Replies


RamananKalirajan
100+
P: 607
Hi, one thing u can do. Just inside the form, have unique id for every element and onSubmit invoke a function that will retrieve all the form values and pass it as a string to the mail. Just try out this if needed help post it. I will try to help u out.

Regards
Ramanan Kalirajan
Aug 13 '08 #2

acoder
Expert Mod 15k+
P: 16,027
The best way to send email is to use server-side.

However, you can do without though it will be unreliable and depend on the user having an email client set up and they can send emails. This method just requires you to set the action of the form to a mailto: address.
Aug 13 '08 #3

P: 44
Hi, one thing u can do. Just inside the form, have unique id for every element and onSubmit invoke a function that will retrieve all the form values and pass it as a string to the mail. Just try out this if needed help post it. I will try to help u out.

Regards
Ramanan Kalirajan

HI Ramanan,
Would you please give me some reference or example of how you do it?
Aug 17 '08 #4

RamananKalirajan
100+
P: 607
HI Ramanan,
Would you please give me some reference or example of how you do it?
This is an Example. But here all the form variable will be submitted.

[HTML]<html>
<body>
<h3>This form sends an e-mail to the user you specified in the Action</h3>
<form id="thisForm" method="post" enctype="text/plain">
Name:<br />
<input type="text" name="name"
value="yourname" size="20" />
<br />
Mail:<br />
<input type="text" name="mail"
value="yourmail" size="20" />
<br />
Comment:<br />
<input type="text" name="comment"
value="yourcomment" size="40" />
<br /><br />
<input type="Button" value="Mail" onclick="mailMe()"/>
<input type="reset" value="Reset" />
</form>
</body>
</html>
<script type="text/javascript">
function mailMe()
{
// alert("Inside Mail");
var myForm = document.getElementById('thisForm');
myForm.action="MAILTO:****@excelacom.in";
myForm.submit();
}
</script>[/HTML]

You can achieve this in another way also. Have two forms within the same page. In one form you put your all input elements. In the other form just have an input hidden field, when the form is subitted collect all the values in the form1 set that value to the hidden element in the 2md form and submit using mail. Further doubts please post it back

Regards
Ramanan Kalirajan
Aug 18 '08 #5

P: 44
Thanks Ramanan, I tried your codes. But i have further questions.

Expand|Select|Wrap|Line Numbers
  1. <%
  2. Set conn = Server.CreateObject("ADODB.Connection")
  3. Set rs = Server.CreateObject("ADODB.Recordset")
  4. conn.Open  "Driver={SQL Native Client};.............etc
  5.  
  6. sql = "select * from returns where gra_id=" & request("gra_id")
  7.  
  8. rs.open sql, conn
  9.  
  10. %>
  11. <html>
  12. <body>
  13.  
  14. <form id="thisForm" action="print_out.asp" method="post" enctype="text/plain">
  15.  
  16. <hr>
  17. <table width="100%">
  18.  
  19. <tr>
  20. <td width="20%"><font size=4.5><b>GRA ID:</b></font></td><td  width="20%"><font size=4.5><b><%=rs("gra_id")%></b></font></td><td width="20%"><font size=4.5><b>No. of Packages</b></font></td><td width="20%"><%=rs("package")%> </td>
  21. </tr>
  22.     <tr>
  23.         <td>&nbsp;</td>
  24.     </tr>
  25. <tr>
  26. <td width="20%"><b>Enter Date:</b></td><td width="20%"><b><%=entered_date%></b></td>
  27. </tr>
  28. <tr>
  29. <td width="20%"><b>Customer Account:</b></td><td width="20%"><%=rs("account")%></td><td width="20%"><b>CSL Invoice No:</b></td><td width="20%"><%=rs("invoice")%></td> <td width="20%"></td>
  30. </tr>
  31. </table>
  32. .........................etc
  33.     <hr />    
  34.  
  35. <table>
  36. ..........................etc
  37.     <tr>
  38.         <td>&nbsp;</td><td><input type="button" value="Print this page " onclick="window.print();return false;" /></td>
  39.         <td>&nbsp;<input type="button" value="Email" onclick="mailForm()" /></td>
  40.     </tr>
  41. </table>
  42. </form>
  43. </body>
  44. </html>
  45. <%
  46.     rs.close
  47.     conn.close
  48.  
  49.     %>
  50.  
  51. </body>
  52. </html>
  53.  
  54. <SCRIPT LANGUAGE="JAVASCRIPT" TYPE="TEXT/JAVASCRIPT">
  55. <!--
  56. function mailForm()
  57.    {
  58.      // alert("ubside Mail")
  59.      var myForm = document.getElementById('thisForm');
  60.      myForm.action="MAILTO:****@cuthbertstewart.co.nz";
  61.      myForm.submit();
  62.    }
  63.  
  64. //-->
  65. </script>
  66.  

My page is retrieving data (VBscript, ADO) through the database so without any textfield available. Is like a report I want to email to people.

I tried the code, however is not attaching with the email if it is not using the input type.

I can print out the form as PDF. Am I able to email the form as an attachment instead?
Aug 18 '08 #6

RamananKalirajan
100+
P: 607
Still u can achieve ur requirement without attaching the PDF. In HTML DOM you are having an element input type="hidden" this variable can hold the value which u retrieve from the DB. pass this value to the mail. Try this out. Still any doubts post it back i will try to help u out.

Regards
Ramanan Kalirajan
Aug 19 '08 #7

Post your reply

Sign in to post your reply or Sign up for a free account.