diff --git a/htdocs/commande/fiche.php b/htdocs/commande/fiche.php
index 359a7bce538..b275c893b45 100644
--- a/htdocs/commande/fiche.php
+++ b/htdocs/commande/fiche.php
@@ -315,6 +315,111 @@ if($_GET['action'] == 'builddoc')
commande_pdf_create($db, $_GET['id'],$commande->modelpdf);
}
+/*
+ * Envoi de la commande par mail
+ */
+if ($_POST['action'] == 'send')
+{
+ $langs->load('mails');
+ $commande= new Commande($db);
+ if ( $commande->fetch($_POST['id']) )
+ {
+ $orderref = sanitize_string($commande->ref);
+ $file = $conf->commande->dir_output . '/' . $orderref . '/' . $orderref . '.pdf';
+ if (is_readable($file))
+ {
+ $soc = new Societe($db, $commande->soc_id);
+ if ($_POST['sendto'])
+ {
+ // Le destinataire a été fourni via le champ libre
+ $sendto = $_POST['sendto'];
+ $sendtoid = 0;
+ }
+ elseif ($_POST['receiver'])
+ {
+ // Le destinataire a été fourni via la liste déroulante
+ $sendto = $soc->contact_get_email($_POST['receiver']);
+ $sendtoid = $_POST['receiver'];
+ }
+
+ if (strlen($sendto))
+ {
+ $from = $_POST['fromname'] . ' <' . $_POST['frommail'] .'>';
+ $replyto = $_POST['replytoname']. ' <' . $_POST['replytomail'].'>';
+ $message = $_POST['message'];
+ if ($_POST['action'] == 'send')
+ {
+ $subject = $langs->trans('Order').' '.$commande->ref;
+ $actiontypeid=3;
+ $actionmsg ='Mail envoyé par '.$from.' à '.$sendto.'.
';
+ if ($message)
+ {
+ $actionmsg.='Texte utilisé dans le corps du message:
';
+ $actionmsg.=$message;
+ }
+ $actionmsg2='Envoi commande par mail';
+ }
+
+ $filepath[0] = $file;
+ $filename[0] = $commande->ref.'.pdf';
+ $mimetype[0] = 'application/pdf';
+ if ($_FILES['addedfile']['tmp_name'])
+ {
+ $filepath[1] = $_FILES['addedfile']['tmp_name'];
+ $filename[1] = $_FILES['addedfile']['name'];
+ $mimetype[1] = $_FILES['addedfile']['type'];
+ }
+ // Envoi de la commande
+ $mailfile = new CMailFile($subject,$sendto,$from,$message,$filepath,$mimetype,$filename,$sendtocc);
+ if ($mailfile->sendfile())
+ {
+ $msg='