help with send mail script

They have: 3 posts

Joined: Jan 2001

Can someone take alook at this script. I don't get meassage sent and it doesn't give an error. see below.

Thanks for your comments!

#!/usr/bin/perl
# This script should send an e-mail

print "Content-type:text/html\n\n";

read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);

foreach $pair (@pairs)
{
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$FORM{$name} = $value;
}

$mailprog = '/var/qmail/bin/qmail-inject';
$recipient = '[email protected]';
open (MAIL, "|$mailprog -t") or &dienice("Can't access $mailprog!\n");
print MAIL "To: $recipient\n";
print MAIL "Reply-to: $FORM{'email'} ($FORM{'name'})\n";
print MAIL "Subject: Form Data\n\n";

# krb print info from form to mail message.
foreach $key (keys(%FORM))
{
print MAIL "$key = $FORM{$key}\n";
}

close(MAIL);

#added to assess problems- krb!!!!!
print "Form Diagnostics";
print "Diagnostics for send mail form\n";
print "Referer = $ENV{'HTTP_REFERER'}\n";
print "Caller = $ENV{'CONTENT_LENGTH'}\n";
print "";

# Notify mail has been delivered - krb
print "";
print <Thank You
Thank you for writing. Your mail has been delivered.
Return to our home page.

EndHTML

sub dienice
{
($errmsg) = @_;
print "Error\n";
print "$errmsg\n";
print "\n";
exit;
}

They have: 453 posts

Joined: Jan 1999

Just a question,

where is the sender specified ?
Some MTA won't deliver it without.

And you won't get an error back.

anti

They have: 3 posts

Joined: Jan 2001

Hello,

The sender should be filled in from the form with the variable - 'email'.

If I understand that right. Is there an environment variable called sender?

Comments? Anyone.

They have: 453 posts

Joined: Jan 1999

But the sender (From: ...) belongs in the header, that is before the empty line(\n\n).

Give it a try.

BTW:
On which system is this running ?
(BSD, Linux, Solaris ?)

They have: 12 posts

Joined: Dec 2000

I slighly modified this since I can't seen to get a mail script to work on my new server (RaQ3). And as with the others, it dosen't work either. ANyone see an obvious problem? I get 500 errors.

#!/usr/bin/perl

print "Content-type:text/html\n\n";

read(STDIN, $buffer, 128000);
@pairs = split(/&/, $buffer);

foreach $pair (@pairs)
{
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$FORM{$name} = $value;
}

$mailprog = '/usr/sbin/sendmail';
open (MAIL, "|$mailprog") or &dienice("Can't access $mailprog!\n");
print MAIL "To: syanet\@neo.rr.com";
print MAIL "From: $FORM{'email'}\n";
print MAIL "Reply-to: $FORM{'email'} ($FORM{'name'})\n";
print MAIL "Subject: Submission\n\n";

foreach $key (keys(%FORM))
{
print MAIL "$key = $FORM{$key}\n";
}

close(MAIL);

They have: 3 posts

Joined: Jan 2001

I did just get this error.

Any comments?

syntax error at /data/pecan204/cgi-bin/send_mail.cgi line 27, near "$key ("
Execution of /data/pecan204/cgi-bin/send_mail.cgi aborted due to compilation errors.
[Fri Jan 26 18:31:38 2001] [error] [client 24.25.151.112] Premature end of script headers: /data/pecan204/cgi-bin/send_mail.cgi
[Fri Jan 26 18:31:38 2001] [error] [client 24.25.151.112] MOD_VR9: Error 500 occured while processing : /data/pecan204/cgi-bin/send_mail.cgi

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.