This ought to be a FAQ if it ain't already.
MIME::Lite is your friend.
#!/usr/bin/perl -w
use strict;
use CGI;
use CGI::Carp qw/ fatalsToBrowser /; # but never in
# production
use MIME::Lite;
my $q=new CGI;
my @contents=();
foreach my $key($q->param) {
# There is a problem with this code, I'll explain
# later.
push @contents,sprintf("%s = %s",$key,$q->param($key));
}
my $mail=new MIME::Lite (
From => 'me@here.com',
To => 'you@there.com',
Subject => 'contents of my form',
Type => "TEXT",
Data => join("\n",@contents)
);
MIME::Lite->send("smtp","my.smtphost.com",120);
$mail -> send;
For more information on what is going on there check out
MIME::Lite's man page.
Caveats
First off I broke all of my rules with this example in that
I do no error checking anywhere. Secondly, if your
CGI parameters have multiple values then my code above
will break. I leave the solution to that as an intellectual
excersize for you to solve.
Another potential problem with the code above is the use
of CGI::Carp qw / fatalsToBrowser/. This is a potential
information leak for hackers if you use that in production
and they manage to make your code break.
I dashed this off as I am about to be late for a meeting,
but there is the nucleus of a solution for you.
Peter L. Berghold | Brewer of Belgian Ales |
Peter@Berghold.Net | www.berghold.net |
Unix Professional |
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.