Well, mine is certainly not as pretty or detailed as davido's, but I will share it anyway. Echo to the previous post, this is also pre-HTML::Template. However, it's easy to modify, it works, and I still use it every now and then when I need something quick and dirty.

#!/usr/bin/perl use CGI qw(:standard); use CGI::Carp qw/ fatalsToBrowser /; # remove for production #Talk directly to sendmail, not using Mail::Sendmail $SENDMAIL_CMD = '|/usr/lib/sendmail -t -oi'; $cgi = new CGI; print $cgi->header; sub getData{ #get form data, $query->Vars(); } sub validate{ if (keys %errors){ while ( ($key, $value) = each %errors){ print $cgi->p("$key, <b>$value</b>\n"); } &displayErrorPage; }else{ &sendEmail; &displayConfirmationPage; } } sub sendEmail{ $emailBody = $emailBody . "EMAIL TEXT"; %mail = ( SMTP => 'localhost', from => 'from address', #userEmail to => "TO <$emailAddress>", cc => "CC <some cc address>", bcc => "Developer <developer@someAddress.com>", subject => "Subject Line", ); $boundary = "====" . time() . "===="; $mail{'content-type'} = "TEXT/plain; boundary=\"$boundary\""; $boundary = '--'.$boundary; $mail{body} = $mail{body} . $emailBody; sendmail(%mail); } sub displayErrorPage{ print $cgi->h1("Errors were present"); } sub displayConfirmationPage{ print $cgi->p("Thank You -- blah blah blah."); } sub sendmail{ my(%mail)= @_; open(MF, $SENDMAIL_CMD) || print "Sendmail Error! ($!)\n";; print MF<<__MAIL_EOF__; From: $mail{from} To: $mail{to} Bcc: $mail{bcc} Subject: $mail{subject} $mail{body} __MAIL_EOF__ }

  • Yet another way:

    sub sendEmail { my $to_field; my %param; foreach my $n ($query->param){ $param{$n} = $query->param($n); push @allStuff, $1; } &request(%param); } sub request{ my( %param )= @_; open(MF, $SENDMAIL_CMD); print MF<<__MAIL_EOF__; From: $param{from_email} To: $param{to_field}, $param{otherEmail} Subject: Subject Line Bcc: $Monitor_email #email message here.... __MAIL_EOF__

    as I said, there are more (and better) examples, but -- TIMTOWTDI :)


    In reply to Re: CGI form to email by csuhockey3
    in thread CGI form to email by ezekiel

    Title:
    Use:  <p> text here (a paragraph) </p>
    and:  <code> code here </code>
    to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.