toonski has asked for the wisdom of the Perl Monks concerning the following question:

Okay, monks, this code won't work:
open(MAIL,"|/usr/sbin/sendmail -oi -t"); print MAIL "To: myemail@myemail.com\n"; print MAIL "From: serveremail@theserver.com\n"; print MAIL "Subject: Blah\n\n"; print MAIL "Put main message in here.\n" close (MAIL);
Now, according my hosting's FAQ, /usr/sbin/sendmail -oi -t is the correct path to use, and the unix commandline mail should work, but it still doesnt. I dont have mail::sendmail. What are my options?

Replies are listed 'Best First'.
Re: Mailer not mailing.
by b10m (Vicar) on Jan 22, 2004 at 18:44 UTC
    Okay, monks, this code won't work:

    Obviously, you don't have relatives who call you on a daily basis with questions like: "My computer ain't working, how to fix it?", or you would know that you don't give much info. I'd be interested in what exactly doesn't work (read: what error do you get?)

    Try the following and post the errors:

    open(MAIL,"|/usr/sbin/sendmail -oi -t") || die "Can't open sendmail: $ +!"; print MAIL "To: myemail\@myemail.com\n"; print MAIL "From: serveremail\@theserver.com\n"; print MAIL "Subject: Blah\n\n"; print MAIL "Put main message in here.\n" close (MAIL);

    Update: I should clarify the code a bit for fast readers ;) I added the || die "Can't open sendmail: $!"; part, to make sure the problem is not there. Also I added two backslashes in front of the @-signs to escape these. Otherwise, Perl will thing "myemail.com" and "theserver.com" are arrays. HTH

    --
    b10m
Re: Mailer not mailing.
by Limbic~Region (Chancellor) on Jan 22, 2004 at 18:40 UTC
    toonski,
    Two things pop out at me:
    open (MAIL, "|/usr/sbin/sendmail -oi -t") or die $!; # check to see i +f a success print MAIL 'To: myemail@myemail.com\n'; # double quotes i +nterpolate @myemail as a variable
    You don't provide any errors so I am assuming that you do not have warnings turned on or that you are checking the return code of your open statement.

    You could always install Mail::Sendmail. In case you are wondering how to do that without root privelages - it's a FAQ

    Cheers - L~R

      Thank you for your quick response. I added your suggestions, but the results are still the same. it acts like it sent it and nothing is sent. here is the updated, full, code.
      #!/usr/bin/perl use strict; use warnings; use CGI ":all"; use CGI::Carp qw(fatalsToBrowser set_message); BEGIN { sub handle_errors { my $msg = shift; print "<h1>ERROR</h1><br>"; print "$msg" } set_message(\&handle_errors); } open(MAIL,'|/usr/sbin/sendmail -oi -t') or die $!; print MAIL 'To: myemail\@myemail.com\n'; print MAIL 'From: serveremail\@theserver.com\n'; print MAIL 'Subject: Blah\n\n'; print MAIL 'Put main message in here.\n'; close (MAIL); print header, "hi";
        toonski,
        You combined b10m and my suggestions. Either use single quotes which won't interpolate or escape the ampersands in the double quotes.

        it acts like it sent it and nothing is sent

        What do you mean? Are you saying there is no error messages but you do not receive the email? If that is the case, have you tried doing checking the mailq? Have you tried running the same process from the command line? You are not giving enough feedback to indicate what the problem is.

        Cheers - L~R