Please help newbie with sendmail problem !

J

Jake Gourd

hey,

Im trying to make a cgi script work on host europe server, as far as i
know the snedmail path is correct and cgi is running correctly (a
simple print works). When I run the code below it just says

The server encountered an internal error or misconfiguration and was
unable to complete your request

on the screen, you can see this by visiting the url

http://www.goodprint.co.uk/cgi_bin/test.cgi

Please help im going mad !

#!/usr/bin/perl

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

print "Hello, world!\n";


open(SENDMAIL, "/usr/sbin/sendmail") or die "Cannot open $sendmail:
$!";
print SENDMAIL "(e-mail address removed)";
print SENDMAIL "test subject";
print SENDMAIL "(e-mail address removed)";
print SENDMAIL "Content-type: text/plain\n\n";
print SENDMAIL "The content";
close(SENDMAIL);
 
J

Jack Challen

Jake said:
Im trying to make a cgi script work on host europe server, as far as i
know the snedmail path is correct and cgi is running correctly (a
simple print works). When I run the code below it just says


Please, please don't try calling the sendmail binary directly. It's almost
guaranteed to be a huge security hole. You should try one of the Mailing
modules on the CPAN. My current favourite is MIME::Lite.

Useful URLs:

http://cpan.org/
http://search.cpan.org/
http://search.cpan.org/~yves/MIME-Lite-3.01/lib/MIME/Lite.pm

Cheers
jack
 
P

Paul Lalli

hey,

Im trying to make a cgi script work on host europe server, as far as i
know the snedmail path is correct and cgi is running correctly (a
simple print works). When I run the code below it just says

The server encountered an internal error or misconfiguration and was
unable to complete your request

on the screen, you can see this by visiting the url

http://www.goodprint.co.uk/cgi_bin/test.cgi

Please help im going mad !

#!/usr/bin/perl

Ask perl for all the help it can give you:
use strict;
use warnings;
use CGI::Carp qw/fatalsToBrowser warningsToBrowser/;
print "Content-type: text/html\n\n";
warningsToBrowser(1);

print "Hello, world!\n";
open(SENDMAIL, "/usr/sbin/sendmail") or die "Cannot open $sendmail: $!";

With the CGI::Carp line above, the error message will print to your
browser. But there are at least 2 problems with this line:
You're trying to open the sendmail program, instead of opening a pipe to
it. That should be "|/usr/sbin/sendmail". Note the |
You're using a variable $sendmail that does not exist in your die
statement.

print SENDMAIL "(e-mail address removed)";

You need to either backslash the @, or (preferably) use single quotes
instead of double:
print SENDMAIL '(e-mail address removed)';
print SENDMAIL "test subject";
print SENDMAIL "(e-mail address removed)";

Same thing here.
print SENDMAIL "Content-type: text/plain\n\n";
print SENDMAIL "The content";
close(SENDMAIL);

With CGI::Carp and the call to warningsToBrowser, as well as the use
warnings; statement, the warnings that would be generated by those @test
and @goodprint lines will be printed as HTML comments.

Paul Lalli
 
S

Steven Smolinski

Jake Gourd said:
Im trying to make a cgi script work on host europe server, as far as i
know the snedmail path is correct and cgi is running correctly (a
simple print works). [...]

perldoc -q 500
#!/usr/bin/perl

#!/usr/bin/perl -T
use warnings;
use strict;

If you're not asking perl for debugging help, you will annoy people.
Around here it's generally considered rude to ask people to do the work
of a machine.
print "Content-type: text/html\n\n";

print "Hello, world!\n";


open(SENDMAIL, "/usr/sbin/sendmail") or die "Cannot open $sendmail:
$!";

UUODQ: Useless Use of Double Quotes (around the sendmail path).

perldoc -q quoting vars

You probably want to write to the stdin of a running sendmail process,
not read from the file itself. Your open() statement says it wants to
be able to read from the sendmail binary itself.

See perlopentut. You might mean something like:

open SENDMAIL, '| /usr/sbin/sendmail' or die "Error piping to sendmail: $!";
print SENDMAIL "(e-mail address removed)";
^^^^^
Did you mean to interpolate the variable @test in there?

Warnings and strict would have told you.
print SENDMAIL "test subject";
UUODQ

print SENDMAIL "(e-mail address removed)";

Did you mean to interpolate the variable @goodprint in there?

Warnings and strict would have told you.
print SENDMAIL "Content-type: text/plain\n\n";
print SENDMAIL "The content";
close(SENDMAIL);

Ugh. Ugh ugh ugh. Have you seen

perldoc -q "send mail"

??

You should really read the posting guidelines for this group. They're
quite good.

Steve
 
B

Ben Morrow

Quoth Steven Smolinski said:
UUODQ: Useless Use of Double Quotes (around the sendmail path).

perldoc -q quoting vars

That faq has nothing to do with it; indeed, there's nothing anywhere in
the std docs on the merits of "" vs '' where there is no need for
interpolation. It is purely a matter of style.
You probably want to write to the stdin of a running sendmail process,
not read from the file itself. Your open() statement says it wants to
be able to read from the sendmail binary itself.

See perlopentut. You might mean something like:

open SENDMAIL, '| /usr/sbin/sendmail' or die "Error piping to sendmail: $!";

You also need '-oi -t', or it won't sens mail anywhere and a . on a line
in the body will terminate the message.
^^^^^
Did you mean to interpolate the variable @test in there?

You're also missing newlines.

DO NOT CALL SENDMAIL YOURSELF. Use one of the modules: Mail::Sendmail,
if you don't need the fanciness of MIME::Lite.

Ben
 
B

Brian McCauley

Subject: Please help newbie with sendmail problem !

"Please help" and "problem" in subject lines are a pointless waste of
space. Good subject lines are very important. Wasting space in them
is seen as bad manners. Everyone wants their posts to be read - in
some newsgroups this leads to an emphasis arms-race. For this reason
any unwaranted emphasis in subject lines (such as your "!") is also
considered rudness.

The word "newbie" in subject lines will usually be read as "person too
lazy to read the FAQ" because experience has shown us that 95% of
posts with newbie in the subject are repeating FAQs.

Do not get upset me for telling you all this. I'm only trying to help
by telling you how your actions are likely to be percieved.

I should also point out that you are indeed repeating a FAQ. Do not
get upset me for telling you this either. It would be quite
irrational for you to get upset at me because of something _you_ have
done.
open(SENDMAIL, "/usr/sbin/sendmail") or die "Cannot open $sendmail:
$!";

Here you are opening the file /usr/sbin/sendmail for reading. For
details of the Perl open() function see "perldoc -f open".

I would guess that what you actually wanted to do is run
/usr/sbin/sendmail (with appropriate switches) as a subprocess and
pipe stuff to it.
print SENDMAIL "(e-mail address removed)";
print SENDMAIL "test subject";
print SENDMAIL "(e-mail address removed)";
print SENDMAIL "Content-type: text/plain\n\n";

That is not a well formed mail message header. The To header should
start "To:", the subject header "Subject:" and so on. Every header
should end with a newline.

The @ character is meta in double quotes and needs to be escaped.

As MJD famously put it: You can't just make shit up and expect the
computer to know what you mean, retardo!

For an example of correct usage of sendmail please see FAQ "How do I
send mail?". However as many others have pointed out, notwithstanding
the FAQ, you maybe better off not using sendmail directly.

--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
 
S

Steven Smolinski

Ben Morrow said:
That faq has nothing to do with it; indeed, there's nothing anywhere
in the std docs on the merits of "" vs '' where there is no need for
interpolation. It is purely a matter of style.

You are entirely correct. Thanks for that.
DO NOT CALL SENDMAIL YOURSELF. Use one of the modules: Mail::Sendmail,
if you don't need the fanciness of MIME::Lite.

Always a good idea. Unless you're just playing with piped opens for
laughs and giggles.

Steve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top