Why does mutt fail when I call it from my Perl CGI script?
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:
p开发者_C百科rint 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;
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.
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?
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.
精彩评论