First off, about the snippet itself -- you're reinventing the wheel here, and doing it poorly. First off, you're assuming that the system running this has sendmail installed and working, and that the binay is in /usr/sbin/sendmail. Secondly, you're using the shell unneccessarly, which can create security problems. However, there are many modules available that do this well: Mail::Sender and Net::SMTP, for example.
Secondly, however, PM is all about communication around the world, so please write in English as much as possible, so the maximum possible number of people can understand your cdoe, and use it, or help you to improve it, as approprate.
Warning: Unless otherwise stated, code is untested. Do not use without understanding. Code is posted in the hopes it is useful, but without warranty. All copyrights are relinquished into the public domain unless otherwise stated. I am not an angel. I am capable of error, and err on a fairly regular basis. If I made a mistake, please let me know (such as by replying to this node).
| [reply] |
OK !
I could rewrite my function ?
#!/usr/bin/perl
use strict;
use warnings;
use Mail::Sender;
our $sender = new Mail::Sender {smtp => 'smtp.yourdomain.com', from =>
+ 'your.address@yourdomain.com'};
sub EnviaEmail {
my ($mail, $subject, $msg, $file) = @_;
$sender->MailFile({to => '$mail', subject => '[$subject]', msg
+=> "\n$msg\n", file => '$file'});
return;
}
...
| [reply] [d/l] |
Watch your quotes! :-) First of ... variables are not interpolated in singlequotes. Therefore instead of the '[$subject]' you should have used "[$subject]". Second you should not enclose variables in quotes unless you need to add something to them. Therefore the '$mail' should not be "$mail" but just $mail.
Jenda
Always code as if the guy who ends up maintaining your code
will be a violent psychopath who knows where you live.
-- Rick Osborne
Edit by castaway: Closed small tag in signature
| [reply] [d/l] [select] |