I'm hoping an experienced PHP coder might be able to help get my extensive Perl based e-mail filter into a PHP 'function' which can be used in PHP scripts. Others might find it useful as well.
I'm a mini-Perl hacker and thanks to one of the gurus on a Perl newsgroup, came up with a more extensive e-mail filtering REGEXP which helped to substantially eliminate unnecessary e-mails being generated only to have them bounce. The classic bogus forgeries (especially from China) seem to take on the following format:
8888888aaaaa@37856666666.com
0@0.com
www@#sxy.com.cn
...etc., etc.
So here's the Perl code I'm using to just bounce MANY of these bogus attempts immediately back into their faces and sure would like to see a PHP version 'cuz it works great! Maybe someone can incorporate this with the bounce-back HTML Echo stuff. I decided upon this coding approach in lieu of one "Monster" REGEXP because I can get in and do additional tweakings very easily.
I don't know if this will format correctly in the post or not.
#CHECK E-MAIL FORMAT VALIDITY (ROUGH TEST)
my $email = $FORM{'email'}; # use this line for live CGI Form processing
#my $email = 'user@somedomain.com'; # e-mail entry for testing only - comment out
email_check() if length $email >40 # most likely bogus or some malicious code!
or $email !~ /[!@]/ # bounce character/word screwaround entries
or $email =~ m/\s/ # delete some valid email addresses :-)
or $email =~ m/[A-Za-z0-9]/ # checks front part of e-mail
or $email =~ m/[A-Za-z0-9]@/ # checks part just before @
or $email =~ m/@[A-Za-z0-9]/ # checks part right after @
or $email =~ m/.[A-Za-z0-9]./ # checks part right before .TLD
or $email !~ m/..[A-Za-z]{2,4}$/ # checks for 2-4 character TLD
or $email =~ m/www/ # bounce dumbo 'www' format entries
or $email =~ m/([A-Za-z0-9]){4,15}/ # bounce aaaaa 88888 etc. types
or $email =~ m/[(\d|\D)]@[(\d|\D)].[A-Za-z]{2,4}$/ # bounce dumbo 0@0.com format entries
or $email =~ m/.[~!@#%^&()[]{}|;:"'<,>?\/].@/ # check weirdos before @
or $email =~ m/.@.[~!@#%^&()_[]{}|;:"'<,>?\/].*./ # check weirdos before .TLD
or $email =~ m/@mydomain.com$/; # axes email forgeries of (myowndomain)
DON'T FORGET TO CHANGE/UNCOMMENT THE FILEWRITING LINES !!!!
subroutine email_check
Print a title and initial heading and reject text
sub email_check
{
print "<Head><Title>Thank You</Title></Head>";
print "<Body><H1>Thank You</H1>";
print "Your e-mail address appears to be invalid and we can not process ";
print "your request(s). Please backup and re-enter.\r\n";
print "<HR>";
print "Return to <A HREF=\"http://www.mydomain.com/index.html\">Webpage</A>.<P>";
exit;
}
Thank you very much!