sloppycode.net
Form to mail example
A very basic form to mail in Perl.
Home
›
Code snippets
›
Perl (CGI)
›
Form to mail example
Here is a basic Perl form to emailer. If needs a form with text fields named "name","company","email","tel","message". You can customise the 'thank you' part of the page at the bottom of the script (between the OUTPUT parts).
#!/usr/local/bin/perl -w read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); # Change these variables $toAddress = "you@yourdomain.com"; $website = "www.yourdomain.com"; # Change this variable to your path to sendmail. Keep -t included $mailprog="/usr/lib/sendmail -t"; @pairs = split(/&/, $buffer); foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $FORM{$name} = $value; } $name = $FORM{'name'}; $company = $FORM{'company'}; $email = $FORM{'email'}; $tel = $FORM{'tel'}; $nessage = $FORM{'message'}; open(MAIL,"|$mailprog"); print MAIL "To: $toAddress\n"; print MAIL "From: (Contact Robot)\n"; print MAIL "Subject: Contact form\n\n"; print MAIL "$Name has filled in the contact form on $website, here are their details:\n"; print MAIL "Name: $bame\n"; print MAIL "Company/Profession: $company\n"; print MAIL "Contact email: $email\n"; print MAIL "Contact telephone: $tel\n"; print MAIL "Message: \n$message\n\n\n"; close(MAIL); print "Content-type: text/html\n\n"; print <<OUTPUT; Thanks, your details have been sent OUTPUT
{Name}
Says:
{Date}
{Text}
› Home
› C#
› Snippets
› Articles
› Tools
› Taglines
› ASP
› Dictionary Object
› FSO
› Unix cheat sheet
› Gaming
› CSS
› Yak
› Umbraco
› About
› Contact
› Privacy
› Projects
› Search
› Sitemap
Buy on Amazon
Buy on Amazon
Buy on Amazon
Buy on Amazon