Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Form mail results in HTML format

Posted on 2002-06-11
2
Medium Priority
?
256 Views
Last Modified: 2013-12-25
I have a very simple form mail script that I use and would like to continue using, as it is easy for me to understand. What I would like to do is to send the email that is generated in html format so that I can include tables etc, allowing me to control the email layout more.

Can anybody help by showing what modification need to be made to my script? (See below)

I am new to cgi so please keep it simple.



#!/usr/bin/perl

# Location of sendmail
$mailprog = '/usr/lib/sendmail';

# Email address that emails are sent from
$to_email = 'me@mydomain.com';

# Full server path to the location of the mailfail & thankyou html files are (with trailing slash).
$pathtohtml = '/home/sites/www.mydomain.com/web/';

# The name of the html mail fail file.
$failfilename = 'mailfail.html';

# The name of the html mail ok file.
$thankyoufilename = 'mailok.html';

##########################################################################

&readparse;

#####################################
# Required Fileds
#####################################

&blank unless $form{name};
&blank unless $form{email};

#####################################
# End of required fields
#####################################

&sendemails;

#######################################################
# print the thank you page
#######################################################

open(HTMLFILE,"$pathtohtml" . "$thankyoufilename") or ("Cannot open $thankyoufilename");
{ local $/; $htmlContent = <HTMLFILE> }
close(HTMLFILE);
$htmlContent = "Content-Type: text/html\n\n" . $htmlContent;
print "$htmlContent";

################################################################################
# Send to email address set above.
#################################################################################
sub sendemails
{
open (MAIL, "|$mailprog $to_email") || die "Can't open $mailprog!\n";
print MAIL "Reply-to: $form{email}\n";
print MAIL "Subject: HTML Test\n";

print MAIL qq!
$form{email} ($form{name})
Address:
$form{address}
Tel No: $form{tel}
Fax No: $form{fax}
------------------------------------------------------------
!;
close (MAIL);
}

#######################################################
# Sub for blank fields that are required
#######################################################
sub blank
{
open(HTMLFILE,"$pathtohtml" . "$failfilename") or ("Cannot open $failfilename");
{ local $/; $htmlContent = <HTMLFILE> }
close(HTMLFILE);
$htmlContent = "Content-Type: text/html\n\n" . $htmlContent;
print "$htmlContent";
exit;
}


##############################################################
#  Parse from the web form
##############################################################
sub readparse
{
read (STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@cgiPairs = split(/&/,$buffer);
foreach $cgiPair (@cgiPairs)
{
  ($name,$value) = split(/=/,$cgiPair);
  $value =~ s/\+/ /g;
  $value =~ s/%(..)/pack("c",hex($1))/ge;
  $form{$name} .= "\0" if (defined($form{$name}));
  $form{$name} .= "$value";
}}

0
Comment
Question by:meto
[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
2 Comments
 
LVL 51

Expert Comment

by:ahoffmann
ID: 7070904
which part should be HTML?
Do you mean something like this (in your sub sendmails):

<table>
<tr><th>$form{email}</th><td>($form{name})</td></tr>
<tr><th>Address:</th><td>$form{address}</td></tr>
<tr><th>Tel No:</th><td>$form{tel}</td></tr>
<tr><th>Fax No:</th><td>$form{fax}</td></tr>
</table><hr>
0
 
LVL 6

Accepted Solution

by:
andreif earned 400 total points
ID: 7072079
add Content-Type header to the message:

print MAIL "Reply-to: $form{email}\n";
print MAIL "Subject: HTML Test\n";
print MAIL "Content-Type: text/html\n";

and, of course, format your message using HTML tags :)
0

Featured Post

TCP/IP Network Protocol Cheat Sheet

TCP/IP is a set of network protocols which is best known for connecting the machines that make up the Internet. The truth is that TCP/IP is one of the oldest network protocols and its survival is mainly based on its simplicity and universality.

Question has a verified solution.

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

A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

705 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