Gossamer Forum
Home : General : Perl Programming :

Mail Alert script. What did I do wrong?

Quote Reply
Mail Alert script. What did I do wrong?
Hi Paul and all,

Can you check what did I do wrong? I got a tons of mail when I test it Frown

Code:
#!/usr/dist/share/perl


use Time::Local;
$today = timelocal(localtime);

# Full path to sendmail on your system
$mailprog = "|/usr/lib/sendmail -t";

sub date_to_unix {

my $date = @_[0];
my ($time);

my ($mon, $day, $year) = split(/\//, $_[0]);
my ($hour, $min, $sec) = split(/:/, $_[0]);
unless ($day and $mon and $year) { return undef; }
use Time::Local;
eval {
$mon = int($mon) - 1; $day = int($day); $year = int($year) - 1900;
# $time = timelocal($hour, $min, $sec, $day, $mon, $year);
$time = timelocal(0,0,0,$day,$mon,$year);
};
if ($@) { return undef; } # Could return 0 if you want.
return ($time);
}






open (DATA,"default.db") || die ("Can't Open data File \n");
@data=<DATA>;
close DATA;


foreach $line (@data) {


($ID, $name, $email , $sfc, $startdate, $expiredate, $reason)=split(/\|/,$line);


my $epdate = &date_to_unix($date);

if ($epdate <= ($today - 604800)) { # more than 7 days {


open (Alertmail, "$mailprog") || &cgierr("Can't start mail program");
print Alertmail "To:$email,you.me\@test.com\n";

print Alertmail "From: you.me\@test.com\n";
print Alertmail "Subject: $sfc is expired . \n\n";
print Alertmail "Hi $name,\n\n";
print Alertmail "$sfc is expired more than 7 days. Please remove it out of database or update the expire date";

print Alertmail "-" x 75 . "\n\n";


print Alertmail "Regards,\n\n";
print Alertmail "Tigger, \n\n";
print Alertmail "\n\n";

}
close (Alertmail);

}

I don't have root access to down load lib or mod so that's why it look messy here Blush

Please help me to make it works better.

Thank you for shareing.
Quote Reply
Re: [britneythuyduong] Mail Alert script. What did I do wrong? In reply to
 

Last edited by:

Paul: Jan 10, 2003, 8:33 AM
Quote Reply
Re: [britneythuyduong] Mail Alert script. What did I do wrong? In reply to
Mmm...try adding some debugging prints in there...also, comment out the part that actuall does the sending for a bit...untiul you can work out where it is going whacko, and why its sending you all those emails Wink

Also, here you have;

Code:
open (Alertmail, "$mailprog") || &cgierr("Can't start mail program");

Where is &cgierr defined? You know how the || die stuff works?

Either use something like;

Code:
open (Alertmail, "$mailprog") || &sub_name("Can't start mail program");

or

Code:
open (Alertmail, "$mailprog") || die "Can't start mail program";

...this one will only show an error to the browser if you have use CGI::Carp qw(fatalsToBrowser); enabled Wink

Hope that helps a little :)

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Paul] Mail Alert script. What did I do wrong? In reply to
Paul, you may wanna re-read what he said ;) He said he got tons of emails...not tons of errors....lol Tongue

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Mail Alert script. What did I do wrong? In reply to
I'm assuming "he" is a "she" Wink

Quote:
You know how the || die stuff works?

You do though right?....that's why you failed to die with anything useful such as the contents of $! Tongue

Quote:
this one will only show an error to the browser if you have use CGI::Carp qw(fatalsToBrowser); enabled

Well for the sake of being picky, that isn't true as I could define a custom die wrapper :)

Last edited by:

Paul: Jan 10, 2003, 8:37 AM
Quote Reply
Re: [Paul] Mail Alert script. What did I do wrong? In reply to
heheh Paul...at least its working better than passing the error to a non-existing sub routine Wink

Quote:
Well for the sake of being picky, that isn't true as I could define a custom die wrapper :)

LOL...you get more and more picky every day ;) I'm talking about general usage...

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Mail Alert script. What did I do wrong? In reply to
Code:

{
local $SIG{__DIE__} = sub {
print "Content-type: text/html\n\n";
print "I barfed: $_[0]";
exit;
};
die "All over the floor!";
}

That prints (to the browser) "I barfed: All over the floor!" - I didn't use Carp :)

Last edited by:

Paul: Jan 10, 2003, 9:41 AM
Quote Reply
Re: [Paul] Mail Alert script. What did I do wrong? In reply to
Yeah, and how many 'new' programmers do you see using $SIG{__DIE__} and 'local' in their first few scripts? Wink

Oh sorry, I bet you did :p

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!