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;
171 } elseif (
$object->element ==
'societe') {
172 '@phan-var-force Societe $object';
174 if (is_object($thirdparty) && $thirdparty->id > 0) {
175 $sendtosocid = $thirdparty->id;
177 } elseif (
$object->element ==
'contact') {
178 '@phan-var-force Contact $object';
180 if ($contact->id > 0) {
181 $contact->fetch_thirdparty();
182 $thirdparty = $contact->thirdparty;
183 if (is_object($thirdparty) && $thirdparty->id > 0) {
184 $sendtosocid = $thirdparty->id;
188 dol_print_error(
null,
"Use actions_sendmails.in.php for an element/object '".
$object->element.
"' that is not supported");
191 if (is_object($hookmanager)) {
192 $parameters = array();
193 $reshook = $hookmanager->executeHooks(
'initSendToSocid', $parameters,
$object, $action);
206 $sendtouserid = array();
207 $sendtoccuserid = array();
210 $receiver =
GETPOST(
'receiver',
'alphawithlgt');
211 if (!is_array($receiver)) {
212 if ($receiver ==
'-1') {
215 $receiver = array($receiver);
220 if (trim(
GETPOST(
'sendto',
'alphawithlgt'))) {
222 $tmparray[] = trim(
GETPOST(
'sendto',
'alphawithlgt'));
225 if (trim(
GETPOST(
'tomail',
'alphawithlgt'))) {
227 $tmparray[] = trim(
GETPOST(
'tomail',
'alphawithlgt'));
230 if (count($receiver) > 0) {
232 foreach ($receiver as $key => $val) {
233 if ($val ==
'thirdparty') {
234 $thirdpartyEmail = (is_object($thirdparty) && !empty($thirdparty->email)) ? (
string) $thirdparty->email :
'';
235 if ($thirdpartyEmail !==
'') {
236 $thirdpartyLabel =
'';
237 if (is_object($thirdparty)) {
238 if (method_exists($thirdparty,
'getFullName')) {
239 $thirdpartyLabel = (string) $thirdparty->getFullName($langs);
240 } elseif (!empty($thirdparty->name)) {
241 $thirdpartyLabel = (string) $thirdparty->name;
242 } elseif (!empty($thirdparty->nom)) {
243 $thirdpartyLabel = (string) $thirdparty->nom;
246 if ($thirdpartyLabel !==
'') {
247 $tmparray[] =
dol_string_nospecial($thirdpartyLabel,
' ', array(
",")).
' <'.$thirdpartyEmail.
'>';
249 $tmparray[] = $thirdpartyEmail;
252 } elseif ($val ==
'contact') {
253 $tmparray[] =
dol_string_nospecial($contact->getFullName($langs),
' ', array(
",")).
' <'.$contact->email.
'>';
254 $sendtoid[] = $contact->id;
255 } elseif ($val &&
$object->element ==
'project' && empty(
$object->socid)) {
257 $ret = $contact->fetch((
int) $val);
258 if ($ret > 0 && !empty($contact->socid)) {
259 $thirdparty =
new Societe($db);
260 $thirdparty->fetch($contact->socid);
261 $tmparray[] = $thirdparty->contact_get_property((
int) $val,
'email');
262 $sendtoid[] = ((int) $val);
264 } elseif (is_numeric($val) && $val > 0) {
265 $tmparray[] = $thirdparty->contact_get_property((
int) $val,
'email');
266 $sendtoid[] = ((int) $val);
267 } elseif ($val !==
'') {
274 $receiveruser =
GETPOST(
'receiveruser',
'alphawithlgt');
275 if (is_array($receiveruser) && count($receiveruser) > 0) {
276 $fuserdest =
new User($db);
277 foreach ($receiveruser as $key => $val) {
278 $tmparray[] = $fuserdest->user_get_property($val,
'email');
279 $sendtouserid[] = $val;
284 $sendto = implode(
',', $tmparray);
287 $receivercc =
GETPOST(
'receivercc',
'alphawithlgt');
288 if (!is_array($receivercc)) {
289 if ($receivercc ==
'-1') {
290 $receivercc = array();
292 $receivercc = array($receivercc);
296 if (trim(
GETPOST(
'sendtocc',
'alphawithlgt'))) {
297 $tmparray[] = trim(
GETPOST(
'sendtocc',
'alphawithlgt'));
299 if (count($receivercc) > 0) {
300 foreach ($receivercc as $key => $val) {
301 if ($val ==
'thirdparty') {
303 $tmparray[] =
dol_string_nospecial((
string) $thirdparty->name,
' ', array(
",")).
' <'.$thirdparty->email.
'>';
304 } elseif ($val ==
'contact') {
306 $tmparray[] =
dol_string_nospecial((
string) $contact->name,
' ', array(
",")).
' <'.$contact->email.
'>';
308 } elseif (is_numeric($val) && $val > 0) {
309 $tmparray[] = $thirdparty->contact_get_property((
int) $val,
'email');
311 } elseif ($val !==
'') {
317 $receiverccuser =
GETPOST(
'receiverccuser',
'alphawithlgt');
319 if (is_array($receiverccuser) && count($receiverccuser) > 0) {
320 $fuserdest =
new User($db);
321 foreach ($receiverccuser as $key => $val) {
322 $tmparray[] = $fuserdest->user_get_property($val,
'email');
323 $sendtoccuserid[] = $val;
327 $sendtocc = implode(
',', $tmparray);
332 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
335 require_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
337 $langs->load(
"commercial");
340 $fromtype =
GETPOST(
'fromtype',
'alpha');
341 $emailsendersignature =
'';
342 if ($fromtype ===
'robot') {
344 } elseif ($fromtype ===
'user') {
345 $email_from =
dol_string_nospecial($user->getFullName($langs),
' ', array(
",")).
' <'.$user->email.
'>';
346 } elseif ($fromtype ===
'company') {
348 } elseif (preg_match(
'/global_aliases_(\d+)/', $fromtype, $reg)) {
350 $email_from = trim($tmp[((
int) $reg[1] - 1)]);
351 } elseif (preg_match(
'/senderprofile_(\d+)_(\d+)/', $fromtype, $reg)) {
352 $sql =
"SELECT rowid, label, email, signature FROM ".MAIN_DB_PREFIX.
"c_email_senderprofile";
353 $sql .=
" WHERE rowid = ".(int) $reg[1];
354 $resql = $db->query($sql);
355 $obj = $db->fetch_object($resql);
358 $emailsendersignature = $obj->signature;
360 } elseif (preg_match(
'/from_template_(\d+)/', $fromtype, $reg)) {
361 $sql =
"SELECT rowid, email_from FROM ".MAIN_DB_PREFIX.
"c_email_templates";
362 $sql .=
" WHERE rowid = ".(int) $reg[1];
363 $resql = $db->query($sql);
364 $obj = $db->fetch_object($resql);
366 $email_from = $obj->email_from;
375 $replyto .= ($replyto ?
' ' :
'').
'<'.
GETPOST(
'replytomail').
'>';
378 $message =
GETPOST(
'message',
'restricthtml');
379 $subject =
GETPOST(
'subject',
'restricthtml');
385 $message = preg_replace(
'/(<img.*src=")[^\"]*viewimage\.php([^\"]*)modulepart=medias([^\"]*)file=([^\"]*)("[^\/]*\/>)/',
'\1'.$urlwithroot.
'/viewimage.php\2modulepart=medias\3file=\4\5', $message);
387 $tmparrayccc = array();
388 if (trim(
GETPOST(
'sendtoccc',
'alphawithlgt'))) {
389 $tmparrayccc[] = trim(
GETPOST(
'sendtoccc',
'alphawithlgt'));
391 $receiverccc =
GETPOST(
'receiverccc',
'alphawithlgt');
392 if (!is_array($receiverccc)) {
393 $receiverccc = ($receiverccc && $receiverccc !=
'-1') ? array($receiverccc) : array();
395 foreach ($receiverccc as $val) {
396 if ($val ==
'thirdparty') {
397 $tmparrayccc[] =
dol_string_nospecial((
string) $thirdparty->name,
' ', array(
",")).
' <'.$thirdparty->email.
'>';
398 } elseif ($val ==
'contact') {
399 $tmparrayccc[] =
dol_string_nospecial((
string) $contact->name,
' ', array(
",")).
' <'.$contact->email.
'>';
400 } elseif (is_numeric($val) && $val > 0) {
401 $tmparrayccc[] = $thirdparty->contact_get_property((
int) $val,
'email');
402 } elseif ($val !==
'') {
403 $tmparrayccc[] =
sanitizeVal($val,
'alphawithlgt');
406 $sendtobcc = implode(
',', $tmparrayccc);
409 if (!empty($autocopy)) {
413 $deliveryreceipt =
GETPOSTINT(
'deliveryreceipt') ? 1 : 0;
415 if ($action ==
'send' || $action ==
'relance') {
430 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
432 $formmail->trackid = $trackid;
434 $attachedfiles = $formmail->get_attached_files();
435 $filepath = $attachedfiles[
'paths'];
436 $filename = $attachedfiles[
'names'];
437 $mimetype = $attachedfiles[
'mimes'];
440 $substitutionarray = getCommonSubstitutionArray($langs, 0,
null,
$object);
442 $substitutionarray[
'__SENDEREMAIL_SIGNATURE__'] = (empty($emailsendersignature) ? $user->signature : $emailsendersignature);
443 $substitutionarray[
'__EMAIL__'] = $sendto;
444 $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"/>' :
'';
446 $parameters = array(
'mode' =>
'formemail');
452 if (is_object(
$object) && method_exists(
$object,
'makeSubstitution')) {
453 $subject =
$object->makeSubstitution($subject);
454 $message =
$object->makeSubstitution($message);
458 if (empty($sendcontext)) {
459 $sendcontext =
'standard';
461 $mailfile =
new CMailFile($subject, $sendto, $email_from, $message, $filepath, $mimetype, $filename, $sendtocc, $sendtobcc, $deliveryreceipt, -1,
'',
'', $trackid,
'', $sendcontext, $replyto, $upload_dir_tmp);
463 if (!empty($mailfile->error) || !empty($mailfile->errors)) {
464 setEventMessages($mailfile->error, $mailfile->errors,
'errors');
467 $result = $mailfile->sendfile();
473 if (empty($actiontypecode)) {
474 $actiontypecode =
'AC_EMAIL';
479 $object->actiontypecode = $actiontypecode;
481 $object->actionmsg2 = $actionmsg2;
483 $object->actionmsg2 = $subject;
489 if (is_array($attachedfiles) && count($attachedfiles) > 0) {
490 $object->attachedfiles = $attachedfiles;
492 if (is_array($sendtouserid) && count($sendtouserid) > 0 &&
getDolGlobalString(
'MAIN_MAIL_ENABLED_USER_DEST_SELECT')) {
493 $object->sendtouserid = $sendtouserid;
497 $object->context[
'email_msgid'] = $mailfile->msgid;
498 $object->context[
'email_from'] = $email_from;
499 $object->context[
'email_subject'] = $subject;
500 $object->context[
'email_to'] = $sendto;
501 $object->context[
'email_tocc'] = $sendtocc;
502 $object->context[
'email_tobcc'] = $sendtobcc;
504 $object->email_msgid = $mailfile->msgid;
505 $object->email_from = $email_from;
506 $object->email_subject = $subject;
508 $object->email_tocc = $sendtocc;
509 $object->email_tobcc = $sendtobcc;
512 if (!empty($triggersendname)) {
513 if ($triggersendname ==
'BILL_SENTBYMAIL' &&
$object instanceof
Facture) {
517 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"facture SET email_sent_counter = email_sent_counter + 1";
518 $sql .=
" WHERE rowid = ".((int)
$object->id);
520 $resql = $db->query($sql);
522 $object->email_sent_counter += 1;
526 $result =
$object->call_trigger($triggersendname, $user);
545 $mesg = $langs->trans(
'MailSuccessfulySent', $mailfile->getValidAddress($email_from, 2), $mailfile->getValidAddress($sendto, 2));
546 setEventMessages($mesg,
null,
'mesgs');
548 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?'.($paramname ??
'id').
'='.(is_object(
$object) ?
$object->id :
''));
551 $langs->load(
"other");
552 $mesg =
'<div class="error">';
553 if (!empty($mailfile->error) || !empty($mailfile->errors)) {
555 if (!empty($mailfile->error)) {
556 $mesg .=
'<br>'.$mailfile->error;
558 if (!empty($mailfile->errors) && is_array($mailfile->errors)) {
559 $mesg .=
'<br>'.implode(
'<br>', $mailfile->errors);
564 $mesg .=
'<br>Feature is disabled by option MAIN_DISABLE_ALL_MAILS';
566 $mesg .=
'<br>Unknown Error, please refer to your administrator';
571 setEventMessages($mesg,
null,
'warnings');
576 $langs->load(
"errors");
577 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"MailTo")),
null,
'warnings');
578 dol_syslog(
'Try to send email with no recipient defined', LOG_WARNING);
582 $langs->load(
"errors");
583 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
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_string_nospecial($str, $newstr='_', $badcharstoreplace='', $badcharstoremove='', $keepspaces=0)
Clean a string from all punctuation characters to use it as a ref or login.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
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.