tags:

views:

123

answers:

3

I have developed a database with the use of Perl CGI with C++. I have problem in sending the results to mail. I used the following code:

print LOG "[",`date`,"] Sending mail to $email\n";  
system (qq{mutt -s "MMM" -a $zip_file $email < $job_id});  
if ( $? == 0) {  
        print LOG "[",`date`,"] Sending mail to $email :: SUCCESS ::\n";  
}else {
        print LOG "[",`date`,"] Sending mail to $email :: FAILED ::\n";
}

close LOG;
A: 

What error do you see?

In particular, what is in $! ?

It could be that the CGI process cannot execute Mutt - how about logging the script's userid and current path:

print LOG getpwuid($<) . "\n";
print LOG $ENV{PATH} . "\n";

Is the location of Mutt's executable in the path, and does that user (probably 'apache') have permission to execute it?

Nick Dixon
A: 

You may also want to look at using the Net::SMTP module, which will communicate directly with the mail server instead of depending on system tools. This is a more portable solution, and avoids the whole permissions issue.

Aquatoad
+1  A: 

See my Troubleshooting Perl CGI scripts. If that doesn't solve your problem, it will at least help you develop your question so you can get more help.

You might also like brian's Guide to Solving Any Perl Problem.

brian d foy