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

Simple Quick question, sendmail...

my code:
$mail{From} = 'nstouch<nobody@localhost.localdomain>'; $mail{To} = 'administrator <pyrox_pro@hotmai +l.com>'; #$server = 'xx.xx.xx.xx'; BEGIN { $| = 1; print ""; } END {print "not ok 1\n" unless $loaded;} $loaded = 1; if ($server) { $mail{Smtp} = $server; } $mail{Subject} = "NStouch has a message for yo +u..."; #$mail{Subject} = "Mail::Sendmail version $Mai +l::Sendmail::VERSION test"; $mail{Message} .= "Hello, \n "; $mail{Message} .= "\nNStouch wants to notify y +ou that: \n"; $mail{Message} .= "\n [ $dater ][ TEST ON $na +meserver WAS COMPLETED: SERVER DOWN ][ TIME : $us2 Miliseconds ] "; $mail{Message} .= "\n Thanks! \n \n $mailcount +er \n"; # Go send it if (sendmail %mail) { #print "content of \$Mail::Sendmail::l +og:\n$Mail::Sendmail::log\n"; if($Mail::Sendmail::er +ror) { print " \n OH DANG! \n + Senmail Errors \n ";
}

How do I kill the message content? Every time this app sends a message, it includes the previous message as well, this is really driving me insane. After the DNS server failes all day I end up with an email 300 lines on. Do I need to kill this header, or close the mail function?

Thanks in advance.

Replies are listed 'Best First'.
Re: Simple question, sendmail... Kill Previous
by suaveant (Parson) on Sep 24, 2001 at 23:06 UTC
    Change
    $mail{Message} .= "Hello, \n "; #to $mail{Message} = "Hello, \n ";
    if you start by doing .= and there is already data, it will just keep adding to it... using strict and warnings probably would have made you prevent that...

                    - Ant
                    - Some of my best work - Fish Dinner

Re: Simple question, sendmail... Kill Previous
by VSarkiss (Monsignor) on Sep 24, 2001 at 23:07 UTC

    You're constantly appending to your message. Change this line: $mail{Message} .= "Hello, \n"; so it assigns rather than appending: $mail{Message} = "Hello, \n";

    IMHO, a better way would be to use a here-doc:

    $mail{Message} = <<"EOM"; Hello, NSTouch wants to ... EOM # ... if (sendmail %mail) { # ...
    If any variables appear in the text of the here-doc, they'll be interpolated.

    HTH

Re: Simple question, sendmail... Kill Previous
by PyroX (Pilgrim) on Sep 25, 2001 at 00:10 UTC
    well I smacked my fore-head on that one....

    Thanks guys!