Solved

form result email in html format

Posted on 2000-03-07
12
234 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This tutorial will give you a fast look what you can do with WhizBase. I expect you already know how to work with HTML at least, and that you understand the basics of the internet and how the internet works. WhizBase is a server-s…
This tutorial will discuss the log-in process using WhizBase. In this article I assume you already know HTML. I will write the code using WhizBase Server Pages, so you need to know some basics in WBSP (you might look at some of my other articles abo…
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

830 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