#!/usr/bin/perl -T # generic contact mail use warnings; use strict; use Mail::Sendmail; use CGI::Carp qw( fatalsToBrowser ); use CGI qw( header param ); sub DEBUG( @ ); sub addError( $ ); # parameters: # fromname = sender's name # fromemail = sender's email addr # msgsubject = subject for the mail # use as: # for example. # put the file contact.conf somewhere outside the www, so people won't be able to see your email # reading the conf file my ( $to, $server, $redirect ); open( my $fd, 'contact.conf' ) or die( "open() ( $! )" ); while ( my $l = <$fd> ) { unless ( defined( $l ) && $l ) { next } if ( $l =~ /^#/ ) { next } if ( $l =~ /^to\s*=\s*(.+)/ ) { $to = $1; DEBUG "Found to: $to\n"; next } if ( $l =~ /^server\s*=\s*(.+)/ ) { $server = $1; DEBUG "Found server: $server\n"; next } if ( $l =~ /^redirect\s*=\s*(.+)/ ) { $redirect = $1; DEBUG "Found redirect: $redirect\n"; next } } close( $fd ); open( $fd, 'template.conf' ) or die( "open() ( $! )" ); my $template = ''; while ( my $l = <$fd> ) { if ( $l =~ /^#/ ) { next } $template .= $l; } close( $fd ); print header; while ( $template =~ /{(.+?)}/g ) { my $m = $1; if ( my $param = param( $m ) || '' ) { $template =~ s/$m/$param/ } } print myheader(); if ( canSendMail( $ENV{ 'REMOTE_ADDR' } ) ) { mail( $to, param( 'fromemail' ), 'Submitted contact form from your website PBD1.CO.UK', $template, $server ); } else { print "