Пример #1
0
            // Subject
            $societeName = $conf->global->MAIN_INFO_SOCIETE_NOM;
            if (!empty($conf->global->MAIN_APPLICATION_TITLE)) {
                $societeName = $conf->global->MAIN_APPLICATION_TITLE;
            }
            $subject = $societeName . " - " . $langs->transnoentitiesnoconv("HolidaysCanceled");
            // Content
            $message = $langs->transnoentitiesnoconv("Hello") . " " . $destinataire->firstname . ",\n";
            $message .= "\n";
            $message .= $langs->transnoentities("HolidaysCanceledBody", dol_print_date($cp->date_debut, 'day'), dol_print_date($cp->date_fin, 'day')) . "\n";
            $message .= "- " . $langs->transnoentitiesnoconv("ModifiedBy") . " : " . dolGetFirstLastname($expediteur->firstname, $expediteur->lastname) . "\n";
            $message .= "- " . $langs->transnoentitiesnoconv("Link") . " : " . $dolibarr_main_url_root . "/holiday/fiche.php?id=" . $cp->rowid . "\n\n";
            $message .= "\n";
            $mail = new CMailFile($subject, $emailTo, $emailFrom, $message);
            // Envoi du mail
            $result = $mail->sendfile();
            if (!$result) {
                header('Location: fiche.php?id=' . $_GET['id'] . '&error=mail&error_content=' . $mail->error);
                exit;
            }
            header('Location: fiche.php?id=' . $_GET['id']);
            exit;
        } else {
            // Sinon on affiche le formulaire de demande avec le message d'erreur SQL
            header('Location: fiche.php?id=' . $_GET['id'] . '&error=SQL_Create&msg=' . $cp->error);
            exit;
        }
    }
}
/*
 * View
 /**
  * Send mail with ticket data
  * @param  $email
  * @return int 			<0 if KO; >0 if OK
  */
 public static function sendMail($email)
 {
     global $db, $conf, $langs;
     $function = "sendMail";
     require_once DOL_DOCUMENT_ROOT . '/core/class/CMailFile.class.php';
     if ($email["idTicket"]) {
         $ticket = new Ticket($db);
         $ticket->fetch($email["idTicket"]);
         $subject = $conf->global->MAIN_INFO_SOCIETE_NOM . ': ' . $langs->trans("CopyOfTicket") . ' ' . $ticket->ticketnumber;
         $message = self::FillMailTicketBody($ticket->id);
     }
     if ($email["idFacture"]) {
         $facture = new Facture($db);
         $facture->fetch($email["idFacture"]);
         $subject = $conf->global->MAIN_INFO_SOCIETE_NOM . ': ' . $langs->trans("CopyOfFacture") . ' ' . $facture->ref;
         $message = self::FillMailFactureBody($facture->id);
     }
     if ($email["idCloseCash"]) {
         $subject = $conf->global->MAIN_INFO_SOCIETE_NOM . ': ' . $langs->trans("CopyOfCloseCash") . ' ' . $email["idCloseCash"];
         $message = self::FillMailCloseCashBody($email["idCloseCash"]);
     }
     $from = $conf->global->MAIN_INFO_SOCIETE_NOM . "<" . $conf->global->MAIN_INFO_SOCIETE_MAIL . ">";
     $mailfile = new CMailFile($subject, $email["mail_to"], $from, $message);
     if ($mailfile->error) {
         $mesg = '<div class="error">' . $mailfile->error . '</div>';
         $res = -1;
     } else {
         $res = $mailfile->sendfile();
     }
     return ErrorControl($res, $function);
 }
Пример #3
0
 /**
  *  Check if notification are active for couple action/company.
  * 	If yes, send mail and save trace into llx_notify.
  *
  * 	@param	string	$notifcode		Code of action in llx_c_action_trigger (new usage) or Id of action in llx_c_action_trigger (old usage)
  * 	@param	Object	$object			Object the notification deals on
  *	@return	int						<0 if KO, or number of changes if OK
  */
 function send($notifcode, $object)
 {
     global $user, $conf, $langs, $mysoc, $dolibarr_main_url_root;
     include_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
     dol_syslog(get_class($this) . "::send notifcode=" . $notifcode . ", object=" . $object->id);
     $langs->load("other");
     // Define $urlwithroot
     $urlwithouturlroot = preg_replace('/' . preg_quote(DOL_URL_ROOT, '/') . '$/i', '', trim($dolibarr_main_url_root));
     $urlwithroot = $urlwithouturlroot . DOL_URL_ROOT;
     // This is to use external domain name found into config file
     //$urlwithroot=DOL_MAIN_URL_ROOT;						// This is to use same domain name than current
     // Define some vars
     $application = $mysoc->name;
     //if (! empty($conf->global->MAIN_APPLICATION_TITLE)) $application = $conf->global->MAIN_APPLICATION_TITLE;
     $replyto = $conf->notification->email_from;
     $filename = basename($file);
     $mimefile = dol_mimetype($file);
     $object_type = '';
     $link = '';
     $num = 0;
     if (!in_array($notifcode, array('BILL_VALIDATE', 'ORDER_VALIDATE', 'PROPAL_VALIDATE', 'FICHINTER_VALIDATE', 'ORDER_SUPPLIER_VALIDATE', 'ORDER_SUPPLIER_APPROVE', 'ORDER_SUPPLIER_REFUSE', 'SHIPPING_VALIDATE'))) {
         return 0;
     }
     $oldref = empty($object->oldref) ? $object->ref : $object->oldref;
     $newref = empty($object->newref) ? $object->ref : $object->newref;
     // Check notification per third party
     $sql = "SELECT s.nom, c.email, c.rowid as cid, c.lastname, c.firstname, c.default_lang,";
     $sql .= " a.rowid as adid, a.label, a.code, n.rowid, n.type";
     $sql .= " FROM " . MAIN_DB_PREFIX . "socpeople as c,";
     $sql .= " " . MAIN_DB_PREFIX . "c_action_trigger as a,";
     $sql .= " " . MAIN_DB_PREFIX . "notify_def as n,";
     $sql .= " " . MAIN_DB_PREFIX . "societe as s";
     $sql .= " WHERE n.fk_contact = c.rowid AND a.rowid = n.fk_action";
     $sql .= " AND n.fk_soc = s.rowid";
     if (is_numeric($notifcode)) {
         $sql .= " AND n.fk_action = " . $notifcode;
     } else {
         $sql .= " AND a.code = '" . $notifcode . "'";
     }
     // New usage
     $sql .= " AND s.rowid = " . $object->socid;
     $result = $this->db->query($sql);
     if ($result) {
         $num = $this->db->num_rows($result);
         if ($num > 0) {
             $i = 0;
             while ($i < $num && !$error) {
                 $obj = $this->db->fetch_object($result);
                 $sendto = dolGetFirstLastname($obj->firstname, $obj->lastname) . " <" . $obj->email . ">";
                 $notifcodedefid = $obj->adid;
                 if (dol_strlen($obj->email)) {
                     // Set output language
                     $outputlangs = $langs;
                     if ($obj->default_lang && $obj->default_lang != $langs->defaultlang) {
                         $outputlangs = new Translate('', $conf);
                         $outputlangs->setDefaultLang($obj->default_lang);
                     }
                     switch ($notifcode) {
                         case 'BILL_VALIDATE':
                             $link = '/compta/facture.php?facid=' . $object->id;
                             $dir_output = $conf->facture->dir_output;
                             $object_type = 'facture';
                             $mesg = $langs->transnoentitiesnoconv("EMailTextInvoiceValidated", $newref);
                             break;
                         case 'ORDER_VALIDATE':
                             $link = '/commande/card.php?id=' . $object->id;
                             $dir_output = $conf->commande->dir_output;
                             $object_type = 'order';
                             $mesg = $langs->transnoentitiesnoconv("EMailTextOrderValidated", $newref);
                             break;
                         case 'PROPAL_VALIDATE':
                             $link = '/comm/propal.php?id=' . $object->id;
                             $dir_output = $conf->propal->dir_output;
                             $object_type = 'propal';
                             $mesg = $langs->transnoentitiesnoconv("EMailTextProposalValidated", $newref);
                             break;
                         case 'FICHINTER_VALIDATE':
                             $link = '/fichinter/card.php?id=' . $object->id;
                             $dir_output = $conf->facture->dir_output;
                             $object_type = 'ficheinter';
                             $mesg = $langs->transnoentitiesnoconv("EMailTextInterventionValidated", $object->ref);
                             break;
                         case 'ORDER_SUPPLIER_VALIDATE':
                             $link = '/fourn/commande/card.php?id=' . $object->id;
                             $dir_output = $conf->fournisseur->dir_output . '/commande/';
                             $object_type = 'order_supplier';
                             $mesg = $langs->transnoentitiesnoconv("Hello") . ",\n\n";
                             $mesg .= $langs->transnoentitiesnoconv("EMailTextOrderValidatedBy", $object->ref, $user->getFullName($langs));
                             $mesg .= "\n\n" . $langs->transnoentitiesnoconv("Sincerely") . ".\n\n";
                             break;
                         case 'ORDER_SUPPLIER_APPROVE':
                             $link = '/fourn/commande/card.php?id=' . $object->id;
                             $dir_output = $conf->fournisseur->dir_output . '/commande/';
                             $object_type = 'order_supplier';
                             $mesg = $langs->transnoentitiesnoconv("Hello") . ",\n\n";
                             $mesg .= $langs->transnoentitiesnoconv("EMailTextOrderApprovedBy", $newref, $user->getFullName($langs));
                             $mesg .= "\n\n" . $langs->transnoentitiesnoconv("Sincerely") . ".\n\n";
                             break;
                         case 'ORDER_SUPPLIER_REFUSE':
                             $link = '/fourn/commande/card.php?id=' . $object->id;
                             $dir_output = $conf->fournisseur->dir_output . '/commande/';
                             $object_type = 'order_supplier';
                             $mesg = $langs->transnoentitiesnoconv("Hello") . ",\n\n";
                             $mesg .= $langs->transnoentitiesnoconv("EMailTextOrderRefusedBy", $newref, $user->getFullName($langs));
                             $mesg .= "\n\n" . $langs->transnoentitiesnoconv("Sincerely") . ".\n\n";
                             break;
                         case 'SHIPPING_VALIDATE':
                             $dir_output = $conf->expedition->dir_output . '/sending/';
                             $object_type = 'order_supplier';
                             $mesg = $langs->transnoentitiesnoconv("EMailTextExpeditionValidated", $newref);
                             break;
                     }
                     $ref = dol_sanitizeFileName($newref);
                     $pdf_path = $dir_output . "/" . $ref . "/" . $ref . ".pdf";
                     if (!dol_is_file($pdf_path)) {
                         // We can't add PDF as it is not generated yet.
                         $filepdf = '';
                     } else {
                         $filepdf = $pdf_path;
                     }
                     $subject = '[' . $application . '] ' . $outputlangs->transnoentitiesnoconv("DolibarrNotification");
                     $message = $outputlangs->transnoentities("YouReceiveMailBecauseOfNotification", $application, $mysoc->name) . "\n";
                     $message .= $outputlangs->transnoentities("YouReceiveMailBecauseOfNotification2", $application, $mysoc->name) . "\n";
                     $message .= "\n";
                     $message .= $mesg;
                     if ($link) {
                         $message = dol_concatdesc($message, $urlwithroot . $link);
                     }
                     $mailfile = new CMailFile($subject, $sendto, $replyto, $message, array($file), array($mimefile), array($filename[count($filename) - 1]), '', '', 0, -1);
                     if ($mailfile->sendfile()) {
                         $sql = "INSERT INTO " . MAIN_DB_PREFIX . "notify (daten, fk_action, fk_soc, fk_contact, type, objet_type, objet_id, email)";
                         $sql .= " VALUES ('" . $this->db->idate(dol_now()) . "', " . $notifcodedefid . ", " . $object->socid . ", " . $obj->cid . ", '" . $obj->type . "', '" . $object_type . "', " . $object->id . ", '" . $this->db->escape($obj->email) . "')";
                         if (!$this->db->query($sql)) {
                             dol_print_error($this->db);
                         }
                     } else {
                         $error++;
                         $this->errors[] = $mailfile->error;
                     }
                 } else {
                     dol_syslog("No notification sent for " . $sendto . " because email is empty");
                 }
                 $i++;
             }
         } else {
             dol_syslog("No notification to thirdparty sent, nothing into notification setup for the thirdparty socid = " . $object->socid);
         }
     } else {
         $error++;
         $this->errors[] = $this->db->lasterror();
         return -1;
     }
     // Check notification using fixed email
     if (!$error) {
         foreach ($conf->global as $key => $val) {
             if ($val == '' || !preg_match('/^NOTIFICATION_FIXEDEMAIL_' . $notifcode . '_THRESHOLD_HIGHER_(.*)$/', $key, $reg)) {
                 continue;
             }
             $threshold = (double) $reg[1];
             if ($object->total_ht <= $threshold) {
                 dol_syslog("A notification is requested for notifcode = " . $notifcode . " but amount = " . $object->total_ht . " so lower than threshold = " . $threshold . ". We discard this notification");
                 continue;
             }
             $param = 'NOTIFICATION_FIXEDEMAIL_' . $notifcode . '_THRESHOLD_HIGHER_' . $reg[1];
             $sendto = $conf->global->{$param};
             $notifcodedefid = dol_getIdFromCode($this->db, $notifcode, 'c_action_trigger', 'code', 'rowid');
             if ($notifcodedefid <= 0) {
                 dol_print_error($this->db, 'Failed to get id from code');
             }
             $object_type = '';
             $link = '';
             $num++;
             switch ($notifcode) {
                 case 'BILL_VALIDATE':
                     $link = '/compta/facture.php?facid=' . $object->id;
                     $dir_output = $conf->facture->dir_output;
                     $object_type = 'facture';
                     $mesg = $langs->transnoentitiesnoconv("EMailTextInvoiceValidated", $newref);
                     break;
                 case 'ORDER_VALIDATE':
                     $link = '/commande/card.php?id=' . $object->id;
                     $dir_output = $conf->commande->dir_output;
                     $object_type = 'order';
                     $mesg = $langs->transnoentitiesnoconv("EMailTextOrderValidated", $newref);
                     break;
                 case 'PROPAL_VALIDATE':
                     $link = '/comm/propal.php?id=' . $object->id;
                     $dir_output = $conf->propal->dir_output;
                     $object_type = 'propal';
                     $mesg = $langs->transnoentitiesnoconv("EMailTextProposalValidated", $newref);
                     break;
                 case 'FICHINTER_VALIDATE':
                     $link = '/fichinter/card.php?id=' . $object->id;
                     $dir_output = $conf->facture->dir_output;
                     $object_type = 'ficheinter';
                     $mesg = $langs->transnoentitiesnoconv("EMailTextInterventionValidated", $newref);
                     break;
                 case 'ORDER_SUPPLIER_VALIDATE':
                     $link = '/fourn/commande/card.php?id=' . $object->id;
                     $dir_output = $conf->fournisseur->dir_output . '/commande/';
                     $object_type = 'order_supplier';
                     $mesg = $langs->transnoentitiesnoconv("Hello") . ",\n\n";
                     $mesg .= $langs->transnoentitiesnoconv("EMailTextOrderValidatedBy", $newref, $user->getFullName($langs));
                     $mesg .= "\n\n" . $langs->transnoentitiesnoconv("Sincerely") . ".\n\n";
                     break;
                 case 'ORDER_SUPPLIER_APPROVE':
                     $link = '/fourn/commande/card.php?id=' . $object->id;
                     $dir_output = $conf->fournisseur->dir_output . '/commande/';
                     $object_type = 'order_supplier';
                     $mesg = $langs->transnoentitiesnoconv("Hello") . ",\n\n";
                     $mesg .= $langs->transnoentitiesnoconv("EMailTextOrderApprovedBy", $newref, $user->getFullName($langs));
                     $mesg .= "\n\n" . $langs->transnoentitiesnoconv("Sincerely") . ".\n\n";
                     break;
                 case 'ORDER_SUPPLIER_APPROVE2':
                     $link = '/fourn/commande/card.php?id=' . $object->id;
                     $dir_output = $conf->fournisseur->dir_output . '/commande/';
                     $object_type = 'order_supplier';
                     $mesg = $langs->transnoentitiesnoconv("Hello") . ",\n\n";
                     $mesg .= $langs->transnoentitiesnoconv("EMailTextOrderApprovedBy", $newref, $user->getFullName($langs));
                     $mesg .= "\n\n" . $langs->transnoentitiesnoconv("Sincerely") . ".\n\n";
                     break;
                 case 'ORDER_SUPPLIER_REFUSE':
                     $link = '/fourn/commande/card.php?id=' . $object->id;
                     $dir_output = $conf->fournisseur->dir_output . '/commande/';
                     $object_type = 'order_supplier';
                     $mesg = $langs->transnoentitiesnoconv("Hello") . ",\n\n";
                     $mesg .= $langs->transnoentitiesnoconv("EMailTextOrderRefusedBy", $newref, $user->getFullName($langs));
                     $mesg .= "\n\n" . $langs->transnoentitiesnoconv("Sincerely") . ".\n\n";
                     break;
                 case 'SHIPPING_VALIDATE':
                     $dir_output = $conf->expedition->dir_output . '/sending/';
                     $object_type = 'order_supplier';
                     $mesg = $langs->transnoentitiesnoconv("EMailTextExpeditionValidated", $newref);
                     break;
             }
             $ref = dol_sanitizeFileName($newref);
             $pdf_path = $dir_output . "/" . $ref . "/" . $ref . ".pdf";
             if (!dol_is_file($pdf_path)) {
                 // We can't add PDF as it is not generated yet.
                 $filepdf = '';
             } else {
                 $filepdf = $pdf_path;
             }
             $subject = '[' . $application . '] ' . $langs->transnoentitiesnoconv("DolibarrNotification");
             $message = $langs->transnoentities("YouReceiveMailBecauseOfNotification", $application, $mysoc->name) . "\n";
             $message .= $langs->transnoentities("YouReceiveMailBecauseOfNotification2", $application, $mysoc->name) . "\n";
             $message .= "\n";
             $message .= $mesg;
             if ($link) {
                 $message = dol_concatdesc($message, $urlwithroot . $link);
             }
             // Replace keyword __SUPERVISOREMAIL__
             if (preg_match('/__SUPERVISOREMAIL__/', $sendto)) {
                 $newval = '';
                 if ($user->fk_user > 0) {
                     $supervisoruser = new User($this->db);
                     $supervisoruser->fetch($user->fk_user);
                     if ($supervisoruser->email) {
                         $newval = trim(dolGetFirstLastname($supervisoruser->firstname, $supervisoruser->lastname) . ' <' . $supervisoruser->email . '>');
                     }
                 }
                 dol_syslog("Replace the __SUPERVISOREMAIL__ key into recipient email string with " . $newval);
                 $sendto = preg_replace('/__SUPERVISOREMAIL__/', $newval, $sendto);
                 $sendto = preg_replace('/^[\\s,]+/', '', $sendto);
                 // Clean start of string
                 $sendto = preg_replace('/[\\s,]+$/', '', $sendto);
                 // Clean end of string
             }
             if ($sendto) {
                 $mailfile = new CMailFile($subject, $sendto, $replyto, $message, array($file), array($mimefile), array($filename[count($filename) - 1]), '', '', 0, -1);
                 if ($mailfile->sendfile()) {
                     $sql = "INSERT INTO " . MAIN_DB_PREFIX . "notify (daten, fk_action, fk_soc, fk_contact, type, objet_type, objet_id, email)";
                     $sql .= " VALUES ('" . $this->db->idate(dol_now()) . "', " . $notifcodedefid . ", " . $object->socid . ", null, 'email', '" . $object_type . "', " . $object->id . ", '" . $this->db->escape($conf->global->{$param}) . "')";
                     if (!$this->db->query($sql)) {
                         dol_print_error($this->db);
                     }
                 } else {
                     $error++;
                     $this->errors[] = $mailfile->error;
                 }
             }
         }
     }
     if (!$error) {
         return $num;
     } else {
         return -1 * $error;
     }
 }
Пример #4
0
 /**
  *  Send new password by email
  *
  *  @param	User	$user           Object user that send email
  *  @param	string	$password       New password
  *	@param	int		$changelater	1=Change password only after clicking on confirm email
  *  @return int 		            < 0 si erreur, > 0 si ok
  */
 function send_password($user, $password = '', $changelater = 0)
 {
     global $conf, $langs;
     global $dolibarr_main_url_root;
     require_once DOL_DOCUMENT_ROOT . '/core/class/CMailFile.class.php';
     $msgishtml = 0;
     // Define $msg
     $mesg = '';
     $outputlangs = new Translate("", $conf);
     if (isset($this->conf->MAIN_LANG_DEFAULT) && $this->conf->MAIN_LANG_DEFAULT != 'auto') {
         // If user has defined its own language (rare because in most cases, auto is used)
         $outputlangs->getDefaultLang($this->conf->MAIN_LANG_DEFAULT);
     } else {
         // If user has not defined its own language, we used current language
         $outputlangs = $langs;
     }
     $outputlangs->load("main");
     $outputlangs->load("errors");
     $outputlangs->load("users");
     $outputlangs->load("other");
     $subject = $outputlangs->transnoentitiesnoconv("SubjectNewPassword");
     // Define $urlwithroot
     //$urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root));
     //$urlwithroot=$urlwithouturlroot.DOL_URL_ROOT;		// This is to use external domain name found into config file
     $urlwithroot = DOL_MAIN_URL_ROOT;
     // This is to use same domain name than current
     if (!$changelater) {
         $mesg .= $outputlangs->transnoentitiesnoconv("RequestToResetPasswordReceived") . ".\n";
         $mesg .= $outputlangs->transnoentitiesnoconv("NewKeyIs") . " :\n\n";
         $mesg .= $outputlangs->transnoentitiesnoconv("Login") . " = " . $this->login . "\n";
         $mesg .= $outputlangs->transnoentitiesnoconv("Password") . " = " . $password . "\n\n";
         $mesg .= "\n";
         $url = $urlwithroot . '/';
         $mesg .= $outputlangs->transnoentitiesnoconv("ClickHereToGoTo", $conf->global->MAIN_APPLICATION_TITLE) . ': ' . $url . "\n\n";
         $mesg .= "--\n";
         $mesg .= $user->getFullName($outputlangs);
         // Username that make then sending
     } else {
         $mesg .= $outputlangs->transnoentitiesnoconv("RequestToResetPasswordReceived") . "\n";
         $mesg .= $outputlangs->transnoentitiesnoconv("NewKeyWillBe") . " :\n\n";
         $mesg .= $outputlangs->transnoentitiesnoconv("Login") . " = " . $this->login . "\n";
         $mesg .= $outputlangs->transnoentitiesnoconv("Password") . " = " . $password . "\n\n";
         $mesg .= "\n";
         $mesg .= $outputlangs->transnoentitiesnoconv("YouMustClickToChange") . " :\n";
         $url = $urlwithroot . '/user/passwordforgotten.php?action=validatenewpassword&username='******'', '', 0, $msgishtml);
     if ($mailfile->sendfile()) {
         return 1;
     } else {
         $langs->trans("errors");
         $this->error = $langs->trans("ErrorFailedToSendPassword") . ' ' . $mailfile->error;
         return -1;
     }
 }
Пример #5
0
 /**
  *    	\brief      Check if notification are active for couple action/company.
  * 					If yes, send mail and save trace into llx_notify.
  * 		\param		action		Code of action in llx_c_action_trigger (new usage) or Id of action in llx_c_action_trigger (old usage)
  * 		\param		socid		Id of third party
  * 		\param		texte		Message to send
  * 		\param		objet_type	Type of object the notification deals on (facture, order, propal, order_supplier...). Just for log in llx_notify.
  * 		\param		objet_id	Id of object the notification deals on
  * 		\param		file		Attach a file
  *		\return		int			<0 if KO, or number of changes if OK
  */
 function send($action, $socid, $texte, $objet_type, $objet_id, $file = "")
 {
     global $conf, $langs, $mysoc, $dolibarr_main_url_root;
     $langs->load("other");
     dol_syslog("Notify::send action={$action}, socid={$socid}, texte={$texte}, objet_type={$objet_type}, objet_id={$objet_id}, file={$file}");
     $sql = "SELECT s.nom, c.email, c.rowid as cid, c.name, c.firstname,";
     $sql .= " a.rowid as adid, a.label, a.code, n.rowid";
     $sql .= " FROM " . MAIN_DB_PREFIX . "socpeople as c,";
     $sql .= " " . MAIN_DB_PREFIX . "c_action_trigger as a,";
     $sql .= " " . MAIN_DB_PREFIX . "notify_def as n,";
     $sql .= " " . MAIN_DB_PREFIX . "societe as s";
     $sql .= " WHERE n.fk_contact = c.rowid AND a.rowid = n.fk_action";
     $sql .= " AND n.fk_soc = s.rowid";
     if (is_numeric($action)) {
         $sql .= " AND n.fk_action = " . $action;
     } else {
         $sql .= " AND a.code = '" . $action . "'";
     }
     // New usage
     $sql .= " AND s.rowid = " . $socid;
     dol_syslog("Notify::send sql=" . $sql);
     $result = $this->db->query($sql);
     if ($result) {
         $num = $this->db->num_rows($result);
         $i = 0;
         while ($i < $num) {
             $obj = $this->db->fetch_object($result);
             $sendto = $obj->firstname . " " . $obj->name . " <" . $obj->email . ">";
             $actiondefid = $obj->adid;
             if (dol_strlen($sendto)) {
                 include_once DOL_DOCUMENT_ROOT . '/lib/files.lib.php';
                 $application = $conf->global->MAIN_APPLICATION_TITLE ? $conf->global->MAIN_APPLICATION_TITLE : 'Dolibarr ERP/CRM';
                 $subject = '[' . $application . '] ' . $langs->transnoentitiesnoconv("DolibarrNotification");
                 $message = $langs->transnoentities("YouReceiveMailBecauseOfNotification", $application, $mysoc->name) . "\n";
                 $message .= $langs->transnoentities("YouReceiveMailBecauseOfNotification2", $application, $mysoc->name) . "\n";
                 $message .= "\n";
                 $message .= $texte;
                 // Add link
                 switch ($objet_type) {
                     case 'ficheinter':
                         $link = DOL_URL_ROOT . '/fichinter/fiche.php?id=' . $objet_id;
                         break;
                     case 'propal':
                         $link = DOL_URL_ROOT . '/comm/propal.php?id=' . $objet_id;
                         break;
                     case 'facture':
                         $link = DOL_URL_ROOT . '/compta/facture.php?facid=' . $objet_id;
                         break;
                     case 'order':
                         $link = DOL_URL_ROOT . '/commande/fiche.php?facid=' . $objet_id;
                         break;
                     case 'order_supplier':
                         $link = DOL_URL_ROOT . '/fourn/commande/fiche.php?facid=' . $objet_id;
                         break;
                 }
                 $urlwithouturlroot = preg_replace('/' . preg_quote(DOL_URL_ROOT, '/') . '$/i', '', $dolibarr_main_url_root);
                 if ($link) {
                     $message .= "\n" . $urlwithouturlroot . $link;
                 }
                 $filename = basename($file);
                 $mimefile = dol_mimetype($file);
                 $msgishtml = 0;
                 $replyto = $conf->notification->email_from;
                 $mailfile = new CMailFile($subject, $sendto, $replyto, $message, array($file), array($mimefile), array($filename[sizeof($filename) - 1]), '', '', 0, $msgishtml);
                 if ($mailfile->sendfile()) {
                     $sendto = htmlentities($sendto);
                     $sql = "INSERT INTO " . MAIN_DB_PREFIX . "notify (daten, fk_action, fk_contact, objet_type, objet_id, email)";
                     $sql .= " VALUES (" . $this->db->idate(mktime()) . ", " . $actiondefid . " ," . $obj->cid . " , '" . $objet_type . "', " . $objet_id . ", '" . $this->db->escape($obj->email) . "')";
                     dol_syslog("Notify::send sql=" . $sql);
                     if (!$this->db->query($sql)) {
                         dol_print_error($this->db);
                     }
                 } else {
                     $this->error = $mailfile->error;
                     //dol_syslog("Notify::send ".$this->error, LOG_ERR);
                 }
             }
             $i++;
         }
         return $i;
     } else {
         $this->error = $this->db->error();
         return -1;
     }
 }
                        if (!is_array($val) && !is_object($val)) {
                            $TSearch[] = $prefix . $attr;
                            $TVal[] = $val;
                        }
                    }
                    //Changement de méthode (pas de str_replace) pour éviter les collisions. Exemple avec __PROPAL_ref et __PROPAL_ref_client
                    foreach ($TSearchPropal as $i => $propal_value) {
                        $msg = preg_replace('/' . $propal_value . '\\b/', $TValPropal[$i], $msg);
                    }
                    $msg = preg_replace('/__SIGNATURE__\\b/', $newUser->signature, $msg);
                    $msg = str_replace($TSearch, $TVal, $msg);
                    $TMail[] = $mail;
                    // Construct mail
                    $CMail = new CMailFile($subject, $mail, $conf->global->MAIN_MAIL_EMAIL_FROM, $msg, $filename_list, $mimetype_list, $mimefilename_list, '', '', '', $msgishtml, $conf->global->MAIN_MAIL_ERRORS_TO);
                    // Send mail
                    $CMail->sendfile();
                    if ($CMail->error) {
                        $TErrorMail[] = $CMail->error;
                    } else {
                        _createEvent($db, $user, $langs, $conf, $propal, 0, $conf->global->PROPALAUTOSEND_MSG_SUBJECT, $msg);
                    }
                }
            }
        }
    }
    echo "liste des mails ok : ";
    var_dump($TMail);
    echo "<br />liste des mails en erreur : ";
    var_dump($TErrorMail);
}
function _createEvent(&$db, &$user, &$langs, &$conf, &$propal, $fk_socpeople, $subject, $message, $type = 'thirdparty')
Пример #7
0
 /**
  * testCMailFileText
  *
  * @return void
  */
 public function testCMailFileText()
 {
     global $conf, $user, $langs, $db;
     $conf = $this->savconf;
     $user = $this->savuser;
     $langs = $this->savlangs;
     $db = $this->savdb;
     $localobject = new CMailFile('Test', '*****@*****.**', '*****@*****.**', 'Message txt', array(), array(), array(), '', '', 1, 0);
     $result = $localobject->sendfile();
     print __METHOD__ . " result=" . $result . "\n";
     $this->assertFalse($result);
     // False because mail send disabled
     return $result;
 }
/**
 * 	Send email
 *
 * 	@param	string	$mode					Mode (test | confirm)
 *  @param	string	$oldemail				Old email
 * 	@param	string	$message				Message to send
 * 	@param	string	$total					Total amount of unpayed invoices
 *  @param	string	$userlang				Code lang to use for email output.
 *  @param	string	$oldsalerepresentative	Old sale representative
 * 	@return	int								<0 if KO, >0 if OK
 */
function envoi_mail($mode, $oldemail, $message, $total, $userlang, $oldsalerepresentative)
{
    global $conf, $langs;
    if (getenv('DOL_FORCE_EMAIL_TO')) {
        $oldemail = getenv('DOL_FORCE_EMAIL_TO');
    }
    $newlangs = new Translate('', $conf);
    $newlangs->setDefaultLang(empty($userlang) ? empty($conf->global->MAIN_LANG_DEFAULT) ? 'auto' : $conf->global->MAIN_LANG_DEFAULT : $userlang);
    $newlangs->load("main");
    $newlangs->load("bills");
    $subject = empty($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_SUBJECT) ? $newlangs->trans("ListOfYourUnpaidInvoices") : $conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_SUBJECT;
    $sendto = $oldemail;
    $from = $conf->global->MAIN_MAIL_EMAIL_FROM;
    $errorsto = $conf->global->MAIN_MAIL_ERRORS_TO;
    $msgishtml = -1;
    print "- Send email for " . $oldsalerepresentative . " (" . $oldemail . "), total: " . $total . "\n";
    dol_syslog("email_unpaid_invoices_to_representatives.php: send mail to " . $oldemail);
    $usehtml = 0;
    if (dol_textishtml($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_FOOTER)) {
        $usehtml += 1;
    }
    if (dol_textishtml($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_HEADER)) {
        $usehtml += 1;
    }
    $allmessage = '';
    if (!empty($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_HEADER)) {
        $allmessage .= $conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_HEADER;
    } else {
        $allmessage .= $newlangs->transnoentities("ListOfYourUnpaidInvoices") . ($usehtml ? "<br>\n" : "\n") . ($usehtml ? "<br>\n" : "\n");
        $allmessage .= $newlangs->transnoentities("NoteListOfYourUnpaidInvoices") . ($usehtml ? "<br>\n" : "\n");
    }
    $allmessage .= $message . ($usehtml ? "<br>\n" : "\n");
    $allmessage .= $langs->trans("Total") . " = " . price($total, 0, $newlangs, 0, 0, -1, $conf->currency) . ($usehtml ? "<br>\n" : "\n");
    if (!empty($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_FOOTER)) {
        $allmessage .= $conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_FOOTER;
        if (dol_textishtml($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_FOOTER)) {
            $usehtml += 1;
        }
    }
    $mail = new CMailFile($subject, $sendto, $from, $allmessage, array(), array(), array(), '', '', 0, $msgishtml);
    $mail->errors_to = $errorsto;
    // Send or not email
    if ($mode == 'confirm') {
        $result = $mail->sendfile();
        if (!$result) {
            print "Error sending email " . $mail->error . "\n";
            dol_syslog("Error sending email " . $mail->error . "\n");
        }
    } else {
        print "No email sent (test mode)\n";
        dol_syslog("No email sent (test mode)");
        $mail->dump_mail();
        $result = 1;
    }
    if ($result) {
        return 1;
    } else {
        return -1;
    }
}
/**
 * 	Send email
 *
 * 	@param	string	$mode			Mode (test | confirm)
 *  @param	string	$oldemail		Target email
 * 	@param	string	$message		Message to send
 * 	@param	string	$total			Total amount of unpayed invoices
 *  @param	string	$userlang		Code lang to use for email output.
 *  @param	string	$oldtarget		Target name
 * 	@return	int						<0 if KO, >0 if OK
 */
function envoi_mail($mode, $oldemail, $message, $total, $userlang, $oldtarget)
{
    global $conf, $langs;
    if (getenv('DOL_FORCE_EMAIL_TO')) {
        $oldemail = getenv('DOL_FORCE_EMAIL_TO');
    }
    $newlangs = new Translate('', $conf);
    $newlangs->setDefaultLang(empty($userlang) ? empty($conf->global->MAIN_LANG_DEFAULT) ? 'auto' : $conf->global->MAIN_LANG_DEFAULT : $userlang);
    $newlangs->load("main");
    $newlangs->load("bills");
    $subject = empty($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_SUBJECT) ? $newlangs->trans("ListOfYourUnpaidInvoices") : $conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_SUBJECT;
    $sendto = $oldemail;
    $from = $conf->global->MAIN_MAIL_EMAIL_FROM;
    $errorsto = $conf->global->MAIN_MAIL_ERRORS_TO;
    $msgishtml = -1;
    print "- Send email to '" . $oldtarget . "' (" . $oldemail . "), total: " . $total . "\n";
    dol_syslog("email_unpaid_invoices_to_customers.php: send mail to " . $oldemail);
    $usehtml = 0;
    if (dol_textishtml($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_FOOTER)) {
        $usehtml += 1;
    }
    if (dol_textishtml($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_HEADER)) {
        $usehtml += 1;
    }
    $allmessage = '';
    if (!empty($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_HEADER)) {
        $allmessage .= $conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_HEADER;
    } else {
        $allmessage .= "Dear customer" . ($usehtml ? "<br>\n" : "\n") . ($usehtml ? "<br>\n" : "\n");
        $allmessage .= "Please, find a summary of the bills with pending payments from you." . ($usehtml ? "<br>\n" : "\n") . ($usehtml ? "<br>\n" : "\n");
        $allmessage .= "Note: This list contains only unpaid invoices." . ($usehtml ? "<br>\n" : "\n");
    }
    $allmessage .= $message . ($usehtml ? "<br>\n" : "\n");
    $allmessage .= $langs->trans("Total") . " = " . price($total, 0, $userlang, 0, 0, -1, $conf->currency) . ($usehtml ? "<br>\n" : "\n");
    if (!empty($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_FOOTER)) {
        $allmessage .= $conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_FOOTER;
        if (dol_textishtml($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_FOOTER)) {
            $usehtml += 1;
        }
    }
    $mail = new CMailFile($subject, $sendto, $from, $allmessage, array(), array(), array(), '', '', 0, $msgishtml);
    $mail->errors_to = $errorsto;
    // Send or not email
    if ($mode == 'confirm') {
        $result = $mail->sendfile();
        if (!$result) {
            print "Error sending email " . $mail->error . "\n";
            dol_syslog("Error sending email " . $mail->error . "\n");
        }
    } else {
        print "No email sent (test mode)\n";
        dol_syslog("No email sent (test mode)");
        $mail->dump_mail();
        $result = 1;
    }
    unset($newlangs);
    if ($result) {
        return 1;
    } else {
        return -1;
    }
}
/**
 * 	Send email
 *
 * 	@param	string	$oldemail	Old email
 * 	@param	string	$message	Message to send
 * 	@param	string	$total		Total amount of unpayed invoices
 * 	@return	int					<0 if KO, >0 if OK
 */
function envoi_mail($oldemail,$message,$total)
{
    global $conf,$langs;

    $subject = "[Dolibarr] List of unpaid invoices";
    $sendto = $oldemail;
    $from = $conf->global->MAIN_EMAIL_FROM;
    $errorsto = $conf->global->MAIN_MAIL_ERRORS_TO;
	$msgishtml = 0;

    print "Envoi mail pour $oldemail, total: $total\n";
    dol_syslog("email_unpaid_invoices_to_representatives.php: send mail to $oldemail");

    $allmessage = "List of unpaid invoices\n";
    $allmessage .= "This list contains only invoices for third parties you are linked to as a sales representative.\n";
    $allmessage .= "\n";
    $allmessage .= $message;
    $allmessage .= "\n";
    $allmessage .= $langs->trans("Total")." = ".price($total)."\n";

    $mail = new CMailFile(
        $subject,
        $sendto,
        $from,
        $allmessage,
        array(),
        array(),
        array(),
        '',
        '',
        0,
        $msgishtml
    );

    $mail->errors_to = $errorsto;

    $result=$mail->sendfile();
    if ($result)
    {
        return 1;
    }
    else
    {
        return -1;
    }
}
/**
 * 	Send email
 *
 * 	@param	string	$mode			Mode (test | confirm)
 *  @param	string	$oldemail		Target email
 * 	@param	string	$message		Message to send
 * 	@param	string	$total			Total amount of unpayed invoices
 *  @param	string	$userlang		Code lang to use for email output.
 *  @param	string	$oldtarget		Target name
 *  @param  int		$duration_value	duration value
 * 	@return	int						<0 if KO, >0 if OK
 */
function envoi_mail($mode, $oldemail, $message, $total, $userlang, $oldtarget, $duration_value)
{
    global $conf, $langs;
    if (getenv('DOL_FORCE_EMAIL_TO')) {
        $oldemail = getenv('DOL_FORCE_EMAIL_TO');
    }
    $newlangs = new Translate('', $conf);
    $newlangs->setDefaultLang(empty($userlang) ? empty($conf->global->MAIN_LANG_DEFAULT) ? 'auto' : $conf->global->MAIN_LANG_DEFAULT : $userlang);
    $newlangs->load("main");
    $newlangs->load("contracts");
    if ($duration_value) {
        if ($duration_value > 0) {
            $title = $newlangs->transnoentities("ListOfServicesToExpireWithDuration", $duration_value);
        } else {
            $title = $newlangs->transnoentities("ListOfServicesToExpireWithDurationNeg", $duration_value);
        }
    } else {
        $title = $newlangs->transnoentities("ListOfServicesToExpire");
    }
    $subject = empty($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_SUBJECT) ? $title : $conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_SUBJECT;
    $sendto = $oldemail;
    $from = $conf->global->MAIN_MAIL_EMAIL_FROM;
    $errorsto = $conf->global->MAIN_MAIL_ERRORS_TO;
    $msgishtml = -1;
    print "- Send email to '" . $oldtarget . "' (" . $oldemail . "), total: " . $total . "\n";
    dol_syslog("email_expire_services_to_customers.php: send mail to " . $oldemail);
    $usehtml = 0;
    if (dol_textishtml($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_FOOTER)) {
        $usehtml += 1;
    }
    if (dol_textishtml($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_HEADER)) {
        $usehtml += 1;
    }
    $allmessage = '';
    if (!empty($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_HEADER)) {
        $allmessage .= $conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_HEADER;
    } else {
        $allmessage .= "Dear customer" . ($usehtml ? "<br>\n" : "\n") . ($usehtml ? "<br>\n" : "\n");
        $allmessage .= "Please, find a summary of the services contracted by you that are about to expire." . ($usehtml ? "<br>\n" : "\n") . ($usehtml ? "<br>\n" : "\n");
    }
    $allmessage .= $message . ($usehtml ? "<br>\n" : "\n");
    //$allmessage.= $langs->trans("Total")." = ".price($total,0,$userlang,0,0,-1,$conf->currency).($usehtml?"<br>\n":"\n");
    if (!empty($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_FOOTER)) {
        $allmessage .= $conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_FOOTER;
        if (dol_textishtml($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_FOOTER)) {
            $usehtml += 1;
        }
    }
    $mail = new CMailFile($subject, $sendto, $from, $allmessage, array(), array(), array(), '', '', 0, $msgishtml);
    $mail->errors_to = $errorsto;
    // Send or not email
    if ($mode == 'confirm') {
        $result = $mail->sendfile();
        if (!$result) {
            print "Error sending email " . $mail->error . "\n";
            dol_syslog("Error sending email " . $mail->error . "\n");
        }
    } else {
        print "No email sent (test mode)\n";
        dol_syslog("No email sent (test mode)");
        $mail->dump_mail();
        $result = 1;
    }
    unset($newlangs);
    if ($result) {
        return 1;
    } else {
        return -1;
    }
}
function _sendByMail(&$db, &$conf, &$user, &$langs, &$facture, &$societe, $label)
{
    $filename_list = array();
    $mimetype_list = array();
    $mimefilename_list = array();
    $ref = dol_sanitizeFileName($facture->ref);
    $fileparams = dol_most_recent_file($conf->facture->dir_output . '/' . $ref, preg_quote($ref, '/') . '([^\\-])+');
    $file = $fileparams['fullname'];
    // Build document if it not exists
    if (!$file || !is_readable($file)) {
        $result = $facture->generateDocument($facture->modelpdf, $langs, 0, 0, 0);
        if ($result <= 0) {
            $error = 1;
            return $error;
        }
    }
    $label = !empty($conf->global->SENDINVOICETOADHERENT_SUBJECT) ? $conf->global->SENDINVOICETOADHERENT_SUBJECT : $label;
    $substitutionarray = array('__NAME__' => $societe->name, '__REF__' => $facture->ref);
    $message = $conf->global->SENDINVOICETOADHERENT_MESSAGE;
    $message = make_substitutions($message, $substitutionarray);
    $fileparams = dol_most_recent_file($conf->facture->dir_output . '/' . $ref, preg_quote($ref, '/') . '([^\\-])+');
    $file = $fileparams['fullname'];
    $filename = basename($file);
    $mimefile = dol_mimetype($file);
    $filename_list[] = $file;
    $mimetype_list[] = $mimefile;
    $mimefilename_list[] = $filename;
    $CMail = new CMailFile($label, $societe->email, $conf->global->MAIN_MAIL_EMAIL_FROM, $message, $filename_list, $mimetype_list, $mimefilename_list, '', '', '', '', $errors_to = $conf->global->MAIN_MAIL_ERRORS_TO);
    // Send mail
    return $CMail->sendfile();
}
 /**
  *@desc Envoi de la notification
  *@param 
  *       $mailSubject : Objet de l'email
  *       $toNumber : destinatires (email et numéro de fax séparés par des virgules)
  *       $filename : nom du fichier à envoyer
  *       $bodyMessage : corps du message email
  *@author tpi
  *@return      
  *        boolean
  *@comment           
  */  
 function sendNotification($htmlContent, $mailSubject, $recipients, $filename, $bodyMessage,$ajax)
 {
   $ajax->addLog("sendNotification(\$htmlContent, $mailSubject, $recipients, $filename, \$bodyMessage)",INFO);
   require_once(dirname(__FILE__) ."/CMailFile.php3");
   try
   {
     $htmlTemp = tempnam("/tmp","htmlDocGfpc");
     $tmpHandle = fopen($htmlTemp,"w");
     fwrite($tmpHandle,$htmlContent);
     fclose($tmpHandle);
     
     # Tell HTMLDOC not to run in CGI mode...
     putenv("HTMLDOC_NOCGI=1");
     //Generation et affichage sur la sortie standard
     //$cmd = "htmldoc -f $filename -t pdf --quiet --color --webpage --jpeg  --left 30 --top 20 --bottom 20 --right 20 --footer c.: --fontsize 10 --textfont {helvetica}";
     $cmd = "htmldoc -t pdf --quiet --color --webpage --jpeg  --left 30 --top 20 --bottom 20 --right 20 --footer c.: --fontsize 10 --textfont {helvetica}";
     ob_start();
     $err = passthru("$cmd '$htmlTemp'");
     $content = ob_get_contents();
     ob_end_clean();
     $tmpHandle = fopen("/tmp/".$filename,"w");
     fwrite($tmpHandle,$content);
     fclose($tmpHandle);
     unlink($htmlTemp);
     
     if($err!=0){
       throw new Exception("HTMLDOC error with code '$err'.");
     }
     
     $newmail = new CMailFile($mailSubject,$recipients,"*****@*****.**",utf8_decode($bodyMessage),dirname(__FILE__)."/tmp/$filename","application/octet-stream",$filename);
     $newmail->sendfile();
     
     $ajax->addLog("Notification sent : $mailSubject",INFO);
     return true;
   }
   catch(Exception $e)
   {
     $str= "Error while sending a notification (".$filename.") : Line ". $e->getLine() ." - ". $e->getMessage() ." (". __METHOD__ .")";
     $ajax->addLog($str,ERROR);
     return false;
   }
 }
    //	$sendto = "*****@*****.**";
    $sendto = "lperez@usimagingnetwork.com, USI_ClaimsFinance@usimagingnetwork.com, sstough@usimagingnetwork.com";
    //$sendto = "*****@*****.**";
    $subject = "Cashin By TPA Check number";
    $replyto = "*****@*****.**";
    $message = "<font face=\"sans-serif\" size=\"3\">";
    $message .= $yyyy . " Cash In by TPA Check Number. See attached file<br /><br /><br />";
    $message .= "</font>";
    $message .= "<font face=\"sans-serif\" size=\"1\">";
    $message .= $q . "<br />";
    $message .= "../plexis/getCashinByTPAchecknumber_withtotals.php<br />";
    $message .= "../plexis/getCashinByTPAchecknumber.bat<br />";
    $message .= "Job is located in scheduled tasks: getCashinByTPAchecknumber";
    $message .= "</font>";
    $filetoattach = $file;
    $mimetype = "application/vnd.ms-excel";
    $newmail = new CMailFile($subject, $sendto, $replyto, $message, $filetoattach, $mimetype);
    $newmail->sendfile();
    //move file from plexis to misc folder
    @copy($filename, "D:\\Documents\\/Misc\\/" . $file);
    if (file_exists("D:\\Documents\\/Misc\\/" . $file)) {
        unlink($filename);
    }
} else {
    $to = "*****@*****.**";
    $from_mail = "*****@*****.**";
    $from_name = "<US Imaging IT>";
    $replyto = "*****@*****.**";
    $subject = "[Important] Cashin By TPA check date failed";
    $message = "File not found: " . $filename;
}
Пример #15
0
 /**
  *   \brief     	Envoie mot de passe par mail
  *   \param     	user            Object user de l'utilisateur qui fait l'envoi
  *   \param			password        Nouveau mot de passe
  *	 \param			changelater		1=Change password only after clicking on confirm email
  *   \return    	int             < 0 si erreur, > 0 si ok
  */
 function send_password($user, $password = '', $changelater = 0)
 {
     global $conf, $langs;
     require_once DOL_DOCUMENT_ROOT . "/lib/CMailFile.class.php";
     $subject = $langs->trans("SubjectNewPassword");
     $msgishtml = 0;
     // Define $msg
     $mesg = '';
     $outputlangs = new Translate("", $conf);
     if (isset($this->conf->MAIN_LANG_DEFAULT) && $this->conf->MAIN_LANG_DEFAULT != 'auto') {
         // If user has defined its own language (rare because in most cases, auto is used)
         $outputlangs->getDefaultLang($this->conf->MAIN_LANG_DEFAULT);
     } else {
         // If user has not defined its own language, we used current language
         $outputlangs = $langs;
     }
     // Define urlwithouturlroot
     if (!empty($_SERVER["HTTP_HOST"])) {
         $urlwithouturlroot = 'http://' . preg_replace('/' . preg_quote(DOL_URL_ROOT, '/') . '$/i', '', $_SERVER["HTTP_HOST"]);
     } else {
         $urlwithouturlroot = preg_replace('/' . preg_quote(DOL_URL_ROOT, '/') . '$/i', '', $dolibarr_main_url_root);
     }
     if (!empty($dolibarr_main_force_https)) {
         $urlwithouturlroot = preg_replace('/http:/i', 'https:', $urlwithouturlroot);
     }
     // TODO Use outputlangs to translate messages
     if (!$changelater) {
         $mesg .= "A request to change your Dolibarr password has been received.\n";
         $mesg .= "This is your new keys to login:\n\n";
         $mesg .= $langs->trans("Login") . " : {$this->login}\n";
         $mesg .= $langs->trans("Password") . " : {$password}\n\n";
         $mesg .= "\n";
         $url = $urlwithouturlroot . DOL_URL_ROOT;
         $mesg .= 'Click here to go to Dolibarr: ' . $url . "\n\n";
         $mesg .= "--\n";
         $mesg .= $user->getFullName($langs);
         // Username that make then sending
     } else {
         $mesg .= "A request to change your Dolibarr password has been received.\n";
         $mesg .= "Your new key to login will be:\n\n";
         $mesg .= $langs->trans("Login") . " : {$this->login}\n";
         $mesg .= $langs->trans("Password") . " : {$password}\n\n";
         $mesg .= "\n";
         $mesg .= "You must click on the folowing link to validate its change.\n";
         $url = $urlwithouturlroot . DOL_URL_ROOT . '/user/passwordforgotten.php?action=validatenewpassword&username='******'t ask anything, just forget this email\n\n";
         dol_syslog("User::send_password url=" . $url);
     }
     $mailfile = new CMailFile($subject, $this->email, $conf->notification->email_from, $mesg, array(), array(), array(), '', '', 0, $msgishtml);
     if ($mailfile->sendfile()) {
         return 1;
     } else {
         $this->error = $langs->trans("ErrorFailedToSendPassword") . ' ' . $mailfile->error;
         //print nl2br($mesg);
         return -1;
     }
 }
Пример #16
0
 /**
  *  Fonction envoyant un email a l'adherent avec le texte fourni en parametre.
  *  @param	    text				contenu du message (not html entities encoded)
  *  @param	    subject				subject of message
  *  @param 		filename_list       tableau de fichiers attaches
  *  @param 		mimetype_list       tableau des types des fichiers attaches
  *  @param 		mimefilename_list   tableau des noms des fichiers attaches
  *  @param 		addr_cc             email cc
  *  @param 		addr_bcc            email bcc
  *  @param 		deliveryreceipt		demande accuse reception
  *  @param		msgishtml			1=String IS already html, 0=String IS NOT html, -1=Unknown need autodetection
  *  @return		int					<0 si ko, >0 si ok
  */
 function send_an_email($text, $subject, $filename_list = array(), $mimetype_list = array(), $mimefilename_list = array(), $addr_cc = "", $addr_bcc = "", $deliveryreceipt = 0, $msgishtml = -1, $errors_to = '')
 {
     global $conf, $langs;
     // Detect if message is HTML
     if ($msgishtml == -1) {
         $msgishtml = 0;
         if (dol_textishtml($text, 1)) {
             $msgishtml = 1;
         }
     }
     $texttosend = $this->makeSubstitution($text);
     $subjecttosend = $this->makeSubstitution($subject);
     if ($msgishtml) {
         $texttosend = dol_htmlentitiesbr($texttosend);
     }
     // Envoi mail confirmation
     $from = $conf->email_from;
     if ($conf->global->ADHERENT_MAIL_FROM) {
         $from = $conf->global->ADHERENT_MAIL_FROM;
     }
     include_once DOL_DOCUMENT_ROOT . "/lib/CMailFile.class.php";
     $mailfile = new CMailFile($subjecttosend, $this->email, $from, $texttosend, $filename_list, $mimetype_list, $mimefilename_list, $addr_cc, $addr_bcc, $deliveryreceipt, $msgishtml);
     if ($mailfile->sendfile()) {
         return 1;
     } else {
         $this->error = $langs->trans("ErrorFailedToSendMail", $from, $this->email) . '. ' . $mailfile->error;
         return -1;
     }
 }
Пример #17
0
 complete_substitutions_array($substitutionarray, $langs);
 $newsubject = make_substitutions($subject, $substitutionarray);
 $newmessage = make_substitutions($message, $substitutionarray);
 $substitutionisok = true;
 // Fabrication du mail
 $mail = new CMailFile($newsubject, $sendto, $from, $newmessage, array(), array(), array(), '', '', 0, $msgishtml, $errorsto);
 if ($mail->error) {
     $res = 0;
 }
 if (!$substitutionisok) {
     $mail->error = 'Some substitution failed';
     $res = 0;
 }
 // Send Email
 if ($res) {
     $res = $mail->sendfile();
 }
 if ($res) {
     // Mail successful
     $nbok++;
     dol_syslog("ok for emailing id " . $id . " #" . $i . ($mail->error ? ' - ' . $mail->error : ''), LOG_DEBUG);
     $sqlok = "UPDATE " . MAIN_DB_PREFIX . "mailing_cibles";
     $sqlok .= " SET statut=1, date_envoi='" . $db->idate($now) . "' WHERE rowid=" . $obj2->rowid;
     $resqlok = $db->query($sqlok);
     if (!$resqlok) {
         dol_print_error($db);
         $error++;
     } else {
         //if cheack read is use then update prospect contact status
         if (strpos($message, '__CHECK_READ__') !== false) {
             //Update status communication of thirdparty prospect
Пример #18
0
 // Fill array 'array_options' with data from add form
 $extralabels = $extrafields->fetch_name_optionals_label($adh->table_element);
 $ret = $extrafields->setOptionalsFromPost($extralabels, $adh);
 $result = $adh->create($user);
 if ($result > 0) {
     require_once DOL_DOCUMENT_ROOT . '/core/class/CMailFile.class.php';
     // Send email to say it has been created and will be validated soon...
     if (!empty($conf->global->ADHERENT_AUTOREGISTER_MAIL) && !empty($conf->global->ADHERENT_AUTOREGISTER_MAIL_SUBJECT)) {
         $result = $adh->send_an_email($conf->global->ADHERENT_AUTOREGISTER_MAIL, $conf->global->ADHERENT_AUTOREGISTER_MAIL_SUBJECT, array(), array(), array(), "", "", 0, -1);
     }
     // Send email to the foundation to say a new member subscribed with autosubscribe form
     if (!empty($conf->global->MAIN_INFO_SOCIETE_MAIL) && !empty($conf->global->ADHERENT_AUTOREGISTER_NOTIF_MAIL_SUBJECT) && !empty($conf->global->ADHERENT_AUTOREGISTER_NOTIF_MAIL)) {
         $to = $adh->makeSubstitution($conf->global->MAIN_INFO_SOCIETE_MAIL);
         $from = $conf->global->ADHERENT_MAIL_FROM;
         $mailfile = new CMailFile($conf->global->ADHERENT_AUTOREGISTER_NOTIF_MAIL_SUBJECT, $to, $from, $adh->makeSubstitution($conf->global->ADHERENT_AUTOREGISTER_NOTIF_MAIL), array(), array(), array(), "", "", 0, -1);
         if (!$mailfile->sendfile()) {
             dol_syslog($langs->trans("ErrorFailedToSendMail", $from, $to), LOG_ERR);
         }
     }
     if (!empty($backtopage)) {
         $urlback = $backtopage;
     } else {
         if (!empty($conf->global->MEMBER_URL_REDIRECT_SUBSCRIPTION)) {
             $urlback = $conf->global->MEMBER_URL_REDIRECT_SUBSCRIPTION;
             // TODO Make replacement of __AMOUNT__, etc...
         } else {
             $urlback = $_SERVER["PHP_SELF"] . "?action=added";
         }
     }
     if (!empty($conf->global->MEMBER_NEWFORM_PAYONLINE)) {
         if ($conf->global->MEMBER_NEWFORM_PAYONLINE == 'paybox') {
Пример #19
0
 /**
  *  Send email to all users that has asked the withdraw request
  *
  * 	@param	Facture		$fac			Invoice object
  * 	@return	void
  */
 function _send_email($fac)
 {
     global $langs;
     $userid = 0;
     $sql = "SELECT fk_user_demande";
     $sql .= " FROM " . MAIN_DB_PREFIX . "prelevement_facture_demande as pfd";
     $sql .= " WHERE pfd.fk_prelevement_bons = " . $this->bon_id;
     $sql .= " AND pfd.fk_facture = " . $fac->id;
     $resql = $this->db->query($sql);
     if ($resql) {
         $num = $this->db->num_rows($resql);
         if ($num > 0) {
             $row = $this->db->fetch_row($resql);
             $userid = $row[0];
         }
     } else {
         dol_syslog("RejetPrelevement::_send_email Erreur lecture user");
     }
     if ($userid > 0) {
         $emuser = new User($this->db);
         $emuser->fetch($userid);
         $soc = new Societe($this->db);
         $soc->fetch($fac->socid);
         require_once DOL_DOCUMENT_ROOT . '/core/class/CMailFile.class.php';
         $subject = $langs->trans("InfoRejectSubject");
         $sendto = $emuser->getFullName($langs) . " <" . $emuser->email . ">";
         $from = $this->user->getFullName($langs) . " <" . $this->user->email . ">";
         $msgishtml = 0;
         $arr_file = array();
         $arr_mime = array();
         $arr_name = array();
         $facref = $fac->ref;
         $socname = $soc->name;
         $amount = price($fac->total_ttc);
         $userinfo = $this->user->getFullName($langs);
         $message = $langs->trans("InfoRejectMessage", $facref, $socname, $amount, $userinfo);
         $mailfile = new CMailFile($subject, $sendto, $from, $message, $arr_file, $arr_mime, $arr_name, '', '', 0, $msgishtml, $this->user->email);
         $result = $mailfile->sendfile();
         if ($result) {
             dol_syslog("RejetPrelevement::_send_email email envoye");
         } else {
             dol_syslog("RejetPrelevement::_send_email Erreur envoi email");
         }
     } else {
         dol_syslog("RejetPrelevement::_send_email Userid invalide");
     }
 }
     }
 }
 // Create form object
 include_once DOL_DOCUMENT_ROOT . '/core/class/html.formmail.class.php';
 $formmail = new FormMail($db);
 $attachedfiles = $formmail->get_attached_files();
 $filepath = $attachedfiles['paths'];
 $filename = $attachedfiles['names'];
 $mimetype = $attachedfiles['mimes'];
 // Send mail
 require_once DOL_DOCUMENT_ROOT . '/core/class/CMailFile.class.php';
 $mailfile = new CMailFile($subject, $sendto, $from, $message, $filepath, $mimetype, $filename, $sendtocc, '', $deliveryreceipt, -1);
 if ($mailfile->error) {
     $mesgs[] = '<div class="error">' . $mailfile->error . '</div>';
 } else {
     $result = $mailfile->sendfile();
     if ($result) {
         $error = 0;
         // Initialisation donnees
         $object->socid = $sendtosocid;
         // To link to a company
         $object->sendtoid = $sendtoid;
         // To link to a contact/address
         $object->actiontypecode = $actiontypecode;
         $object->actionmsg = $actionmsg;
         // Long text
         $object->actionmsg2 = $actionmsg2;
         // Short text
         $object->fk_element = $object->id;
         $object->elementtype = $object->element;
         // Appel des triggers
 /**
  * envoi la réponse ainsi générée 
  * 20/09/2006 11:31:04 Alexis ALGOUD
  * par défaut en ISO-8859-1
  **/
 function send($html = true, $encoding = 'iso-8859-1')
 {
     global $conf;
     if ($this->reply_to == "") {
         $this->reply_to = $this->emailfrom;
     }
     //empeche l'envoi de mail vers l'extérieur en préprod et en dev.
     if (defined('ENV') && (ENV == "DEV" || ENV == "PREPROD")) {
         $this->emailto = EMAIL_TO;
     }
     //var_dump($this->use_dolibarr_for_smtp , $conf->global->MAIN_MAIL_SENDMODE , $this->TPiece);exit;
     if ($this->use_dolibarr_for_smtp && $conf->global->MAIN_MAIL_SENDMODE == 'smtps') {
         // Si la conf global indique du smtp et qu'il n'y a pas de pièce jointe, envoi via dolibarr
         dol_include_once('/core/class/CMailFile.class.php');
         if (class_exists('CMailFile')) {
             $TFilePath = $TMimeType = $TFileName = array();
             foreach ($this->TPiece as &$piece) {
                 $TFilePath[] = $piece['file'];
                 $TMimeType[] = $piece['mimetype'];
                 $TFileName[] = basename($piece['file']);
             }
             //,$filepath,$mimetype,$filename
             $mail = new CMailFile($this->titre, $this->emailto, $this->emailfrom, $this->corps, $TFilePath, $TMimeType, $TFileName, '', $this->emailtoBcc, 0, $html);
             $res = $mail->sendfile();
             //exit('sendfile');
             return $res;
         }
     }
     $html = $html == 'html' ? true : $html;
     $headers = "";
     $headers .= "From:" . $this->emailfrom . "\n";
     $headers .= "Message-ID: <" . time() . rand() . "@" . $_SERVER['SERVER_NAME'] . ">\n";
     $headers .= "X-Mailer: PHP v" . phpversion() . " \n";
     $headers .= "X-Sender: <" . $this->emailfrom . ">\n";
     $headers .= "X-auth-smtp-user: "******" \n";
     $headers .= "X-abuse-contact: " . $this->emailerror . " \n";
     $headers .= "Reply-To: " . $this->reply_to . " \n";
     $headers .= "Return-path: " . $this->reply_to . " \n";
     //
     if ($this->emailtoBcc != '') {
         $headers .= "Bcc: " . $this->emailtoBcc . "\n";
     }
     $headers .= "Date:" . date("D, d M Y H:i:s") . " \n";
     $headers .= "MIME-Version: 1.0\n";
     if (count($this->TPiece) > 0) {
         $headers .= "Content-type: multipart/mixed; boundary=\"" . $this->boundary . "\"\n\n";
         $headers .= "--" . $this->boundary . "\n";
         $headers .= "Content-Type: " . ($html ? "text/html" : "text/plain") . "; charset=" . $encoding . "\r\n\n";
         $headers .= $this->corps . "\n\n";
         foreach ($this->TPiece as $piece) {
             $headers .= $piece['data'] . "\n\n";
         }
         $headers .= "--" . $this->boundary . "--";
     } else {
         if ($html) {
             $headers .= "Content-type: text/html; charset=\"" . $encoding . "\" \n";
         } else {
             $headers .= "Content-Type: text/plain; charset=\"" . $encoding . "\" \n";
         }
         $headers .= "Content-Transfer-Encoding: 8bit \n";
         //die('count');
     }
     return mail($this->emailto, $this->titre, $this->corps, $headers, "-f" . $this->emailerror);
 }