- # do something if it doesnt work....
- carp "Error sending mail: empty basket" if !defined($iso2709);
- carp "Error sending mail: $Mail::Sendmail::error" if $Mail::Sendmail::error;
- $template->param( error => 1 );
+ try {
+ # if you want to use the KohaAdmin address as from, that is the default no need to set it
+ my $email = Koha::Email->create({
+ to => $email_add,
+ reply_to => $email_replyto,
+ subject => $subject,
+ });
+ $email->header( 'X-Abuse-Report' => C4::Context->preference('KohaAdminEmailAddress') );
+ $email->text_body( $THE_body );
+ $email->attach(
+ Encode::encode( "UTF-8", $iso2709 ),
+ content_type => 'application/octet-stream',
+ name => 'basket.iso2709',
+ disposition => 'attachment',
+ );
+ my $library = $patron->library;
+ $email->transport( $library->smtp_server->transport );
+ $email->send_or_die;
+ $template->param( SENT => "1" );
+ }
+ catch {
+ carp "Error sending mail: $_";
+ $template->param( error => 1 );
+ };