Hi,

I looked through 'Categorized Questions and Answers' and also searched this site and others, and I haven't come up with an answer.

I am trying to pluck email addresses from a mysql db to send reminder letters.

My code:
#!/usr/bin/perl -w use strict; use CGI; use DBI; # Declare and initialize variables my $host = 'hostname'; my $db = 'dbname'; my $db_user = 'dbuser'; my $db_password = 'mypassword'; my $dbh = DBI->connect("dbi:mysql:$db:$host", "$db_user", "$db_passwor +d" or die "Couldn't connect: $DBI::errstr"); my $sth = $dbh->prepare("SELECT * FROM feRegistrants" or die "Couldn't + prepare SQL: $DBI::errstr"); $sth->execute or die "Couldn't execute statement: " . $sth->errstr; my @data; while (@data = $sth->fetchrow_array()) { my $email = $data[5]; my $fname = $data[2]; print "Content-type:text/html\n\n"; open(MAIL, "|/usr/lib/sendmail -t -n") || die "Unable to open sendmail +"; print MAIL "To: $email \nFrom: the server\n"; print MAIL "Subject: Subject\n"; print MAIL<<EOF; Dear $fname,\n You have registered for *** workshop on the *** of ****, 2005. Please +let us know if you are unable to attend by emailing us at *** or call +ing us at ***. We look forward to working with you. EOF close(MAIL); } $dbh->disconnect();
The error messages I get are:
Useless use of string in void context at ./email2.cgi line 16.
Useless use of string in void context at ./email2.cgi line 16.
Can't connect(ch@ngeme), no database driver specified and DBI_DSN env var not set at ./email2.cgi line 16

Any suggestions?


In reply to no database driver specified and DBI_DSN env var not set by patricia_e

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.