in reply to Sending email with Perl
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.
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 | |
|
|---|