Any and all help is appreciated. Thank you in advance.
OK, I am a relative novice to Programming, Perl, CGI, CGI.pm and
MIME::Lite. As suggested by others on this list I'm using MIME::Lite.
I've written the below code with part of a MIME::Lite example copied.
I've put the whole code here because I'm not sure what to leave out.
The actual problem occurs at during the sub main section where the
line reads: my $filepath = $ARGV[0] || die "missing path to
FILE\n"; The output is a blank screen, no error messages, just
nothing happens.
#!/usr/local/bin/perl -w
use strict;
use CGI;
use lib '/path/to/lib';
use MIME::Lite;
use Getopt::Std;
#PRINT HTML HEADER
print "Content-type: text/html \n\n";
#GET VARIABLES
my $query=new CGI;
my $recipient=$query->param('recipient');
my $sender=$query->param('sender');
my $subject=$query->param('subject');
my $message=$query->param('message');
my $file=$query->param('file');
#PRINT HTML HEADER
print "Content-type: text/html \n\n";
#------------------------------
#TESTS FOR IMAGE/FILE TYPES
my $content_type;
if ( $file =~ /\.gif$/i )
{
$content_type = "image/gif";
}
elsif ( $file =~ /\.jpg$/i || $file=~/\.jpeg$/i || $file=~/\.jpe$/i)
{
$content_type = "image/jpeg";
}
elsif ( $file =~ /\.html$/i || $file =~ /\.htm$/i )
{
$content_type = "text/html";
}
elsif ( $file =~ /\.txt$/i || $file =~ /\.dat$/i || $file =~ /\.doc$/i)
{
$content_type = "text/plain";
}
else
{
print "<html><head><title>Alert!</title></head><body>\n";
print "<h3>Alert! I'm sorry that file type is not recognized or
allowed.</h3>\n";
print "<p>Please push the back button on your browser and try again.</p>";
print "</body></html>";
exit(0);
}
&main;
print "<html><head><title>Thank You!</title></head>\n";
print "<body><h3>Thank you for your ad submission!</h3>\n";
print "</body></html>";
#------------------------------
sub main {
my %opts;
### Get options:
getopts('', \%opts) or die "usage error\n";
my $filepath = $ARGV[0] || die "missing path to FILE\n";
### Create message:
my $msg = MIME::Lite->new(From => "$sender",
To => "$recipient",
Subject => "$subject",
Type => 'TEXT',
Data => "$message");
$msg->attach(
Path => "$file",
Filename => "$file",
Type => "$content_type");
### Read data:
open IN, "<$filepath/$file" or die "open $filepath: $!\n";
binmode IN;
my @data;
local $_ = '';
while (read(IN, $_, 1024)) {
push @data, $_;
}
close IN;
$msg->send ("sendmail") || die "Can't find the path to mailprog.\n";
}
*** Teresa Raymond
*** http://www.mariposanet.com
*** [EMAIL PROTECTED]