Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Mac OS X > trying to send email from CGI script

trying to send email from CGI script
Thread Tools
Mac Elite
Join Date: Feb 2000
Location: RTP, NC
Status: Offline
Reply With Quote
May 24, 2009, 05:12 PM
 
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]"); }
24" iMac 3.06GHz Intel Core 2 Duo, 4GB RAM, 500GB drive
MacBook Air 11.6", 4GB RAM, 128GB drive
iPhone 4 (AT&T)
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 01:47 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2