Web page, attach the form to the email

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • yimma216
    New Member
    • Jul 2008
    • 44

    Web page, attach the form to the email

    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?

    Code:
    <form>
    ....etc
    
    <td><input type="button" value="Print this page " onclick="window.print();return false;" /></td>
    <td>&nbsp;<input type="button" value="Email" onclick="location.href='mailto:'" /></td>
    
    </form>
  • RamananKalirajan
    Contributor
    • Mar 2008
    • 608

    #2
    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

    Comment

    • acoder
      Recognized Expert MVP
      • Nov 2006
      • 16032

      #3
      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.

      Comment

      • yimma216
        New Member
        • Jul 2008
        • 44

        #4
        Originally posted by RamananKaliraja n
        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?

        Comment

        • RamananKalirajan
          Contributor
          • Mar 2008
          • 608

          #5
          Originally posted by yimma216
          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="yourcomm ent" 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.getEle mentById('thisF orm');
          myForm.action=" MAILTO:****@exc elacom.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
          Last edited by acoder; Aug 18 '08, 09:27 AM. Reason: munged email

          Comment

          • yimma216
            New Member
            • Jul 2008
            • 44

            #6
            Thanks Ramanan, I tried your codes. But i have further questions.

            Code:
            <%
            Set conn = Server.CreateObject("ADODB.Connection")
            Set rs = Server.CreateObject("ADODB.Recordset")
            conn.Open  "Driver={SQL Native Client};.............etc
            
            sql = "select * from returns where gra_id=" & request("gra_id")
            
            rs.open sql, conn
            		
            %>
            <html>
            <body>
            
            <form id="thisForm" action="print_out.asp" method="post" enctype="text/plain">
            
            <hr>
            <table width="100%">
            
            <tr>
            <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>
            </tr>
            	<tr>
            		<td>&nbsp;</td>
            	</tr>
            <tr>
            <td width="20%"><b>Enter Date:</b></td><td width="20%"><b><%=entered_date%></b></td>
            </tr>
            <tr>
            <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>
            </tr>
            </table>
            .........................etc
            	<hr />	
            
            <table>
            ..........................etc
            	<tr>
            		<td>&nbsp;</td><td><input type="button" value="Print this page " onclick="window.print();return false;" /></td>
            		<td>&nbsp;<input type="button" value="Email" onclick="mailForm()" /></td>
            	</tr>
            </table>
            </form>
            </body>
            </html>
            <%
            	rs.close
            	conn.close
            	
            	%>
            
            </body>
            </html>
            
            <SCRIPT LANGUAGE="JAVASCRIPT" TYPE="TEXT/JAVASCRIPT">
            <!--
            function mailForm()
               {
            	 // alert("ubside Mail")
            	 var myForm = document.getElementById('thisForm');
            	 myForm.action="MAILTO:****@cuthbertstewart.co.nz";
            	 myForm.submit();
               }
            
            //-->
            </script>

            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?
            Last edited by acoder; Aug 19 '08, 10:59 AM. Reason: munged email

            Comment

            • RamananKalirajan
              Contributor
              • Mar 2008
              • 608

              #7
              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
              Last edited by acoder; Aug 19 '08, 10:58 AM. Reason: Removed unnecessary quote

              Comment

              Working...