Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Re: CGI form to email

by csuhockey3 (Curate)
on Sep 13, 2004 at 05:44 UTC ( #390500=note: print w/replies, xml ) Need Help??

in reply to CGI form to email

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 <>", 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 :)

  • Log In?

    What's my password?
    Create A New User
    Node Status?
    node history
    Node Type: note [id://390500]
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others cooling their heels in the Monastery: (2)
    As of 2021-01-25 02:39 GMT
    Find Nodes?
      Voting Booth?