I'm currently trying to setup a perl script to send an email to a recipient based on form input from a website, the webserver and destination emailserver are seperate servers but in the same subnet, so it's not a firewall issue.  
I appear to have two email servers on my webserver, which is on a CentOS OS, sendmail, which i've just installed and one called Exim, which seems to be taking control.  
The exim log shows the following when the perl script is activated:
"2010-08-05 14:02:27 1Oh4lv-0002Yd-TW <= U=horizon P=local S=499
2010-08-05 14:02:27 1Oh4lv-0002Yd-TW => cwfi <> R=localuser T=local_delivery
2010-08-05 14:02:27 1Oh4lv-0002Yd-TW Completed"

Which seems to show that the Exim is accepting it and delivering it somewhere locally on the webserver, which i don't want.  As the Perl script is set to use SendMail.  Any ideas?

I'll include the Perl script below if that helps, but i'd say from the Exim log, that it is working:

# location of Perl (above) - check your doc or ask admin
# URL to go to if there is a problem with form input
$ErrorPage = "/a_fail.html";
#URL to go to if there is a problem with email format
$EmailError = "/a_email_fail.html";
# URL to go to when form has been successfully submitted
$ThankPage = "/a_thanks_Green.html";
# URL to go to if a 'foreign' referer calls the script
#$EvilReferer = "";
# E-mail address to send intake form to (your address)
# If not using PERL 5, escape the @ thus: \@ instead of @
$YourEmail = '';
# Script works only on your server(s) - ('URL1','URL2')
#@referers = ('','');
# Location of mail program - check your doc or ask admin
$MailProgram = '/usr/sbin/sendmail';
# Subject of the e-mail autoreply to the submitter
$Subject = "Go Green, Go Paperless" ;
# Header line in the auto-reply message
$Header = "Go Green, Go Paperless" ;
# Brief tail message for body of e-mail autoreply
$TailMessage = "If your message requires a reply, we'll get back to you soon.";
# Your signature lines the end of the autoreply e-mail
$Signature1 = "Webmaster";
$Signature2 = "domain.url";
$client_name = $in{'client_name'};
$client_email = $in{'client_email'};
$client_AccountNo = $in{'client_AccountNo'};
$client_phone = $in{'client_phone'};
$DirectDebit = $in{'DirectDebit'};
$ItemisedB = $in{'ItemisedB'};
print "Location: $ThankPage\n\n";
# _________________________________________________________
sub SendSubmission {
open (MAIL,"|$MailProgram -t");
print MAIL "To: $YourEmail\n";
print MAIL "From: $client_email\n";
print MAIL "Subject: $Subject\n";
print MAIL "$Date\n\n";
print MAIL "Details\n\n";
print MAIL "Name: $client_name\n";
print MAIL "Email: $client_email\n";
print MAIL "AccountNo: $client_AccountNo\n";
print MAIL "Phone: $client_phone\n";
print MAIL "Direct Debit Form: $DirectDebit\n";
print MAIL "Itemised?: $ItemisedB\n\n";
close (MAIL);
# _________________________________________________________
sub GetDate {
@days = ('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday')
@months = ('01','02','03','04','05','06','07','08','09','10','11','12');
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
$year = $year+1900;
$Date = "$days[$wday] $months[$mon]/$mday/$year";
# _________________________________________________________
sub ReadParse { local (*in) = @_ if @_;
local ($i, $key, $val); if ( $ENV{'REQUEST_METHOD'} eq "GET" )
{$in = $ENV{'QUERY_STRING'};}
elsif ($ENV{'REQUEST_METHOD'} eq "POST")
else {
$in = ( grep( !/^-/, @ARGV )) [0];
$in =~ s/\\&/&/g; } @in = split(/&/,$in);
foreach $i (0 .. $#in) {
$in[$i] =~ s/\+/ /g;
($key, $val) = split(/=/,$in[$i],2);
$key =~ s/%(..)/pack("c",hex($1))/ge;
$val =~ s/%(..)/pack("c",hex($1))/ge;
$in{$key} .= "\0" if (defined($in{$key}));
$in{$key} .= $val; } return length($in); }

Any input would be greatly appreciated,


asked 08/05/2010 03:41

cwipfk's gravatar image

cwipfk ♦♦

9 Answers:

'' is Perl program that has been around a long time to use sendmail to send info from forms.  Maybe you can use it to figure out what you want to do. There is also a newer version called nms formmail list on their site:



DaveBaldwin's gravatar image


Hmmm.. well, first off, change this line:

  open (MAIL,"|$MailProgram -t");


  open (MAIL,"|$MailProgram -oi -t");

To ignore lines containing a single period (rarely needed, but a good idea, just in case you process a textarea where the user put a period on a line by itself).

It's odd that EXIM is doing a local delivery and reporting success.  Are you sure it isn't delivering to a local account somehow?  'sendmail' can be used for both sending and receiving e-mail, but it may be set up and/or used to do only one.  You can easily send mail using 'sendmail' on a server that is actually running Exim to do local & remote delivery.

There are several possibilities as to what could be going on here.  The web server might incorrectly be configure to handle mail for the other server, in which case it will definitely be doing a local delivery (maybe the web server once *was* the e-mail server).  Remove this as a possibility - set the destination e-mail to a Gmail or other 3rd part service and see what happens.


answered 2010-08-05 at 12:31:00

nemws1's gravatar image


You could consider using Net::SMTP to avoid any dependencies to a particluar mail client.  Example, add to the top:

use Net::SMTP;

and then change SendSubmission to

sub SendSubmission {
  my $smtp = Net::SMTP->new('localhost');
  print MAIL "To: $YourEmail\n";
  print MAIL "From: $client_email\n";
  print MAIL "Subject: $Subject\n";
  print MAIL "$Date\n\n";
  print MAIL "Details\n\n";
  print MAIL "Name: $client_name\n";
  print MAIL "Email: $client_email\n";
  print MAIL "AccountNo: $client_AccountNo\n";
  print MAIL "Phone: $client_phone\n";
  print MAIL "Direct Debit Form: $DirectDebit\n";
  print MAIL "Itemised?: $ItemisedB\n\n";
  close (MAIL);


answered 2010-08-05 at 12:33:57

bguyton3's gravatar image


Whoops... don't know how that got submitted early...  should read

sub SendSubmission {
  my $smtp = Net::SMTP->new('localhost');

  $smtp->datasend("To: $YourEmail\n");
  $smtp->datasend("From: $client_email\n");
  $smtp->datasend("Subject: $Subject\n");
  $smtp->datasend("Details\n\n" .
      "Name: $client_name\n" .
      "Email: $client_email\n" .
      "AccountNo: $client_AccountNo\n" .
      "Phone: $client_phone\n" .
      "Direct Debit Form: $DirectDebit\n" .
      "Itemised?: $ItemisedB\n\n";


answered 2010-08-05 at 20:40:56

bguyton3's gravatar image


I'd use MIME::Lite which defaults to using sendmail, but it also allows you to specify the smtp server.

And please get rid of the GetDate and ReadParse subroutines.

The GetDate sub would be replaced with:

use POSIX qw(strftime);
my $Date = strftime("%A %m/%d/%Y", localtime);

The ReadParse sub would be replaced with:

use CGI qw(:standard);
my %in = Vars;

or the OO interface, which is my preference.

use CGI;
my $cgi = CGI->new;
my %in = $cgi->Vars;


answered 2010-08-05 at 20:48:33

FishMonger's gravatar image


I assume that the script you're currently using was downloaded from some web site instead of being written by you.  It is very poorly written, and I'm being polite.  It should not be used.

The formmail script from scriptarchive that Dave pointed to is better, but still poorly written.  The one from the NMS project is well written and would be a good choice if you simply need the form submission info.


answered 2010-08-06 at 07:17:59

FishMonger's gravatar image


If you are familiar an used to this script, you might want to check whether the domain is also configured on this domain and thus considered local.

Happened to me and the issue was purely dns


Rodrigo O


answered 2010-08-06 at 07:32:55

rordonez's gravatar image


Here's a function I use that doesn't require an external module, just the location of sendmail.  Short and sweet, works perfectly for my automated reports.

sub sendEmail {
        my ($to, $from, $subject, $message) = @_;
        my $sendmail = '/usr/sbin/sendmail';

        open(MAIL, "|$sendmail -oi -t");
        print MAIL "From: $from\n";
        print MAIL "To: $to\n";
        print MAIL "Subject: $subject\n\n";
        print MAIL "$message\n";



answered 2010-08-09 at 19:07:23

group0's gravatar image


This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.


answered 2010-08-13 at 10:15:17

suhasbharadwaj's gravatar image


Your answer
[hide preview]

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments



Asked: 08/05/2010 03:41

Seen: 262 times

Last updated: 12/17/2011 05:21