Changeset 152


Ignore:
Timestamp:
Oct 24, 2006, 6:22:51 PM (13 years ago)
Author:
Dominic Hargreaves
Message:

Streamline mail processing

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/npemap.org.uk/cgi/problem.fcgi

    r135 r152  
    88
    99use DBI;
     10use MIME::Lite;
     11use Email::Valid;
    1012use CGI::Fast qw/:standard -debug/;
    1113
     
    4749        next REQUEST;
    4850    }
    49     my $type = $cgi->param('type');
    50     my $email = $cgi->param('email');
    51     my $comment= $cgi->param('comment');
     51
     52    if (defined $cgi->param('email') and !(Email::Valid->address($cgi->param('email')))) {
     53        print_err ("Invalid email address supplied");
     54        next REQUEST;
     55    }
     56
     57    my $type = $cgi->param('type') || 'none';
     58    my $from = $cgi->param('email') || 'webmaster@npemap.org.uk';
     59    my $comment = $cgi->param('comment');
    5260    my $subject = "[$type] comment from npemap.org.uk ";
    53     my $message = <<"END";
    5461
    55 From $email
     62    my $msg = MIME::Lite->new(
     63        From => $from,
     64        To => 'webmaster@npemap.org.uk',
     65        Subject => $subject,
     66        Data => $comment);
     67    $msg->send;
    5668
    57 $comment
    58 
    59 END
    60     sendEmail('webmaster@npemap.org.uk', 'webmaster@npemap.org.uk', $subject, $message) ;
    6169    print "Content-type: text/html\n\n";
    6270    print "<html><head><title>Thanks</title></head>";
     
    8795    return $dbh = DBI->connect_cached($data_source, $dbuser, $dbpass);
    8896}
    89 
    90 # Simple Email Function
    91 # ($to, $from, $subject, $message)
    92 sub sendEmail
    93 {
    94     my ($to, $from, $subject, $message) = @_;
    95     my $sendmail = '/usr/lib/sendmail';
    96     open(MAIL, "|$sendmail -oi -t");
    97     print MAIL "From: $from\n";
    98     print MAIL "To: $to\n";
    99     print MAIL "Subject: $subject\n\n";
    100     print MAIL "$message\n";
    101     close(MAIL);
    102 }
Note: See TracChangeset for help on using the changeset viewer.