#!/usr/bin/perl # database names, emails, subjects have been changed # to protect the innocent use strict; use CGI; use CGI::Carp qw(fatalsToBrowser); use Postgres; # old module, I know use Mail::Send; my $sql = db_connect("mydbname"); if (!$sql){ die "Unable to open database: $!\n"; } my $table = 'users'; my $q = new CGI; print $q->header; if($q->param('email') eq ''){ print $q->p(qq{

Please go back and provide your account email address.

\n}); exit; } my $query = sprintf(q{SELECT email, namefirst, namelast, username, userpass from %s WHERE email ~ %s}, $table, qstr($q->param('email')) ); my $result = $sql->execute($query); my @data = $result->fetchrow(); my $email = $data[0]; if($email ne ''){ send_account(\@data); print $q->p( "Thank you! Your account information has been sent to " . $email ); print $q->p( qq{Log In} ); }else{ print $q->p(qq{

Sorry! No account found with that email address. Please } . qq{go back and try again.

\n}); } sub qstr{ # this old Postgres module does not have its own quote() method. # this is a weak implementation, but better than nothing. (I think) my ($str) = @_; $str =~ s#(\\)#/#sg; # replace backslashes with slashes $str =~ s/(['])/\\$1/; # escape single-quotes return qq{'$str'}; } sub send_account{ my ($matching_row) = @_; # Set Mail Headers my $mailout = new Mail::Send; $mailout->to( shift @{$matching_row} ); $mailout->subject("Online Registration"); $mailout->add('From', 'user@domain.com'); $mailout->add('Reply-To', 'user@domain.com'); # open up a mail filehandle my $mailfh = $mailout->open; # print mail body my $mailbody=<close; }