I've got a web tool that I use at work, and lately I'm running out of disk space and needing to monitor it. I want to set up the CGI script to check the free space and email me if it's low.
I have a personal setup on my iMac at home (10.5.6) and the actual server is currently an Xserve running 10.4.11. I generally code at home, then copy to the server when ready. (I haven't tried this on the server yet.)
I've got the disk space part working. But I've tried various Perl/CGI methods for sending email and nothing seems to happen... no error, no email, no logs I can find for clues.
I tried straight up sendmail from Terminal, but same thing... nothing at all. (I may have screwed it up... do you use Ctrl-D to end and send?)
What log can I look at to see what happened? Do I need to enable this somewhere? And how does this work, exactly? All I'm doing is spec'ing the To, From, Subject and Body... currently I'm testing using my work email and Yahoo email, but nothing is working. (I'm setting To and From to be the same address... not sure what else to use for From.)
Samples that are failing. Note that "log()" is a function I use for debugging.
Code:
sub sendEmailNotice()
{
my $subject = $_[0];
my $body = $_[1];
$to='myacct@yahoo.com';
$from='myacct@yahoo.com';
if ( open(MAIL, "|/usr/sbin/sendmail -t") )
{
## Mail Header
print MAIL "To: $to\n";
print MAIL "From: $from\n";
print MAIL "Subject: $subject\n\n";
## Mail Body
print MAIL $body;
print MAIL "\n\n";
close(MAIL);
&log("MAIL SENT: $subject [$body]");
}
else {
&log("MAIL NOT SENT: $subject [$body]");
}
}
This fails, too.
Code:
sub sendEmailNotice2()
{
my $subject = $_[0];
my $body = $_[1];
use Mail::Send;
my $mail = Mail::Send->new;
$mail->to('myacct@yahoo.com');
$mail->subject($subject);
my $fh = $mail->open();
print $fh $body;
$fh->close;
&log("MAIL SENT: $subject [$body]");
}