Solved

form result email in html format

Posted on 2000-03-07
12
228 Views
Last Modified: 2013-12-25
Does anyone know of a script that will process the results of an html form and that would send an email that would be in html format and look exactly like the html form, but with the fields filled in as they were when the form was submitted? In that way, the recipient would be able to print out a completed form from the user. Any other ideas would be welcome as well.
0
Comment
Question by:bogie
  • 5
  • 3
  • 3
  • +1
12 Comments
 
LVL 16

Expert Comment

by:maneshr
ID: 2594036
is pretty easy to do in PERL. However you must remember that not ALL email clients support HTML tags in their Email. so not everybody can get the HTML like look-and-feel. An alternate would be a neatly formatted text output that would be supported by all the Email clients including Non-GUI ones!!
0
 

Author Comment

by:bogie
ID: 2594452
Thank you for your reply. The receipient would only be a single user,and they would like the form fields heading and all... but in any case, do you have a Perl script that can handle this? I can handle html very well, but Perl is not my forte. Would I be able to add/change the fields myself by going into the script and simply adding/changing small snippets?

You can see the form here: http://www.marblelife.com/salesrpt.htm

Thanks, Herb
0
 
LVL 3

Expert Comment

by:monas
ID: 2597477
1. make copy of salesrpt.htm file - salessend.htm
2. edit salessend.htm and in every <input > insert text value="%%fieldName%%"
3. create script

#!/usr/bin/perl

use CGI;
$q = new CGI;
open(F, 'salessend.htm");
$sales = join('', <F>);
close(F);

@fields = qw(RESMarbleRest RESGraniteRest all other field names with correct Cappitals );

foreach $f(@fields){
  $pat = '%%'.$f.'%%';
  $sales =~ s/$pat/$q->param($f)/g;
}

open(M, '|/bin/mail -s Subject person@to.send.to');
print M $sales;
close(M);

print $q->header();
print "Report sent\n";

exit 0;

Good Look!
0
 
LVL 3

Expert Comment

by:monas
ID: 2597488
oops, line

$sales =~ s/$pat/$q->param($f)/g;

should read

$sales =~ s/$pat/$q->param($f)/ge;

0
 
LVL 3

Expert Comment

by:monas
ID: 2597503
yet another typo
open(F, 'salessend.htm");
should be
open(F, 'salessend.htm');
0
 
LVL 16

Expert Comment

by:maneshr
ID: 2597510
try this.

you dont need to modify anything in salesrpt.htm.
it is the starting point for the CGI i am have coded below.

Also you must copy this template file to any location and put the full path to the file in the CGI script.

Basically this is how it works. i have created a mirror hmtl file that acts as a template to salesrpt.htm.

it has all the HTML tags and so on. The only difference is that instead of the input tags i have put the actual variable names in CAPS with a ## before and after the variable. Eg ##RETURN_LINK_URL##, ##WEEK_OF## etc..

NOTE: the variable names MUST be the same as in salesrpt.htm and in all caps.

Now when the user submits the form, the CGI script goes thru the template and just replaces the variables with their actual value!!

this program is flexible so that tomorrow if you were to add/remove new variable(s) to salesrpt.htm, you need to ONLY add/remove the variable in the salesrpt_template.html file!! your CGI can continue to remain unchanged!!

However do remember the NOTE above.


Installation: copy the formmail.pl to your cgi-bin directory, give it proper permissions & remember to changed the full path of the template file
($template_file="/www/sbarney/docs/manesh/salesrpt_template.html";)
to your location.


==========================salesrpt_template.html
<html>
<BODY>

<center><font size="4" color="#000080"><u>##SUBJECT##</u></font></b></CENTER><P
>

<table border=0 cellpadding=4>

<TD><font size="2">For the Week of: </font></TD>
<TD>##WEEK_OF##</TD>
<TD></TD>
<TD></TD>
<TR>

<TD><font size="2">Franchise Name: </font></TD>
<TD>##FRANCHISENAME##</TD>
<TD><font size="2">Franchise Acct: </font></TD>
<TD>##FRANCHISEACCT##</TD>
<TR>

<TD><font size="2">Email Address: </font></TD>
<TD>##EMAIL##</TD>
<TD></TD>
<TD></TD>
<TR>
<TD><font size="2">Total Sales: </font></TD>
<TD>##TOTALSALES##</TD>
<TD></TD>
<TD></TD>
<TR>

<TD><font size="2">Residential:</font></TD>
<TD>##RESIDENTIALSALES##</TD>
<TD></TD>
<TD></TD>
<TR>

<TD><font size="2">Commercial:</font></TD>
<TD>##COMMERCIALSALES##</TD>
<TD></TD>
<TD></TD>
</TABLE>

<b>
<p ALIGN="CENTER"><font size="2">Weekly Residential Sales Analysis</font></p>
</b>
<div align="center">
  <center>
  <table BORDER="1" CELLSPACING="1" CELLPADDING="0" width="100%">
    <tr>
      <td bgcolor="#FFFFFF" align="center">
        <p><font size="2">Marble Restoration</font></td>
      <td bgcolor="#FFFFFF" align="center">
        <p><font size="2">Granite Restoration</font></td>
      <td bgcolor="#FFFFFF" align="center">
        <p><font size="2">Terrazzo Restoration</font></td>
      <td bgcolor="#FFFFFF" align="center">
        <p><font size="2">Ceramic Tile</font></td>
      <td bgcolor="#FFFFFF" align="center">
        <p><font size="2">Vanities &amp; Tables Restored</font></td>
      <td bgcolor="#FFFFFF" align="center">
        <p><font size="2">Clean &amp; Polish</font></td>
    </tr>
    <tr>
      <td align="center">
        <p>##RESMARBLEREST##</p>
      </td>
      <td align="center">##RESGRANITEREST##</td>
      <td align="center">
        <p>##RESTERRAZZOREST##</p>
      </td>
      <td align="center">
        <p>##RESCERAMICTILEREST##</p>
      </td>
      <td align="center">
        <p>##RESVANITIESTABLEREST##</p>
      </td>
      <td align="center">
        <p>##RESCLEANPOLISH##</p>
      </td>
    </tr>
    <tr>
      <td align="center" bgcolor="#FFFFFF">
        <p><font size="2">Stone Sealed Interlok</font></td>
      <td align="center" bgcolor="#FFFFFF">
        <p><font size="2">Stone Sealed Impregnator</font></td>
      <td align="center" bgcolor="#FFFFFF">
        <p><font size="2">Maintenance Acct.^Òs</font></td>
      <td align="center" bgcolor="#FFFFFF">
        <p><font size="2">InterCare Sales</font></td>
      <td align="center" bgcolor="#FFFFFF">
        <p><font size="2">Step 1 &amp; Step 2 Sales</font></td>
      <td align="center" bgcolor="#FFFFFF">
        <p><font size="2">Misc.</font></td>
    </tr>
    <tr>
      <td align="center">
        <p>##RESSTONESEALEDINTERLOK##</p>
      </td>
      <td align="center">
        <p>##RESSTONESEALEDIMPREGNATOR##</p>
      </td>
      <td align="center">
       <p>##RESMAINTACCTS##</p>
      </td>
      <td align="center">
        <p>##RESINTERCARESALES##</p>
      </td>
      <td align="center">
        <p>##RESSTEP1AND2SALES##</p>
      </td>
      <td align="center">
        <p>##RESMISCSALES##</p>
      </td>
    </tr>
  </table>
  </center>
</div>
<p align="center"><b><font size="2">Weekly Commercial Sales Analysis</font></p>
</b>
<div align="center">
  <center>
  <table BORDER="1" CELLSPACING="1" CELLPADDING="0" width="100%">
    <tr>
      <td align="center" bgcolor="#FFFFFF">
        <p><font size="2">Marble Restoration</font></td>
      <td align="center" bgcolor="#FFFFFF">
        <p><font size="2">Granite Restoration</font></td>
      <td align="center" bgcolor="#FFFFFF">
      <p><font size="2">Terrazzo Restoration</font></td>
      <td align="center" bgcolor="#FFFFFF">
        <p><font size="2">Ceramic Tile</font></td>
      <td align="center" bgcolor="#FFFFFF">
        <p><font size="2">Vanities &amp; Tables Restored</font></td>
      <td align="center" bgcolor="#FFFFFF">
        <p><font size="2">Clean &amp; Polish</font></td>
    </tr>
    <tr>
      <td align="center">
        <p>##COMMARBLEREST##</p>
      </td>
      <td align="center">
        <p>##COMGRANITEREST##</p>
      </td>
      <td align="center">
        <p>##COMTERRAZZOREST##</p>
      </td>
      <td align="center">
        <p>##COMCERAMICTILEREST##</p>
      </td>
      <td align="center">
        <p>##COMVANITIESTABLEREST##</p>
      </td>
      <td align="center">
        <p>##COMCLEANPOLISH##</p>
     </td>
    </tr>
    <tr>
      <td align="center" bgcolor="#FFFFFF">
        <p><font size="2">Stone Sealed Interlok</font></td>
      <td align="center" bgcolor="#FFFFFF">
        <p><font size="2">Stone Sealed Impregnator</font></td>
      <td align="center" bgcolor="#FFFFFF">
        <p><font size="2">Maintenance Acct.^Òs</font></td>
      <td align="center" bgcolor="#FFFFFF">
        <p><font size="2">InterCare Sales</font></td>
      <td align="center" bgcolor="#FFFFFF">
        <p><font size="2">Step 1 &amp; Step 2 Sales</font></td>
      <td align="center" bgcolor="#FFFFFF">
        <p><font size="2">Misc.</font></td>
    </tr>
    <tr>
      <td align="center">
        <p>##COMSTONESEALEDINTERLOK##</p>
      </td>
      <td align="center">
        <p>##COMSTONESEALEDIMPREGNATOR##</p>
      </td>
      <td align="center">
        <p>##COMMAINTACCTS##</p>
      </td>
     <td align="center">
        <p>##COMINTERCARESALES##</p>
      </td>
      <td align="center">
        <p>##COMSTEP1AND2SALES##</p>
      </td>
      <td align="center">
        <p>##COMMISCSALES##</p>
      </td>
    </tr>
  </table>
  </center>
</div><br>
<div align="center">
  <center>
  <table border="0" cellpadding="0" cellspacing="0" width="100%">
    <tr>
      <td align="center"><font size="2">Column 1</font></td>
      <td align="center"><font size="2">+ Column 2</font></td>
      <td align="center"><font size="2">+ Column 3</font></td>
      <td align="center"><font size="2">+ Column 4</font></td>
      <td align="center"><font size="2">= Column 5</font></td>
    </tr>
  </table>
  </center>
</div>
<div align="center">
  <center>
  <table BORDER="1" CELLSPACING="1" CELLPADDING="0" width="100%">
    <tr>
      <td align="center" bgcolor="#FFFFFF">
        <p><font size="2">Previous Acct^Òs Receivable</font></td>
      <td align="center" bgcolor="#FFFFFF">
        <p><font size="2">Weekly Sales</font></td>
      <td align="center" bgcolor="#FFFFFF">
        <p><font size="2">Weekly Sales Collected</font></td>
      <td align="center" bgcolor="#FFFFFF">
        <p><font size="2">Acct^Òs Receivable Collected</font></td>
      <td align="center" bgcolor="#FFFFFF">
        <p><font size="2">Current Acct.^Òs Receivable</font></td>
    </tr>
    <tr>
      <td align="center">
        <p>##PREVAR##</p>
      </td>
      <td align="center">
        <p>##WEEKLYSALES##</p>
      </td>
      <td align="center">
        <p>##WEELKYSALESCOLLECTED##</p>
      </td>
      <td align="center">
       <p>##ARCOLLECTED##</p>
      </td>
      <td align="center">
        <p>##CURRENTAR##</p>
      </td>
    </tr>
  </table>
  </center>
</div>

<P>
<TABLE border=0 cellpadding=2>
<TD><font size="2">6% Royalty Fee of Moneys Collected:</font></TD>
<TD>##SIXPERCENT_AMT##</TD>
<TD><font size="2">CK#</font></TD>
<TD>##ROYALTYFEE##</TD>
<TR>

<TD><font size="2">2% Ad Fund of Moneys Collected:</TD>
<TD>##TWOPERCENT_AMT##</font></TD>
<TD><font size="2">CK#</font></TD>
<TD>##ADFUND##</TD>
<TR>

<TD><font size="2">Total Due MARBLELIFE, Inc: </font></TD>
<TD>##TOTALDUE##</TD>
<TD></TD>
<TD></TD>
<TR>

<TD><font size="2">Total of Weekly Sales Collected and <br>Accounts Receivable
Collected (Column 3 + Column 4): </font></TD>
<TD>##TOTALWEEKLYSALESANDARCOLLECTED##</TD>
<TD></TD>
<TD></TD>
</TABLE>

<p><font size="2">Franchise Signature:</font>_________________________

<P><A HREF="##RETURN_LINK_URL##">##RETURN_LINK_TITLE##</A>

<CENTER><font size="2">Mail Checks and Copies of all Sequentially Numbered Invo
ices to:<br>MARBLELIFE, INC. 805 W. N. Carrier Pkwy, Suite #220, Grand Prairie,
 Texas 75050</font></center>

</body>
</html>
========================formmail.pl
#!/usr/local/bin/perl

use CGI;

$query=new CGI; ##  Create a CGI object to read the values entered in the HTML
form.

##  Full path to the template file.
$template_file="/www/sbarney/docs/manesh/salesrpt_template.html";

print "Content-type: text/html\n\n";
if ($query->param){ ##  This script has been called via a Submit button

  ##  Read every parameter entered in the form...
  ##  ...& store it in an associative array after...
  ##  ...converting the variable to UPPER CASE.
  ##  E.g. if your form variable is called TotalSales, the key will be TOTALSAL
ES and the value against the key will be whatever was entered in the HTML form!
!
  foreach($query->param){
    $key=uc $_;
    $data{$key}=$query->param($_);
  }

  ##  NOTE: DOS files have ^Z as the end-of-file indicator
  $/="^Z";  ##  Make the end-of-line seperator as ^Z
  open(TEMPL,$template_file) || die $!;
 $entire_file=<TEMPL>; ##  Read the ENTIRE file into a PERL variable
  close(TEMPL);
  $/="\n";  ##  Restore the end-of-line seperator to carriage return

  ##  Now, search in the read file for every key in the hash.
  foreach $sp_var (sort keys %data){
    ##  If a match is found, replace the key with its correspoding value.
    $entire_file=~ s/##$sp_var##/$data{$sp_var}/g if $entire_file=~ /##$sp_var#
#/;
  }

  ##  Print the final file. If required, the same can be ...
  ##  ...sent out via an E-mail!!
  print $entire_file,"\n";
}else{  ##  We dont allow the user to directly call this CGI script
  print "<B>You are not allowed here!!</B><br>\n";
}

0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 16

Expert Comment

by:maneshr
ID: 2608858
have you been able to test the code that i gave you??

if so, did it work properly??
0
 

Author Comment

by:bogie
ID: 2608920
Been out of town all week. Just returned, so I should be able to give it a good going over in the next day or so...but it looks very complete, thanks!
Herb
0
 
LVL 16

Expert Comment

by:maneshr
ID: 2641847
any success so far??

Rgds
0
 

Author Comment

by:bogie
ID: 2644608
I am sorry I have been delinquent in working on your answer...we had a family emergency and I have not been able to work on it. Please rest assured that if your answer works, I will let you know and also give a bonus for your patience!
Thanks, Herb
0
 
LVL 16

Expert Comment

by:maneshr
ID: 2645020
i'm sorry. i hope everything is Ok with your family.

please take you time to review the code.

Regards
0
 
LVL 1

Accepted Solution

by:
mfragoso earned 100 total points
ID: 2838542
Here is a script that you can use, and additionaly could format the mail received, as your form, letter or as you wish.

You don't mention your OS, but this solutions works under Windows NT, 98, 95

http://www.lss.com.au/lss/windows/mf/mf_ins.htm
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now