I have been struggling with a script but cant make it work.

There are two Sales Executives called :

Randal  &   Tom

Randal's  Email ID is > [EMAIL PROTECTED]

Tom's Email ID is > [EMAIL PROTECTED]

Below are the contents of a text  file called           prospects.txt

You'll observe that there are six lines for Randal and six lines for Tom.

The second last field is the date field in mm/dd/yy and the last field is time in 
EPOCH seconds 
as per date in second last field.

Today is July 16 so when script should be executed it should send line1, line3, line5 
to Randal on [EMAIL PROTECTED]

Similarly it should send line7, line9, line11 to Tom on [EMAIL PROTECTED]

NOW THE PROBLEM => Though it is sending email but only line5 to Randal  and   line11 
to  Tom

I cant figure out and solve this ! 

I look forward to your help on this

Thanks & regards

Sunish Kapoor

-------------------------------------------------prospects.txt below

[EMAIL PROTECTED]/10/2004%%Services & Trade%%Mr Sarathi%%Manager%%7711455%%Renewal - 
Gold Membership%%75%%7/16/2004%%1089961200
[EMAIL PROTECTED]/10/2004%%Abu Zaki%%Mr Jauqim%%I T Manager%%7730611%%Gold Membership 
+ Banner%%125%%7/10/2004%%1089403200
[EMAIL PROTECTED]/10/2004%%Medical Supplies%%Ms Priya%%Asst Manager%%7715771%%Gold 
Membership + Banner%%125%%7/16/2004%%1089961200
[EMAIL PROTECTED]/10/2004%%Intl Stationery%%Mr Khalid 
Shanfari%%Manager%%701302%%Platinum membership%%210%%7/12/2004%%1089576000
[EMAIL PROTECTED]/10/2004%%Salah Cooler%%Mr. Vijay Nirula%%General 
Manager%%701721%%Gold membership%%75%%7/16/2004%%1089961200
[EMAIL PROTECTED]/10/2004%%Insurance Center%%Mr Ravi Shankar%%General 
Manager%%792923%%Gold Membership%%75%%7/12/2004%%1089604800
[EMAIL PROTECTED]/10/2004%%Al Batinah Int SAOG%%Mr Fairuz%%General 
Manager%%783388%%Gold Membership%%75%%7/16/2004%%1089961200
[EMAIL PROTECTED]/10/2004%%Qatar Airways%%Mr Ali Khalid Shanfari%%Area 
manager%%785843%%Gold Membership%%75%%7/12/2004%%1089576000
[EMAIL PROTECTED]/10/2004%%Asha Ent (cont)%%Mr. Domnic %%A/c Manager%%568591%%Gold 
Membersahip%%75%%7/16/2004%%1089961200
[EMAIL PROTECTED]/10/2004%%Renaissance%%Mr Arindam Roy%%Manager%%796636%%Platinum 
Membership%%210%%7/10/2004%%1089403200
[EMAIL PROTECTED]/10/2004%%Muscat General Ent%%Mr Joseph%%Manager%%700667%%Gold 
Membership%%75%%7/16/2004%%1089961200
[EMAIL PROTECTED]/10/2004%%Global Finance Investment%%Mr. 
Milind%%Manager%%7716960%%Gold Membership%%75%%7/20/2004%%1090296000

-------------------------Below is the SCRIPT-------------------

#!c:/perl/bin/perl 

use Time::Local; 

$sendmail = "c:/sendmail/sendmail.exe"; #where sendmail lives on my WindowsXP 

$file = "c:/prospects.txt"; 

$epoch = timelocal($mday, $month, $year, (localtime)[3,4,5]); 

&curtime; 

sub curtime 

{ 

($a,$b,$c)=(localtime(time))[3,4,5]; 

$c = $c + 1900; 

$thetime = timelocal(0,0,0,$a,$b,$c); 

return($thetime); 

} 

%hash=(); 

open (FILE, "<$file"); 

while ($line = <FILE>) 

{ 

chomp; 

@fields = split (/%%/, $line); 

$hash{$fields[1]}= 
[$fields[0],$fields[2],$fields[3],$fields[4],$fields[5],$fields[6],$fields[7],$fields[8],$fields[9]]
 if ($fields[10] == "$epoch" ) ; 

} 

close (FILE); 

&mail_report; 

sub mail_report 

{


foreach my $key (keys %hash) { 
open (MAIL, "|$sendmail -t"); 
print MAIL "Return-Path: [EMAIL PROTECTED]"; 
print MAIL "To: <$hash{$key}[0]>\n"; 
print MAIL "From: [EMAIL PROTECTED]"; 
print MAIL "Subject:$key >> Your Prospects Report\n"; 
print MAIL "Content-Type: text/html\n\n"; 
print MAIL "<html>\n"; 
print MAIL "<body>\n"; 
print MAIL "<center><h3> $key Your Prospects</h3><hr> 

<table border=1> 
<tr><center> 
<td><center><h3>COMPANY</h3></center></td> 
<td><center><h3>CONTACT</h3></center></td> 
<td><center><h3>TITLE</h3></center></td> 
<td><center><h3>PHONE</h3></center></td> 
<td><center><h3>PROSPECT FOR</h3></center></td> 
<td><center><h3>VALUE</h3></center></td> 
<td><center><h3>EXP DATE</h3></center></td>
</h3></center></tr>"; 

print MAIL"<tr> 

<td><center>$hash{$key}[2]</center></td> 
<td>$hash{$key}[3]</td> 
<td>$hash{$key}[4]</td> 
<td>$hash{$key}[5]</td> 
<td><center>$hash{$key}[6]</center></td> 
<td><center>$hash{$key}[7]</center></td> 
<td><center>$hash{$key}[8]</center></td> 
<td><center>$hash{$key}[9]</center></td>\n"; 

}
print MAIL"</td></tr></table></center>"; 
print MAIL "</body>\n"; 
print MAIL "</html>\n"; 
close (MAIL); 

} 

sleep (1);
print "Content-type: text/html\n\n"; #HTML response 
print "Message Sent\n"; 

-------------------------------------------------------------






Reply via email to