Please help newbie with sendmail problem !

Discussion in 'Perl Misc' started by Jake Gourd, Jun 4, 2004.

  1. Jake Gourd

    Jake Gourd Guest

    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 "";
    print SENDMAIL "test subject";
    print SENDMAIL "";
    print SENDMAIL "Content-type: text/plain\n\n";
    print SENDMAIL "The content";
    close(SENDMAIL);
    Jake Gourd, Jun 4, 2004
    #1
    1. Advertising

  2. Jake Gourd

    Jack Challen Guest

    Jake Gourd wrote:
    > 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
    Jack Challen, Jun 4, 2004
    #2
    1. Advertising

  3. Jake Gourd

    Paul Lalli Guest

    On Fri, 4 Jun 2004, Jake Gourd wrote:

    > 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 "";


    You need to either backslash the @, or (preferably) use single quotes
    instead of double:
    print SENDMAIL '';

    > print SENDMAIL "test subject";
    > print SENDMAIL "";


    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
    Paul Lalli, Jun 4, 2004
    #3
  4. Jake Gourd <> wrote:
    >
    > 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 "";

    ^^^^^
    Did you mean to interpolate the variable @test in there?

    Warnings and strict would have told you.

    > print SENDMAIL "test subject";


    UUODQ

    > print SENDMAIL "";


    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
    Steven Smolinski, Jun 4, 2004
    #4
  5. Jake Gourd

    Ben Morrow Guest

    Quoth Steven Smolinski <>:
    > > open(SENDMAIL, "/usr/sbin/sendmail") or die "Cannot open $sendmail:
    > > $!";

    >
    > 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.

    > > print SENDMAIL "";

    > ^^^^^
    > 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

    --
    Although few may originate a policy, we are all able to judge it.
    - Pericles of Athens, c.430 B.C.
    Ben Morrow, Jun 4, 2004
    #5
  6. (Jake Gourd) writes:

    > 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 "";
    > print SENDMAIL "test subject";
    > print SENDMAIL "";
    > 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\\
    Brian McCauley, Jun 4, 2004
    #6
  7. Ben Morrow <> wrote:
    >
    > Quoth Steven Smolinski <>:
    >> > open(SENDMAIL, "/usr/sbin/sendmail") or die "Cannot open $sendmail:
    >> > $!";

    >>
    >> 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 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
    Steven Smolinski, Jun 6, 2004
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. KK
    Replies:
    2
    Views:
    556
    Big Brian
    Oct 14, 2003
  2. sugapablo
    Replies:
    0
    Views:
    2,153
    sugapablo
    Sep 21, 2007
  3. Andrzej Adam Filip
    Replies:
    0
    Views:
    4,083
    Andrzej Adam Filip
    Mar 31, 2008
  4. Ninou
    Replies:
    0
    Views:
    181
    Ninou
    Mar 4, 2004
  5. Replies:
    3
    Views:
    87
Loading...

Share This Page