
Scot
Novice
Apr 19, 2007, 1:16 PM
Post #1 of 7
(1807 views)
|
A few glitches in email script
|
Can't Post
|
|
Hi, I have a file with some data like so: Scot|admin@link-exchangers.com|Thu Apr 19 03:39:19 EDT 2007 | Scot|support@webwizsoftware.com|Thu Apr 19 03:41:05 EDT 2007 | Scot|support@link-exchangers.com|Thu Apr 19 14:17:14 EDT 2007 | The program used to create this writes 2 newlines \n\n after the 2007| I wrote a program which reads in this data, and also reads in data from a text file (below) and the program is supposed to send an email to everyone on the list. This is my optin email program. Right now if you run the program, it says it is emailing all three addresses, because I made it print "Email sent to: " and then the name of the email address in the sendmail sub. If you run the script http://www.cash-for-structured-settlements.net/cgi-bin/eratesemail.cgi you'll see what I mean. I guess my loop isn't working since it's only sending an email to the one of the first line. The other 2 records aren't getting email. I don't understand why after sending the first email, the output says it sent to nobody two more times with no email address before sending to the next email address. I understand that there are 3 items per record and then it hits a newline character. I'm confused about this. Here is the output right now: Email sent to : admin@link-exchangers.com Email sent to : Email sent to : Email sent to : support@webwizsoftware.com Email sent to : Email sent to : Email sent to : support@link-exchangers.com Email sent to : Email sent to :
#!/usr/bin/perl my $email=''; my $name=''; my $subject="Interest Rate Updates from Pacific West Capital"; my $i=0; # get rates open(FILE,"rates.txt") || die ("Can't open file!"); my @rates=<FILE>; close FILE; my $r30c=$rates[1]; my $r15c=$rates[3]; my $r51c=$rates[5]; my $r30j=$rates[7]; my $r15j=$rates[9]; my $r51j=$rates[11]; my $date = `date`; my $message="Interest Rates for $date \n\n\nConforming 30 year fixed: $r30c\nConforming 15 year fixed: $r15c\nConforming 5/1 ARM: $r51c\n\nJumbo 30 year fixed: $r30j\nJumbo 15 year fixed: $r15j\nJumbo 5/1 ARM : $r51j\n\n\n"; # get members list open(FILE,"../www/mortgage-pros.com/erates/members.txt") || die ("Can't open file!"); my @emaillist=<FILE>; close FILE; print "Content-type: text/html\n\n"; my $i=0; for (@emaillist) { chomp; my @emaillistrow=split('\|',$_); $name= $emaillistrow[0]; $email= $emaillistrow[1]; # print $emaillistrow[0]; # print $emaillistrow[1]; # print $emaillistrow[2]; # print $emaillist[0]; # print length($emaillist[0]); # print $emaillist[1] ; # print $emaillist[2]; # exit; emailrates($name,$email) } sub emailrates { my $sendto=$_[0]; my $fname=$_[1]; unless (open(MAIL, "|/usr/lib/sendmail -t")) { print "error.\n"; warn "Error starting sendmail: $!"; } print MAIL "From: info\@mortgage-pros.com\n"; print MAIL "To: $sendto\n"; print MAIL "Subject: $subject\n\n"; print MAIL "Hello $fname,\n\n"; print MAIL $message; print MAIL "Best Regards,\n\nPacific West Capital"; close(MAIL) || warn "Error closing mail: $!"; print "Email sent to : $email\n"; } Here is the contents of rates.txt: C30 6.0 C15 5.75 C5/1 6.125 J30 6.375 J15 6.25 J5/1 6.125
|