Hi again:

This is my first attempt at trying to pull info from a
database ... but this is my goal:

A few days ago, I was having problems emailing a list of
users ('documentation about perl / email' ... thanks to
Brett and Jenda for the pointers) and I got to thinking,
"Why not go directly to the database, get the list of users
and append \@domain.com at the end and send the message on
it's way?"

In my current script, however, I'm trying to figure out how
to email myself the result of a select statement from a database.

I think I'm shooting myself with a water pistol repeatedly.

[code]

#!/usr/bin/perl

# Attempting to edit this so that email can be
# set to user community (from users table) without
# needing to get a list of users in a text file 
# and THEN emailing them

# created 14 Dec 01 -X

use CGI qw(:standard);
use Pg;
require "/var/www/hminclude.pl";

$conn=dbOpen("dbname=database");

# hopefully, this get my column of email addresses

$result=doquery('Email Community',"
SELECT   email
FROM     users
WHERE    email ~* '[a-z]'
ORDER BY upper(email) ");

# set the date

open DATE, "date |";
$date=<DATE>;
chop $date;

# should be the address of sender and users

$addr='[EMAIL PROTECTED]';
$users=$result;
#$message=param('message');



$boundary='!*@&#^$% Apache web server MIME boundary %$^#&@*!';


open MAIL, "|/usr/lib/sendmail -oi -t -odq "
        || print "no sendmail\n";
print MAIL <<EOF
From: "Apache Webserver" <admin\@domain.com>
To: $addr
Date: $date
Subject: Apache mailing list request
Mime-Version: 1.0
Content-type: multipart/mixed;
        Boundary="$boundary"
Content-Disposition: inline

--$boundary
ontent-type: text/html; charset=us-ascii
Content-Disposition: inline

This is a list or message that would go to the list
of users if we need to send them something.

For your reference, the query executed is shown below:
$users

EOF
;
close(MAIL) || print "can't close mail\n";
print "mail has been sent\n";

__END__

[/code]


The SQL part works.  The mail part works.  But I'm not pulling (or trapping)
the data that I want.  The only thing I get is
a message that says:

[message]

This is a list or message that would go to the list
of users if we need to send them something.

For your reference, the query executed is shown below:
`PG_results=SCALAR(0x81a82a0)`

[/message]

How does that work?  I don't understand how to query and have 
perl KEEP the data in some variable for me to print (or use) later.
I'm not even sure how to check to see if I'm even connecting properly.

By the way, I'm sorta looking at examples and attempting to 'learn
as I go' ... yeah, I know.  I need a better method of learning ...

TIA

-X

Reply via email to