cgi-dev

Repository that serves as my CGI "scratchpad" to try things out.
git clone git://git.samirparikh.com/cgi-dev
Log | Files | Refs | README

commit 47642a855b74cba6f9b632826e8989373da3d59c
parent d9ce5eb20b3e7ddf0718a9f7bba3a6bf7ba89c3a
Author: Samir Parikh <noreply@samirparikh.com>
Date:   Wed,  2 Mar 2022 13:52:52 +0000

add mail_form.cgi

Diffstat:
Amail_form.cgi | 75+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 75 insertions(+), 0 deletions(-)

diff --git a/mail_form.cgi b/mail_form.cgi @@ -0,0 +1,75 @@ +#!/usr/bin/perl + +# mail_form.cgi + +# bundle up form output and mail it to the specified address + +use strict; +use warnings; + +# configuration: + +my $sendmail = '/usr/sbin/sendmail'; # where is sendmail? +my $recipient = 'spython01@gmail.com'; # who gets the form data? +my $sender = 'forms@perlcgi.tk'; # default sender? +my $site_name = 'PerlCGI'; # name of site to return to after +my $site_url = '/'; # URL to return to after + +# script proper begins... + +use CGI qw(:standard); + +# bundle up form submissions into a mail_body + +my $mail_body = ''; + +foreach my $field (param) { + foreach my $value (param($field)) { + $mail_body .= "$field: $value\n"; + } +} + +# set an appropriate From: address +my $email = ''; +if ($email = param('email')) { + # the user supplied an email address + $email =~ s/\n/ /g; + $sender = $email; +} + +# send the email message + +open MAIL, "|$sendmail" or die "Can't open pipe to $sendmail: $!\n"; + +print MAIL <<"EOF"; +To: $recipient +From: $sender +Subject: Sample Web Form Submission + +$mail_body +EOF + +close MAIL or die "Can't close pipe to $sendmail: $!\n"; + +# now show the thank-you screen + +print header, <<"EOF"; +<HTML> +<HEAD> +<TITLE>Thank you</TITLE> +</HEAD> + +<BODY> + +<H1>Thank you</H1> + +<P>Thank you for your form submission. You will be hearing +from me shortly.</P> + +<P>Return to +<A HREF="$site_url">$site_name</A>.</P> + +</BODY> +</HTML> +EOF +