Gunnar Hjalmarsson wrote:

Werner Otto wrote:

I would try changing those to full paths. It's not advisable to
rely on an assumption about the working directory. Optionally you
can set the working directory with the chdir() function.


I have changed the path to the full path concerning the files attachments. Still it doesn't work. Is it not got something to do
with the fact that its called as part of CGI?


Yeah, obviously.

You should find out what the web server's error log has to tell you
about it.

If you don't get any error messages, another theory is that it has
something to do with the configuration of the mail server. You could
for instance try to change

    my $mail_host = 'smtp.dcs.kcl.ac.uk';

to

    my $mail_host = 'localhost';

I can't see that when it works from the command line, now I have to change the smtp details?

Here is the full script again.

#!/usr/bin/perl

use CGI qw(:standard);

use lib "/home/staff/wot/public_html/perl/MIME-Lite-3.01_04/lib/";
use MIME::Lite;
use Net::SMTP;

print "Content-type: text/html\n\n";

open(test123, ">>/home/staff/wot/public_html/perl/test.csv") or die ("File test.csv could not be opened for writing");

$surname = param("surname");
$name    = param("forename");
$email   = param("email");

print "<p><b>The following details have been captured by our system\n</b></p>";
print "<p><b>Surname:</b>$surname\n</p>";
print "<p><b>Name:</b>$name\n</p>";
print "<p><b>Email:</b>$email</p>";


flock(test, 2);
seek(test, 0, 2);

print test123 "$surname,$name,$email\n";

close(test);

my $from_address = '[EMAIL PROTECTED]';
my $to_address = '[EMAIL PROTECTED]';
my $mail_host = 'smtp.dcs.kcl.ac.uk';

my $subject = 'Test Subject';
my $message_body = "Attachment file(s) test";

my $my_file_gif = '/home/staff/wot/public_html/perl/logo.gif';
my $your_file_gif = '/home/staff/wot/public_html/perl/logo.gif';
my $my_file_zip = '/home/staff/wot/public_html/perl/running.pdf';
my $your_file_zip = '/home/staff/wot/public_html/perl/running.pdf';

$msg = MIME::Lite->new (
 From => $from_address,
 To => $to_address,
 Subject => $subject,
 Type =>'multipart/mixed'
) or die "Error creating multipart container: $!\n";

$msg->attach (
 Type => 'TEXT',
 Data => $message_body
) or die "Error adding the text message part: $!\n";

$msg->attach (
  Type => 'image/gif',
  Path => $my_file_gif,
  Filename => $your_file_gif,
  Disposition => 'attachment'
) or die "Error adding $file_gif: $!\n";

$msg->attach (
  Type => 'application/zip',
  Path => $my_file_zip,
  Filename => $your_file_zip,
  Disposition => 'attachment'
) or die "Error adding $file_zip: $!\n";

MIME::Lite->send('smtp', $mail_host, Timeout=>60);
$msg->send;


-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to