Hi All,

Finally, a newsgroup where I haven't got a clue (most of the time) what you 
lot are talking about!

Anyway, above statement proving my newbie status so I need help with :

Retrieve email addresses from 'email_address' field in 'users' database.
Send out email from email.txt file to all those addresses.

Seems simple , and I can do it no problem by reteiving the email addresses 
from another addresses.txt file
but not from the database. It is obviously the syntax that is wrong, but 
being new to perl I can't figure
it out.

Can someone point me as to what is wrong with this :-

------------------------------------------------------------------------------------------------------------
#!/usr/bin/perl
use CGI::Carp qw(fatalsToBrowser);
use CGI qw(:standard);
use DBI;
$|=1;


open(MESSAGE, "/home/site/public_html/cgi-bin/email.txt") or die "cannot 
open message: $!";
flock(MESSAGE, 2) or die "cannot lock message exclusively: $!";
my @msgfile = <MESSAGE>;
close (MESSAGE) or die "cannot close message file: $!";


my ($dbh, $sth, @row);
$dbh = open_dbi();
my $sth = $dbh->prepare("SELECT email_address FROM users");
$sth->execute();
while(@row = $sth->fetchrow_array){
$address = $row[0];
chomp($address);
open (SENDMAIL, "|/usr/sbin/sendmail -t") or die "cannot open sendmail: $!";
print SENDMAIL "To:$address\n";
print SENDMAIL "From: [EMAIL PROTECTED]";
print SENDMAIL "Subject: ITgazette $address\n\n";
print SENDMAIL @msgfile;
}

sub open_dbi
{
my $host = 'localhost';
my $db = 'databasename';
my $db_user = 'username';
my $db_password = 'password';
my $dbh = DBI->connect("dbi:mysql:$db:$host", "$db_user", "$db_password",
{RaiseError => 0, PrintError => 0} )
or err_trap("Cannot connect to the database");
return $dbh;
}# end: open_dbi


sub err_trap
{
my $error_message = shift(@_);
die "$error_message\n
ERROR: $DBI::err ($DBI::errstr)\n";
}# end: err_trap

$sth->finish;
$dbh->disconnect();

print "Location: http://sitename/index.php\n\n";;

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

It does not produce an error message, it just does not send the emails 
out,but it does redirect to the location.

Thanks for your help,



Gav...



-- 
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.308 / Virus Database: 266.8.1 - Release Date: 23/03/2005

Reply via email to