gmacfadden has asked for the wisdom of the Perl Monks concerning the following question:

The following code results in a nagging little message on the web host which reads as follows:sendmail_with_attachments.cgi: Use of uninitialized value in concatenation (.) or string at sendmail_with_attachments.cgi line 49. I've figured out, that this is a scoping problem. Variables only are scoped (visible) to the block they are in when use strict is in place (as it should be). Please can you tell me how to prevent / correct the scoping error?
#! /usr/bin/perl -wT # use strict; #force all variables to be declared before use use CGI qw(:standard escapeHTML); # import most common gateway inte +rface functions use CGI::Carp qw(warningsToBrowser fatalsToBrowser); #cause all diagno +stics to be sent to browser use Mail::Sendmail; use MIME::Entity; print header; print start_html (-title => "email"); my $from = qq~"Me" <me\@here.com>~; my $to = qq~"You" <you\@there.com>~; my $cc = qq~"Him" <him\@overthere.com>~; my $bcc = qq~bccguy\@where.com>~; $ENV{PATH} = "/usr/sbin"; open (MAIL, "|/usr/sbin/sendmail -t") or &dienice("Can't fork for send +mail: $!\n"); print "Testing Mail::Sendmail version $Mail::Sendmail::VERSION&nbsp&nb +sp&nbsp&nbsp\n\n"; print "\n\nDefault server: $Mail::Sendmail::mailcf +g{smtp}->[0]&nbsp&nbsp&nbsp&nbsp\n\n"; my $top = MIME::Entity->build(Type => "multipart/mixed", From => "$from", To => "$to", Cc => "$cc", Bcc => "$bcc", Subject => "two attachment email"); $top->attach (Type =>"text/html", Encoding => "quoted-printable", Data => [ "<p><font size='3' face='Times' color='black'>HTML test:</font>\n\n", "<p><a href='http://www.anyoldsomethingforurl.com'> any old URL</a>\n\ +n", "<p><img src='http://www...../images/image1.jpg' height='361' width='2 +50' alt='any old image'>\n\n" ]); $top->attach (Path =>"/home/..../public_html/images/p +ower.pps", Type => "application/vnd.ms-powerpoint" +, Encoding => "base64", ); $top->attach (Path =>"/home/..../public_html/images/i +mage2.jpg", Type => "image/jpg", Encoding => "base64", ); $top->print(\*MAIL); print "\n\n\$Mail::Sendmail::log says:&nbsp&nbsp $Mail::Sendmail::log\ +n"; close(MAIL); print end_html; exit (0);

Replies are listed 'Best First'.
Re: scoping problem with Mail::Sendmail
by afresh1 (Hermit) on Oct 15, 2008 at 20:32 UTC

    From what I can tell from the docs of Mail::Sendmail, $Mail::Sendmail::log is only set after a send.

    $Mail::Sendmail::log A summary that you could write to a log file after each send

    However, you are using open (MAIL, "|/usr/sbin/sendmail -t") instead of sendmail(%mail) so $Mail::Sendmail::log is never set.

    You might want to check out How do I send mail? and pick which method you actually want to use. If you do choose Mail::Sendmail, I would suggest reading the docs again.

    l8rZ,
    --
    andrew