Solved

form result email in html format

Posted on 2000-03-07
12
236 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

 
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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

Suggested Solutions

Introduction:   Welcome to my first article ever. To begin with, the reason I write this article.  I participated in a question on Experts Exchange about the start command in Windows and there were some discussion about the usage. The discussio…
In this tutorial I will show you how to provide a dynamic RTF document on your website generated with data from your database. For this tutorial you will need Microsoft Word or WordPad, WhizBase and Microsoft Access. In this tutorial I will show …
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

710 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