Click to See Complete Forum and Search --> : hellllppppp!


Danny
01-24-2003, 02:02 AM
I am trying to retrive a e-mail address from a file, input the address into my script so that I can use sendmail. I can get the address but sendmail doesn't want to send it.

Help. Here is the code.

open (data,"$webfile2") || die "Can't Open $webfile2: $!\n";
@data = <data>;
close (data);
$fig = '\@';
($idnumber, $realname, $username) = split(/,/, $data[1]);
($user, $name) = split(/@/, $username);
open (file,">$webfile3");
print file "$user$fig$name";
close (file);

open (file,"$webfile3");
@file = <file>;
close (file);
$rename = $file[0];
$recipients = $rename;
if ($mail eq'1'){
open (MAIL,"|$mailprog -t") || die "Can't open $mailprog!\n";
print MAIL "To: $recipients\n";
print MAIL "From: $fromsender\n";
print MAIL "Subject: $subject\n\n";

Nedals
01-24-2003, 02:58 PM
$mail is not set in this script.

Does $mail eq '1' ????

Danny
01-24-2003, 07:41 PM
Yes, MAIL is set to 1

Nedals
01-24-2003, 08:12 PM
I meant the variable, $mail, not the file handle, MAIL

The script as shown has syntax errors, so it will not work as shown. (no closing brace on if statement)

Try this to make sure the mail section works.
$recipients = "<your email address>";
$fromsender = "<your email address>";
open (MAIL,"|$mailprog -t") || die "Can't open $mailprog!\n";
print MAIL "To: $recipients\n";
print MAIL "From: $fromsender\n";
print MAIL "Subject: Test message\n";
print MAIL "Here's my test message\n";
close MAIL; # not closed in your script.

Danny
01-24-2003, 08:30 PM
Yes $mail is set to 1. I just provided a small amount of the code.

The script works fine if $recipients = "danny@email.net";
I need to script to read the file $webfile3, which it does. Then read the data, it does this, then close, it does. The data that is stored in this file has about 150 line, with each line as below.
1,danny name,danny@ltw.net
2,dan crumpton,dan@ltw.net
3,pam,pam@ltw.net

etc... to 150

I need to split out the e-mail address and then use sendmail to send an email.

Thanks

Danny

Nedals
01-24-2003, 09:42 PM
first post
I can get the address but sendmail doesn't want to send it.
last post
The script works fine if $recipients = "danny@email.net";So what's the problem?
I'm guessing: do you want to send all 150 emails?

# 'data' used for file handle AND data in your code!!!!
open (FIL,"$webfile2") || die "Can't Open $webfile2: $!\n";
@data = <FIL>; # 1,danny name,danny@ltw.net
close (FIL);

foreach $line (@data) {
chop $line; # to get rid of the return char
($idnumber, $realname, $address) = split(/,/,$line);
# if valid address set $mail = 1 here
if ($mail eq '1'){
open (MAIL,"|$mailprog -t") || die "Can't open $mailprog!\n";
print MAIL "To: $address\n";
print MAIL "From: $fromsender\n";
print MAIL "Subject: $subject\n";
print MAIL "$message\n";
close MAIL;
}
}
exit;

I don't know what the '$webfile3' stuff is all about.
Good luck!

jeffmott
01-24-2003, 10:19 PM
Originally posted by nedals
chop $line; # to get rid of the return char
You should use chomp to maintain portability.