Changeset 26

Show
Ignore:
Timestamp:
08/30/09 21:03:00 (1 year ago)
Author:
jdixon
Message:

email notifications for new comments

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/examples/httpd-blogsum.conf

    r17 r26  
    1515                SetHandler perl-script 
    1616                PerlHandler Apache::PerlRun 
    17                 PerlModule strict CGI DBI DBD::SQLite HTML::Template XML::RSS Captcha::reCAPTCHA HTML::Entities HTTP::Request::Common URI::_foreign Errno Net::HTTP IO::Select Compress::Zlib Log::Agent URI::http LWP::Protocol::http Carp::Heavy 
     17                PerlModule strict CGI DBI DBD::SQLite HTML::Template XML::RSS Net::SMTP Captcha::reCAPTCHA HTML::Entities HTTP::Request::Common URI::_foreign Errno Net::HTTP IO::Select Compress::Zlib Log::Agent URI::http LWP::Protocol::http Carp::Heavy 
    1818                Options ExecCGI 
    1919                Order deny,allow 
  • trunk/index.cgi

    r25 r26  
    2020my $comment_max_length = '1000'; 
    2121my $comments_allowed = 0; 
     22my $smtp_server = 'localhost:25'; 
     23my $smtp_sender = 'blogsum@example.com'; 
    2224 
    2325 
     
    240242 
    241243        if ($cgi->param('recaptcha_response_field') && $cgi->param('comment') && $cgi->param('id')) { 
     244 
    242245                # test our captcha 
    243246                my $result = $captcha->check_answer( $captcha_seckey, $ENV{'REMOTE_ADDR'}, $cgi->param('recaptcha_challenge_field'), $cgi->param('recaptcha_response_field') ); 
     247 
    244248                if ($result->{'is_valid'}) { 
     249 
    245250                        # save comment 
    246251                        my $comment = $cgi->param('comment'); 
     
    250255                        $sth->execute($cgi->param('id'), $cgi->param('name') || 'anonymous', $cgi->param('email') || undef, $cgi->param('url') || undef, substr(HTML::Entities::encode($cgi->param('comment')), 0, $comment_max_length)) || die $dbh->errstr; 
    251256                        $template->param( message => 'comment awaiting moderation, thank you' ); 
     257 
     258                        # send email notification 
     259                        my $smtp = Net::SMTP->new($smtp_server); 
     260                        $smtp->mail($ENV{USER}); 
     261                        $smtp->to("$blog_owner\n"); 
     262                        $smtp->data(); 
     263                        $smtp->datasend("From: $smtp_sender\n");  
     264                        $smtp->datasend("To: $blog_owner\n"); 
     265                        $smtp->datasend("Subject: $blog_title comment submission\n\n"); 
     266                        $smtp->datasend("You have received a new comment submission.\n\n");  
     267                        $smtp->datasend(sprintf("From: %s\n", $cgi->param('name') || 'anonymous')); 
     268                        $smtp->datasend(sprintf("Date: %s\n", scalar(localtime))); 
     269                        $smtp->datasend(sprintf("Comment:\n\"%s\"\n\n", substr(HTML::Entities::encode($cgi->param('comment')), 0, $comment_max_length))); 
     270                        $smtp->datasend("Moderate comments at ${blog_url}admin.cgi?view=moderate\n"); 
     271                        $smtp->dataend();  
     272                        $smtp->quit; 
    252273                } else { 
    253274                        $template->param( error => $friendly_errors{ $result->{'error'} } );