diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index 0ccc07b837a..6cc739139ec 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -254,52 +254,60 @@ if ($HTTP_POST_VARS["action"] == 'confirm_delete' && $HTTP_POST_VARS["confirm"] if ($action == 'send') { $fac = new Facture($db,"",$facid); - $fac->fetch($facid); - $soc = new Societe($db, $fac->socidp); - - $file = FAC_OUTPUTDIR . "/" . $fac->ref . "/" . $fac->ref . ".pdf"; - - if (file_exists($file)) + if ( $fac->fetch($facid) ) { + $soc = new Societe($db, $fac->socidp); - $sendto = $soc->contact_get_email($HTTP_POST_VARS["destinataire"]); - $sendtoid = $HTTP_POST_VARS["destinataire"]; - - if (strlen($sendto)) + $file = FAC_OUTPUTDIR . "/" . $fac->ref . "/" . $fac->ref . ".pdf"; + + if (file_exists($file)) { + $sendto = $soc->contact_get_email($HTTP_POST_VARS["destinataire"]); + $sendtoid = $HTTP_POST_VARS["destinataire"]; - $subject = "Facture $fac->ref"; - $message = "Veuillez trouver ci-joint la facture $fac->ref\n\nCordialement\n\n"; - $filename = "$fac->ref.pdf"; - - $replyto = $HTTP_POST_VARS["replytoname"] . " <".$HTTP_POST_VARS["replytomail"] .">"; - - $mailfile = new CMailFile($subject,$sendto,$replyto,$message,$file, "application/pdf", $filename); - - if ( $mailfile->sendfile() ) - { - - $sendto = htmlentities($sendto); + if (strlen($sendto)) + { + $subject = "Facture $fac->ref"; + $message = "Veuillez trouver ci-joint la facture $fac->ref\n\nCordialement\n\n"; + $filename = $fac->ref.".pdf"; - $sql = "INSERT INTO ".MAIN_DB_PREFIX."actioncomm (datea,fk_action,fk_soc,note,fk_facture, fk_contact,fk_user_author, label, percent) VALUES (now(), '9' ,'$fac->socidp' ,'Envoyée à $sendto','$fac->id','$sendtoid','$user->id', 'Envoi Facture par mail',100);"; - - if (! $db->query($sql) ) + $replyto = $HTTP_POST_VARS["replytoname"] . " <".$HTTP_POST_VARS["replytomail"] .">"; + + $mailfile = new CMailFile($subject,$sendto,$replyto,$message,$file, "application/pdf", $filename); + + if ( $mailfile->sendfile() ) { - print $db->error(); - print "
$sql
"; - } + + $sendto = htmlentities($sendto); + + $sql = "INSERT INTO ".MAIN_DB_PREFIX."actioncomm (datea,fk_action,fk_soc,note,fk_facture, fk_contact,fk_user_author, label, percent) VALUES (now(), '9' ,'$fac->socidp' ,'Envoyée à $sendto','$fac->id','$sendtoid','$user->id', 'Envoi Facture par mail',100);"; + + if (! $db->query($sql) ) + { + print $db->error(); + print "$sql
"; + } + } + else + { + print "!! erreur d'envoi