Solved

Form mail results in HTML format

Posted on 2002-06-11
2
248 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 100 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

Enroll in July's Course of the Month

July's Course of the Month is now available! Enroll to learn HTML5 and prepare for certification. It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

This tutorial will discuss fancy secure registration forms, with AJAX technology support. In this article I assume you already know HTML and some JS. I will write the code using WhizBase Server Pages, so you need to know some basics in WBSP (you mig…
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 the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
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…

623 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