49@phan-var-force Societe $mysoc
50@phan-var-force CommonObject $object
51@phan-var-force int $error
58if (
GETPOST(
'addfile',
'alpha')) {
59 $trackid =
GETPOST(
'trackid',
'aZ09');
61 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
64 $vardir =
$conf->user->dir_output.
"/".$user->id;
65 $upload_dir_tmp = $vardir.
'/temp';
75 $trackid =
GETPOST(
'trackid',
'aZ09');
77 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
80 $vardir =
$conf->user->dir_output.
"/".$user->id;
81 $upload_dir_tmp = $vardir.
'/temp';
92if (
GETPOST(
'removeAll',
'alpha')) {
93 $trackid =
GETPOST(
'trackid',
'aZ09');
95 $listofpaths = array();
96 $listofnames = array();
97 $listofmimes = array();
98 $keytoavoidconflict = empty($trackid) ?
'' :
'-'.$trackid;
99 if (!empty($_SESSION[
"listofpaths".$keytoavoidconflict])) {
100 $listofpaths = explode(
';', $_SESSION[
"listofpaths".$keytoavoidconflict]);
102 if (!empty($_SESSION[
"listofnames".$keytoavoidconflict])) {
103 $listofnames = explode(
';', $_SESSION[
"listofnames".$keytoavoidconflict]);
105 if (!empty($_SESSION[
"listofmimes".$keytoavoidconflict])) {
106 $listofmimes = explode(
';', $_SESSION[
"listofmimes".$keytoavoidconflict]);
109 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
111 $formmail->trackid = $trackid;
113 foreach ($listofpaths as $key => $value) {
114 $pathtodelete = $value;
115 $filetodelete = $listofnames[$key];
118 $langs->load(
"other");
119 setEventMessages($langs->trans(
"FileWasRemoved", $filetodelete),
null,
'mesgs');
121 $formmail->remove_attached_files($key);
128if (($action ==
'send' || $action ==
'relance') && !
GETPOST(
'addfile') && !
GETPOST(
'removeAll') && !
GETPOST(
'removedfile') && !
GETPOST(
'cancel') && !
GETPOST(
'modelselected')) {
129 if (empty($trackid)) {
130 $trackid =
GETPOST(
'trackid',
'aZ09');
134 $vardir =
$conf->user->dir_output.
"/".$user->id;
135 $upload_dir_tmp = $vardir.
'/temp';
144 $langs->load(
'mails');
151 if (method_exists(
$object,
"fetch_thirdparty") && !in_array(
$object->element, array(
'member',
'user',
'expensereport',
'societe',
'contact'))) {
153 $thirdparty =
$object->thirdparty;
154 if (is_object($thirdparty)) {
155 $sendtosocid = $thirdparty->id;
157 } elseif (
$object->element ==
'member' ||
$object->element ==
'user') {
158 '@phan-var-force Adherent|User $object';
163 } elseif (
$object->element ==
'expensereport') {
164 '@phan-var-force ExpenseReport $object';
165 $tmpuser =
new User($db);
166 $tmpuser->fetch(
$object->fk_user_author);
167 $thirdparty = $tmpuser;
168 } elseif (
$object->element ==
'societe') {
169 '@phan-var-force Societe $object';
171 if (is_object($thirdparty) && $thirdparty->id > 0) {
172 $sendtosocid = $thirdparty->id;
174 } elseif (
$object->element ==
'contact') {
175 '@phan-var-force Contact $object';
177 if ($contact->id > 0) {
178 $contact->fetch_thirdparty();
179 $thirdparty = $contact->thirdparty;
180 if (is_object($thirdparty) && $thirdparty->id > 0) {
181 $sendtosocid = $thirdparty->id;
185 dol_print_error(
null,
"Use actions_sendmails.in.php for an element/object '".
$object->element.
"' that is not supported");
188 if (is_object($hookmanager)) {
189 $parameters = array();
190 $reshook = $hookmanager->executeHooks(
'initSendToSocid', $parameters,
$object, $action);
203 $sendtouserid = array();
204 $sendtoccuserid = array();
207 $receiver =
GETPOST(
'receiver',
'alphawithlgt');
208 if (!is_array($receiver)) {
209 if ($receiver ==
'-1') {
212 $receiver = array($receiver);
217 if (trim(
GETPOST(
'sendto',
'alphawithlgt'))) {
219 $tmparray[] = trim(
GETPOST(
'sendto',
'alphawithlgt'));
222 if (trim(
GETPOST(
'tomail',
'alphawithlgt'))) {
224 $tmparray[] = trim(
GETPOST(
'tomail',
'alphawithlgt'));
227 if (count($receiver) > 0) {
229 foreach ($receiver as $key => $val) {
230 if ($val ==
'thirdparty') {
231 $thirdpartyEmail = (is_object($thirdparty) && !empty($thirdparty->email)) ? (
string) $thirdparty->email :
'';
232 if ($thirdpartyEmail !==
'') {
233 $thirdpartyLabel =
'';
234 if (is_object($thirdparty)) {
235 if (method_exists($thirdparty,
'getFullName')) {
236 $thirdpartyLabel = (string) $thirdparty->getFullName($langs);
237 } elseif (!empty($thirdparty->name)) {
238 $thirdpartyLabel = (string) $thirdparty->name;
239 } elseif (!empty($thirdparty->nom)) {
240 $thirdpartyLabel = (string) $thirdparty->nom;
243 if ($thirdpartyLabel !==
'') {
244 $tmparray[] =
dol_string_nospecial($thirdpartyLabel,
' ', array(
",")).
' <'.$thirdpartyEmail.
'>';
246 $tmparray[] = $thirdpartyEmail;
249 } elseif ($val ==
'contact') {
250 $tmparray[] =
dol_string_nospecial($contact->getFullName($langs),
' ', array(
",")).
' <'.$contact->email.
'>';
251 $sendtoid[] = $contact->id;
252 } elseif ($val &&
$object->element ==
'project' && empty(
$object->socid)) {
254 $ret = $contact->fetch((
int) $val);
255 if ($ret > 0 && !empty($contact->socid)) {
256 $thirdparty =
new Societe($db);
257 $thirdparty->fetch($contact->socid);
258 $tmparray[] = $thirdparty->contact_get_property((
int) $val,
'email');
259 $sendtoid[] = ((int) $val);
261 } elseif (is_numeric($val) && $val > 0) {
262 $tmparray[] = $thirdparty->contact_get_property((
int) $val,
'email');
263 $sendtoid[] = ((int) $val);
264 } elseif ($val !==
'') {
271 $receiveruser =
GETPOST(
'receiveruser',
'alphawithlgt');
272 if (is_array($receiveruser) && count($receiveruser) > 0) {
273 $fuserdest =
new User($db);
274 foreach ($receiveruser as $key => $val) {
275 $tmparray[] = $fuserdest->user_get_property($val,
'email');
276 $sendtouserid[] = $val;
281 $sendto = implode(
',', $tmparray);
284 $receivercc =
GETPOST(
'receivercc',
'alphawithlgt');
285 if (!is_array($receivercc)) {
286 if ($receivercc ==
'-1') {
287 $receivercc = array();
289 $receivercc = array($receivercc);
293 if (trim(
GETPOST(
'sendtocc',
'alphawithlgt'))) {
294 $tmparray[] = trim(
GETPOST(
'sendtocc',
'alphawithlgt'));
296 if (count($receivercc) > 0) {
297 foreach ($receivercc as $key => $val) {
298 if ($val ==
'thirdparty') {
300 $tmparray[] =
dol_string_nospecial((
string) $thirdparty->name,
' ', array(
",")).
' <'.$thirdparty->email.
'>';
301 } elseif ($val ==
'contact') {
303 $tmparray[] =
dol_string_nospecial((
string) $contact->name,
' ', array(
",")).
' <'.$contact->email.
'>';
305 } elseif (is_numeric($val) && $val > 0) {
306 $tmparray[] = $thirdparty->contact_get_property((
int) $val,
'email');
308 } elseif ($val !==
'') {
314 $receiverccuser =
GETPOST(
'receiverccuser',
'alphawithlgt');
316 if (is_array($receiverccuser) && count($receiverccuser) > 0) {
317 $fuserdest =
new User($db);
318 foreach ($receiverccuser as $key => $val) {
319 $tmparray[] = $fuserdest->user_get_property($val,
'email');
320 $sendtoccuserid[] = $val;
324 $sendtocc = implode(
',', $tmparray);
329 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
332 require_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
334 $langs->load(
"commercial");
337 $fromtype =
GETPOST(
'fromtype',
'alpha');
338 $emailsendersignature =
'';
339 if ($fromtype ===
'robot') {
341 } elseif ($fromtype ===
'user') {
342 $email_from =
dol_string_nospecial($user->getFullName($langs),
' ', array(
",")).
' <'.$user->email.
'>';
343 } elseif ($fromtype ===
'company') {
345 } elseif (preg_match(
'/global_aliases_(\d+)/', $fromtype, $reg)) {
347 $email_from = trim($tmp[((
int) $reg[1] - 1)]);
348 } elseif (preg_match(
'/senderprofile_(\d+)_(\d+)/', $fromtype, $reg)) {
349 $sql =
"SELECT rowid, label, email, signature FROM ".MAIN_DB_PREFIX.
"c_email_senderprofile";
350 $sql .=
" WHERE rowid = ".(int) $reg[1];
351 $resql = $db->query($sql);
352 $obj = $db->fetch_object($resql);
355 $emailsendersignature = $obj->signature;
357 } elseif (preg_match(
'/from_template_(\d+)/', $fromtype, $reg)) {
358 $sql =
"SELECT rowid, email_from FROM ".MAIN_DB_PREFIX.
"c_email_templates";
359 $sql .=
" WHERE rowid = ".(int) $reg[1];
360 $resql = $db->query($sql);
361 $obj = $db->fetch_object($resql);
363 $email_from = $obj->email_from;
372 $replyto .= ($replyto ?
' ' :
'').
'<'.
GETPOST(
'replytomail').
'>';
375 $message =
GETPOST(
'message',
'restricthtml');
376 $subject =
GETPOST(
'subject',
'restricthtml');
382 $message = preg_replace(
'/(<img.*src=")[^\"]*viewimage\.php([^\"]*)modulepart=medias([^\"]*)file=([^\"]*)("[^\/]*\/>)/',
'\1'.$urlwithroot.
'/viewimage.php\2modulepart=medias\3file=\4\5', $message);
384 $tmparrayccc = array();
385 if (trim(
GETPOST(
'sendtoccc',
'alphawithlgt'))) {
386 $tmparrayccc[] = trim(
GETPOST(
'sendtoccc',
'alphawithlgt'));
388 $receiverccc =
GETPOST(
'receiverccc',
'alphawithlgt');
389 if (!is_array($receiverccc)) {
390 $receiverccc = ($receiverccc && $receiverccc !=
'-1') ? array($receiverccc) : array();
392 foreach ($receiverccc as $val) {
393 if ($val ==
'thirdparty') {
394 $tmparrayccc[] =
dol_string_nospecial((
string) $thirdparty->name,
' ', array(
",")).
' <'.$thirdparty->email.
'>';
395 } elseif ($val ==
'contact') {
396 $tmparrayccc[] =
dol_string_nospecial((
string) $contact->name,
' ', array(
",")).
' <'.$contact->email.
'>';
397 } elseif (is_numeric($val) && $val > 0) {
398 $tmparrayccc[] = $thirdparty->contact_get_property((
int) $val,
'email');
399 } elseif ($val !==
'') {
400 $tmparrayccc[] =
sanitizeVal($val,
'alphawithlgt');
403 $sendtobcc = implode(
',', $tmparrayccc);
406 if (!empty($autocopy)) {
410 $deliveryreceipt =
GETPOSTINT(
'deliveryreceipt') ? 1 : 0;
412 if ($action ==
'send' || $action ==
'relance') {
427 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
429 $formmail->trackid = $trackid;
431 $attachedfiles = $formmail->get_attached_files();
432 $filepath = $attachedfiles[
'paths'];
433 $filename = $attachedfiles[
'names'];
434 $mimetype = $attachedfiles[
'mimes'];
437 $substitutionarray = getCommonSubstitutionArray($langs, 0,
null,
$object);
439 $substitutionarray[
'__SENDEREMAIL_SIGNATURE__'] = (empty($emailsendersignature) ? $user->signature : $emailsendersignature);
440 $substitutionarray[
'__EMAIL__'] = $sendto;
441 $substitutionarray[
'__CHECK_READ__'] = (is_object(
$object) && is_object(
$object->thirdparty)) ?
'<img src="'.DOL_MAIN_URL_ROOT.
'/public/emailing/mailing-read.php?tag=undefined&securitykey='.
dol_hash(
getDolGlobalString(
'MAILING_EMAIL_UNSUBSCRIBE_KEY').
"-undefined",
'md5').
'" width="1" height="1" style="width:1px;height:1px" border="0"/>' :
'';
443 $parameters = array(
'mode' =>
'formemail');
449 if (is_object(
$object) && method_exists(
$object,
'makeSubstitution')) {
450 $subject =
$object->makeSubstitution($subject);
451 $message =
$object->makeSubstitution($message);
455 if (empty($sendcontext)) {
456 $sendcontext =
'standard';
458 $mailfile =
new CMailFile($subject, $sendto, $email_from, $message, $filepath, $mimetype, $filename, $sendtocc, $sendtobcc, $deliveryreceipt, -1,
'',
'', $trackid,
'', $sendcontext, $replyto, $upload_dir_tmp);
460 if (!empty($mailfile->error) || !empty($mailfile->errors)) {
461 setEventMessages($mailfile->error, $mailfile->errors,
'errors');
464 $result = $mailfile->sendfile();
470 if (empty($actiontypecode)) {
471 $actiontypecode =
'AC_EMAIL';
476 $object->actiontypecode = $actiontypecode;
478 $object->actionmsg2 = $actionmsg2;
480 $object->actionmsg2 = $subject;
486 if (is_array($attachedfiles) && count($attachedfiles) > 0) {
487 $object->attachedfiles = $attachedfiles;
489 if (is_array($sendtouserid) && count($sendtouserid) > 0 &&
getDolGlobalString(
'MAIN_MAIL_ENABLED_USER_DEST_SELECT')) {
490 $object->sendtouserid = $sendtouserid;
494 $object->context[
'email_msgid'] = $mailfile->msgid;
495 $object->context[
'email_from'] = $email_from;
496 $object->context[
'email_subject'] = $subject;
497 $object->context[
'email_to'] = $sendto;
498 $object->context[
'email_tocc'] = $sendtocc;
499 $object->context[
'email_tobcc'] = $sendtobcc;
501 $object->email_msgid = $mailfile->msgid;
502 $object->email_from = $email_from;
503 $object->email_subject = $subject;
505 $object->email_tocc = $sendtocc;
506 $object->email_tobcc = $sendtobcc;
509 if (!empty($triggersendname)) {
510 if ($triggersendname ==
'BILL_SENTBYMAIL' &&
$object instanceof
Facture) {
514 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"facture SET email_sent_counter = email_sent_counter + 1";
515 $sql .=
" WHERE rowid = ".((int)
$object->id);
517 $resql = $db->query($sql);
519 $object->email_sent_counter += 1;
523 $result =
$object->call_trigger($triggersendname, $user);
542 $mesg = $langs->trans(
'MailSuccessfulySent', $mailfile->getValidAddress($email_from, 2), $mailfile->getValidAddress($sendto, 2));
543 setEventMessages($mesg,
null,
'mesgs');
545 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?'.($paramname ??
'id').
'='.(is_object(
$object) ?
$object->id :
''));
548 $langs->load(
"other");
549 $mesg =
'<div class="error">';
550 if (!empty($mailfile->error) || !empty($mailfile->errors)) {
552 if (!empty($mailfile->error)) {
553 $mesg .=
'<br>'.$mailfile->error;
555 if (!empty($mailfile->errors) && is_array($mailfile->errors)) {
556 $mesg .=
'<br>'.implode(
'<br>', $mailfile->errors);
561 $mesg .=
'<br>Feature is disabled by option MAIN_DISABLE_ALL_MAILS';
563 $mesg .=
'<br>Unknown Error, please refer to your administrator';
568 setEventMessages($mesg,
null,
'warnings');
573 $langs->load(
"errors");
574 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"MailTo")),
null,
'warnings');
575 dol_syslog(
'Try to send email with no recipient defined', LOG_WARNING);
579 $langs->load(
"errors");
580 setEventMessages($langs->trans(
'ErrorFailedToReadObject',
$object->element),
null,
'errors');
$id
Support class for third parties, contacts, members, users or resources.
if(! $sortfield) if(! $sortorder) $object
global $dolibarr_main_url_root
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
Class to send emails (with attachments or not) Usage: $mailfile = new CMailFile($subject,...
static getValidAddress($address, $format, $encode=0, $maxnumberofemail=0)
Return a formatted address string for SMTP protocol.
Class to manage invoices.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage Dolibarr users.
dol_add_file_process($upload_dir, $allowoverwrite=0, $updatesessionordb=0, $keyforsourcefile='addedfile', $savingdocmask='', $link=null, $trackid='', $generatethumbs=1, $object=null, $forceFullTextIndexation='', $mode=0)
Get and save an upload file (for example after submitting a new file in a mail form).
dol_delete_file($file, $disableglob=0, $nophperrors=0, $nohook=0, $object=null, $allowdotdot=false, $indexdatabase=1, $nolog=0)
Remove a file or several files with a mask.
dol_remove_file_process($filenb, $donotupdatesession=0, $donotdeletefile=1, $trackid='')
Remove an uploaded file (for example after submitting a new file a mail form).
dol_strlen($string, $stringencoding='UTF-8', $binarycount=0)
Make a strlen call.
dol_string_nospecial($str, $newstr='_', $badcharstoreplace='', $badcharstoremove='', $keepspaces=0)
Clean a string from all punctuation characters to use it as a ref or login.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
complete_substitutions_array(&$substitutionarray, $outputlangs, $object=null, $parameters=null, $callfunc="completesubstitutionarray")
Complete the $substitutionarray with more entries coming from external module that had set the "subst...
make_substitutions($text, $substitutionarray, $outputlangs=null, $converttextinhtmlifnecessary=0)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
sanitizeVal($out='', $check='alphanohtml', $filter=null, $options=null)
Return a sanitized or empty value after checking value against a rule.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
dol_hash($chain, $type='0', $nosalt=0, $mode=0)
Returns a hash (non reversible encryption) of a string.