Hi everyone,
The problem is really simple. When i try to send a message with this
function with a wrong sender email address, my script just stops...
as an exemple : sender address [EMAIL PROTECTED] the error message
is - user not found on this server.... and the script stops.
-------------------------------------------------------------------------------------------------------------------------------------
use Mail::Sendmail;
use MIME::Lite;
use Email::Valid;
sub send_mail {
my ($mailto, $mailfrom, $sujet, $body_file, $file_send, $cc) = @_;
my $body_msg = "";
my $mail_err;
if ((Email::Valid->address( -address => $mailto, -mxcheck => 1 ) ?
'1' : '0') eq '0' ) {
($mailto, $mailerr, $mailrom) = ($mailfrom, $mailto,
"[EMAIL PROTECTED]");
$sujet = "Destination invalide / Invalid destination $mailerr" .
$sujet;
if ((Email::Valid->address( -address => $mailto, -mxcheck => 1 )
? '1' : '0') eq '0' ) {
$sujet = "ERROR: $mailto $mailfrom " . $sujet;
$mailto = "[EMAIL PROTECTED]";
}
}
if ( $cc eq "1" ) {
### Create a new multipart message:
$msg = MIME::Lite->new(
From =>$mailfrom,
To =>$mailto,
Cc =>$mailfrom,
Subject =>$sujet,
Type =>'multipart/mixed'
);
}
else {
### Create a new multipart message:
$msg = MIME::Lite->new(
From =>$mailfrom,
To =>$mailto,
Subject =>$sujet,
Type =>'multipart/mixed'
);
}
open (FIC, $body_file) or die("Le fichier body $body n'existe pas\n");
while (<FIC>) {
$body_msg .= $_;
}
### Add parts (each "attach" has same arguments as "new"):
$msg->attach(Type =>'TEXT',
Data =>$body_msg
);
$msg->attach(Type =>'application/pdf',
Path =>$file_send,
Filename =>$file_name,
Disposition => 'attachment'
);
### Send in the "best" way (the default is to use "sendmail"):
MIME::Lite->send('smtp', "mail.xxxxxxxx.com", 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>