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

I tring to send e-mail through SendMail this is what I have but it isn't working
$mailp="/usr/sbin/sendmail"; $email="somthing\@hotmail.com"; open(MAIL, "|$mailp -t"); print MAIL "To:$email<$email> \n"; print MAIL "From:$email<$email>\n"; print MAIL "Subject:$email testing\n"; print MAIL "Somthing Somthing Somthing Somthing\n"; close(MAIL);
Can some one tell me what I'm doing wrong
That is the correct path to sendmail on my server.

edited: Sun Jan 26 17:11:31 2003 by jeffa - reformatted code to hug left side

Replies are listed 'Best First'.
(jeffa) Re: Help with SendMail
by jeffa (Bishop) on Jan 26, 2003 at 17:14 UTC
    I don't notice anything wrong with your code offhand, other then you aren't using strict ... checking the return value of open is always a Good Thing™, so you might want to add or die "can't open sendmail". Hmmm, how about trying the CPAN module MIME::Lite instead?
    use strict; use warnings; use MIME::Lite; my $msg = MIME::Lite->new( To => $email, From => $email, Subject => 'Subject:$email testing', Data => 'Somthing Somthing Somthing Somthing', ); $msg->send('sendmail');

    jeffa

    L-LL-L--L-LL-L--L-LL-L--
    -R--R-RR-R--R-RR-R--R-RR
    B--B--B--B--B--B--B--B--
    H---H---H---H---H---H---
    (the triplet paradiddle with high-hat)
    
Re: Help with SendMail
by blokhead (Monsignor) on Jan 26, 2003 at 18:26 UTC
    You need two \n's after the Subject: line, to differentiate headers from the body. Apart from that, jeffa has wise advice -- checking the return value of open is a good idea, and using a module to send email is probably better. When you start using form input for email addresses, you can get into trouble faster with a raw sendmail pipe.

    blokhead

Re: Help with SendMail
by Limbic~Region (Chancellor) on Jan 26, 2003 at 19:34 UTC
    Well.....

    Aside from the fact that you should take the suggestions others have provided about using a module that makes your life easier, not assuming your open works, scoping variables, using strict/warnings - you really should RTM when it comes to reinventing wheels.

    For instance - the man page on sendmail
    RFCs governing SMTP (821,822, etc)

    The proper syntax for ending a message (or so I believe) is to send a single period on a line all by itself.

    Cheers - L~R

      The proper syntax for ending a message (or so I believe) is to send a single period on a line all by itself.

      This is not true for MIME messages, only for some (command-line) mail programs.
        This is not true for MIME messages, only for some (command-line) mail programs.

        Which is exactly what the anonymous monk is trying to use - Sendmail from the command line.

Re: Help with SendMail
by ibanix (Hermit) on Jan 26, 2003 at 23:24 UTC
    Perl has a plethora of modules that will do mail for you:

    Mime::Lite as mentioned before
    Mail::Mailer
    Mail::Bulkmail
    Mail::Sender (my personal favorite)

    have a look at all the Mime and Mail modules, you're sure to find what you want.

    Cheers,
    ibanix

    $ echo '$0 & $0 &' > foo; chmod a+x foo; foo;
Re: Help with SendMail
by Marza (Vicar) on Jan 26, 2003 at 18:31 UTC

    Did you try like the Doc said?

    use Mail::Sendmail; %mail = ( To => 'you@there.com', From => 'me@here.com', Message => "This is a very short message" ); sendmail(%mail) or die $Mail::Sendmail::error; print "OK. Log says:\n", $Mail::Sendmail::log;

    I agree with jeffa mime::lite is good!

    Update

    Okay my execuse is being sick and drugged up. Not a good combo for problem solving. Thanks for spotting that iguaanodon

      Anonymous_Monk isn't using Mail::Sendmail, (s)he is piping output directly to the sendmail program. However, I agree with those who suggest using a module, and I like Mail::Sendmail as well as MIME::Lite.