Below is a simple script we use on both Linux and BSD servers that run Apache, to create a way for customers to email us, without giving out our email address. It is very simple, nothing fancy at all, but will serve as a framework if you want to add the feature on your website. It does refer back to the original page, and tells you the IP address of the request, to deal with abuse. The SENDTO email address is hard coded so it can't spam anyone (except you). It isn't the right way, it is just my way. Just copy everything BELOW the --- line, making sure the line with #!/usr/bin/perl is the first line. You may need to edit that line to point to your Perl executable. Then change $appat and $mailto. Make sure to chmod a+x (or chmod 755 [filename]) so it can execute, and make sure the extension is something that works on your system, ie: .pl or .cgi Obviously, no warranty expressed or implied, use at your own risk. ---------------------------------------------------------------- #!/usr/bin/perl # version 0.0.2 - by Dennis Brown dennis at mypanda dot com # Released to the Public Domain. Use at your own risk. # Simple perl script to allow your customers to email you without # posting your email addresses. Should work on Apache on BSD or Linux. # Tested on Yahoo's FreeBSD servers. ("sendmail -f" NOT allowed there) ################################# ### ENVIRONMENT (edit to your own needs) ################################# # This is the full URL to the program itself. $appat="http://www.example.com/cgi-bin/contactus.pl"; # This is who you want to receive all emails $mailto='yourname@example.com'; # You shouldn't need to edit anything below this line except for layout ################################# ### SUB ROUTINES ################################# sub startpage { # we captures HTTP_REFERER so we can send them back to the same page # after they are done if they choose. print "Content-type: text/html\n\n"; print <Email Us

Contact Us

$lastmsg

Have a question that isn't answered on the website?   Email is often the fastest way to get an answer because we often check our email even when not in the office.

Please note:  Your email address will NOT be added to any list or used for any purpose except answering your question.  We respect your privacy, and we hate spam as much as you do.  All fields are required to be filled out.


Your name


Your email address


Your area code and phone

PAGE ;; exit 0; }#end of startpage sub check{ # this just makes sure each field has SOME content on it. # comment out any if() section you don't want checking for if ($cgi{appcheck} !~ /[a-zA-Z0-9]/){ #first time to run? startpage(); exit 0; } #missing data? elsif ($cgi{email} !~ /[a-zA-Z0-9]/){ error(); } elsif ($cgi{name} !~ /[a-zA-Z0-9]/){ error(); } elsif ($cgi{phone} !~ /[a-zA-Z0-9]/){ error(); } elsif ($cgi{question} !~ /[a-zA-Z0-9]/){ error(); } else{ sendmail(); endpage(); exit 0; } } sub error{ #simple error message and redraws startpage $lastmsg="

You must fill out all the fields before submitting.

"; startpage(); exit 0; } ######### sub parseit{ #standard method to read the contents of a POST form if (defined($ENV{CONTENT_LENGTH}) && $ENV{CONTENT_LENGTH} != 0) { read(STDIN, $content, $ENV{CONTENT_LENGTH}); foreach $pairset (split(/&/, $content)) { ($key, $value) = split(/=/, $pairset); $value =~ tr/+/ /; $value =~ s/%(..)/pack("c", hex($1))/eg; $cgi{$key} = $value; } #end foreach } } ######### sub sendmail{ # the SERVER_NAME variable is passed by Apache. It lets you know # what domain the form came from, without hardcoding the name in. $subject="$ENV{'SERVER_NAME'} Comment from $cgi{name} - $cgi{email}"; close(SOCK); open(SOCK, "| /usr/sbin/sendmail -t"); print SOCK "To: $mailto\n"; print SOCK "Errors-To: $mailto\n"; print SOCK "Reply-To: $cgi{email}\n"; print SOCK "Subject: $subject\n"; print SOCK "Automsg via $ENV{'SERVER_NAME'} \n"; print SOCK "from $cgi{name} at $cgi{email}\n" print SOCK "Phone number: $cgi{phone}\n\n"; print SOCK "$cgi{question}\n\n"; print SOCK "--------------------\n"; print SOCK "Source IP: $ENV{'REMOTE_ADDR'}\n" print SOCK "--------------------\n"; close(SOCK); } sub endpage{ print "Content-type: text/html\n\n"; print <Thank You!

Thank You!

Your question/comment will be forwarded to the proper department and you should be hearing from someone very soon.   We check our email very frequently during business hours, and the person responsible for answering your question will either email you back or call you, depending upon the nature of the question.

If you like, you can go back to the previous page.


PAGE ;; exit 0; } ################################# ### PROGRAM ################################# parseit(); check(); exit 0; 1;