Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

SENDMAIL problem!

by Anonymous Monk
on Apr 06, 2005 at 12:00 UTC ( #445268=perlquestion: print w/ replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

My funtion
sub send_mail { my ($send_from,$subject,$message) = @_; open(SENDMAIL, "|/usr/sbin/sendmail -oi ") or return ("<span class='darkredbold'>Sorry you email coudn't be s +end. $!</span>"); print SENDMAIL "From: ".$send_from; print SENDMAIL "To: aaa\@aaa.com"; print SENDMAIL "Subject:".$subject; print SENDMAIL "\n"; print SENDMAIL $message; close(SENDMAIL) or return ("<span class='darkredbold'>Sorry you em +ail coudn't be send. $!</span>"); return("<span class='darkbluebold'>Email sended. Thanks for your o +pinion.</span>"); }
Doesn't work!!!

Comment on SENDMAIL problem!
Download Code
Re: SENDMAIL problem!
by cog (Parson) on Apr 06, 2005 at 12:04 UTC
    And exactly how doesn't it work?
Re: SENDMAIL problem!
by BazB (Priest) on Apr 06, 2005 at 12:05 UTC

    Define "doesn't work".

    You should avoid using a piped open to sendmail. Try using one of the many modules on CPAN that provide a simple, well tested, abstracted and portable solution, such as Net::SMTP.


    If the information in this post is inaccurate, or just plain wrong, don't just downvote - please post explaining what's wrong.
    That way everyone learns.

      I don't have access to server, i can't run the CPAN :(

      You should avoid using a piped open to sendmail.

      As a matter of interest why? Using the mail injection capabilities of sendmail (or other MTA - most provide a similar interface) is reliable and simple: the MTA will perform all the queuing, error recovery and MX lookup for you whereas with (e.g) Net::SMTP you have to do all of these things for yourself plus you are subject to the exigencies of the networks condition, if a local MTA cannot send a message because the MX host is unreachable then it will try again until it can send it (or the retry times out), if you don't provide this functionality yourself with one of the modules then the message at best won't get sent.

      Of course I'm not suggesting that one shouldn't use the modules either, just taking issue with the assertion that they are in all cases superior than using the MTA directly.

      This has been done to death over the years and I am sure you can find plenty of arguments and counter arguments in the archives of CLPM.

      /J\

Re: SENDMAIL problem!
by gellyfish (Monsignor) on Apr 06, 2005 at 12:06 UTC

    Firstly you don't specify how it doesn't work - does it throw an error or simply not send any mail.

    Secondly I think you want /usr/sbin/sendmail -oi -t if you are expecting sendmail to parse the recipient address from the headers of the message you feed it.

    /J\

Re: SENDMAIL problem!
by Anonymous Monk on Apr 06, 2005 at 12:08 UTC
    Doesn't send email. i will try the -t option.
Re: SENDMAIL problem!
by sh1tn (Priest) on Apr 06, 2005 at 12:10 UTC
    ... open(SENDMAIL, "|/usr/sbin/sendmail -oi ") or warn "cannot open pipe $!" and return ("...") ...


Re: SENDMAIL problem!
by Anonymous Monk on Apr 06, 2005 at 12:21 UTC
    i allready use     or warn "cannot open pipe $!" and return(...) and -t option still doesn't send the email :(....

      You are missing the "\n" off the header lines - sendmail will not be able to parse the headers to get the To: address.

      /J\

Re: SENDMAIL problem!
by Anonymous Monk on Apr 06, 2005 at 14:21 UTC
    Well know it's sending email :)
    sub send_mail { my ($send_from,$subject,$message) = @_; open(SENDMAIL, "|/usr/sbin/sendmail -oi -t") or warn "cannot open pipe $!" and return ("<span class='darkredbol +d'>Sorry you email coudn't be send. $!</span>"); print SENDMAIL "From: $send_from \n"; print SENDMAIL "To: aaa\@aaa.com \n"; print SENDMAIL "Subject: $subject \n"; print SENDMAIL "\n"; print SENDMAIL "$message \n"; close(SENDMAIL) or return ("<span class='darkredbold'>Sorry you em +ail coudn't be send. $!</span>"); return("<span class='darkbluebold'>Email sended.Contact. Thanks fo +r your opinion.</span>"); }
    i add  \n and change
     print SENDMAIL "From: ".$send_from;
    for
    print SENDMAIL "From: $send_from \n"; Thanks for the help you guys are great, one more time thanks.
Re: SENDMAIL problem!
by NateTut (Deacon) on Apr 06, 2005 at 15:12 UTC
    And now a word from the grammar Nazi:

    Change:
    "Sorry you email coudn't be send."
    To:
    "Sorry your e-mail couldn't be sent."

    And:
    "Email sended. Thanks for your opinion."

    To:
    "Email sent. Thank you for your opinion."



    And now back to your regularly scheduled node...

      I fail to see how that would prevent the program from sending mail :-p

      /J\

        It might indeed send mail, but this way the user will clearly know that the mail has been sent, or not!

        I'm not trying to bust the OP's chops, English is obviously not his primary language, I'm just trying to help him make his code a bit better.

        The Grammer Nazi

        P.S. I am HTML challenged, what is the tag for a tab character?
Re: SENDMAIL problem!
by Anonymous Monk on Apr 06, 2005 at 16:19 UTC
    "I'm not trying to bust the OP's chops, English is obviously not his primary language, I'm just trying to help him make his code a bit better." And i thank you ;), it's true my primary language isn't english but i thinks that it isn't soo bad :( , ok not perfect ... but with time and practice and with your help it can be better ;)
      One more thing, in internet explorer my site is fine, but if i try in Mozilla Firefox, some problems happens, like spaces and stuff like that. Can you give a direction to see the diferences between browsers?
        You don't indicate you've done so, so you may wish to validate your html against w3c ( html validator ) standards. There's also a .css validator, if you're using stylesheets.

        But there are many other questions here: what vers. each browser? how is site hosted (windows, linux, ???? Did you use proper upload mode to prevent *n*x vs. DOS line-ending issues? address of site? description of where (in what page) discrepancies occur?

        Point is, you have details that the Monastery does not. We can best help you -- even if no more than offering the likes of my first paragraph -- if we have sufficient info to offer decent help.

        And with all that said, why don't you register a name, and join the madness?

      I'm sure you speak English better than I speak your language! You manage to communicate your ideas which is the objective after all.

      I'm glad you took my suggestions in the spirit in which they were intended.

      The Grammar Nazi

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://445268]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (5)
As of 2014-09-19 02:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (129 votes), past polls