48@phan-var-force Societe $mysoc
49@phan-var-force CommonObject $object
57if (
GETPOST(
'addfile',
'alpha')) {
58 $trackid =
GETPOST(
'trackid',
'aZ09');
60 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
63 $vardir = $conf->user->dir_output.
"/".$user->id;
64 $upload_dir_tmp = $vardir.
'/temp';
74 $trackid =
GETPOST(
'trackid',
'aZ09');
76 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
79 $vardir = $conf->user->dir_output.
"/".$user->id;
80 $upload_dir_tmp = $vardir.
'/temp';
91if (
GETPOST(
'removeAll',
'alpha')) {
92 $trackid =
GETPOST(
'trackid',
'aZ09');
94 $listofpaths = array();
95 $listofnames = array();
96 $listofmimes = array();
97 $keytoavoidconflict = empty($trackid) ?
'' :
'-'.$trackid;
98 if (!empty($_SESSION[
"listofpaths".$keytoavoidconflict])) {
99 $listofpaths = explode(
';', $_SESSION[
"listofpaths".$keytoavoidconflict]);
101 if (!empty($_SESSION[
"listofnames".$keytoavoidconflict])) {
102 $listofnames = explode(
';', $_SESSION[
"listofnames".$keytoavoidconflict]);
104 if (!empty($_SESSION[
"listofmimes".$keytoavoidconflict])) {
105 $listofmimes = explode(
';', $_SESSION[
"listofmimes".$keytoavoidconflict]);
108 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
110 $formmail->trackid = $trackid;
112 foreach ($listofpaths as $key => $value) {
113 $pathtodelete = $value;
114 $filetodelete = $listofnames[$key];
117 $langs->load(
"other");
118 setEventMessages($langs->trans(
"FileWasRemoved", $filetodelete),
null,
'mesgs');
120 $formmail->remove_attached_files($key);
127if (($action ==
'send' || $action ==
'relance') && !
GETPOST(
'addfile') && !
GETPOST(
'removeAll') && !
GETPOST(
'removedfile') && !
GETPOST(
'cancel') && !
GETPOST(
'modelselected')) {
128 if (empty($trackid)) {
129 $trackid =
GETPOST(
'trackid',
'aZ09');
133 $vardir = $conf->user->dir_output.
"/".$user->id;
134 $upload_dir_tmp = $vardir.
'/temp';
143 $langs->load(
'mails');
150 if (method_exists(
$object,
"fetch_thirdparty") && !in_array(
$object->element, array(
'member',
'user',
'expensereport',
'societe',
'contact'))) {
152 $thirdparty =
$object->thirdparty;
153 if (is_object($thirdparty)) {
154 $sendtosocid = $thirdparty->id;
156 } elseif (
$object->element ==
'member' ||
$object->element ==
'user') {
161 } elseif (
$object->element ==
'expensereport') {
162 $tmpuser =
new User($db);
163 $tmpuser->fetch(
$object->fk_user_author);
164 $thirdparty = $tmpuser;
168 } elseif (
$object->element ==
'societe') {
170 if (is_object($thirdparty) && $thirdparty->id > 0) {
171 $sendtosocid = $thirdparty->id;
173 } elseif (
$object->element ==
'contact') {
175 if ($contact->id > 0) {
176 $contact->fetch_thirdparty();
177 $thirdparty = $contact->thirdparty;
178 if (is_object($thirdparty) && $thirdparty->id > 0) {
179 $sendtosocid = $thirdparty->id;
183 dol_print_error(
null,
"Use actions_sendmails.in.php for an element/object '".
$object->element.
"' that is not supported");
186 if (is_object($hookmanager)) {
187 $parameters = array();
188 $reshook = $hookmanager->executeHooks(
'initSendToSocid', $parameters,
$object, $action);
201 $sendtouserid = array();
202 $sendtoccuserid = array();
205 $receiver =
GETPOST(
'receiver',
'alphawithlgt');
206 if (!is_array($receiver)) {
207 if ($receiver ==
'-1') {
210 $receiver = array($receiver);
215 if (trim(
GETPOST(
'sendto',
'alphawithlgt'))) {
217 $tmparray[] = trim(
GETPOST(
'sendto',
'alphawithlgt'));
220 if (trim(
GETPOST(
'tomail',
'alphawithlgt'))) {
222 $tmparray[] = trim(
GETPOST(
'tomail',
'alphawithlgt'));
225 if (count($receiver) > 0) {
227 foreach ($receiver as $key => $val) {
228 if ($val ==
'thirdparty') {
229 $tmparray[] =
dol_string_nospecial($thirdparty->getFullName($langs),
' ', array(
",")).
' <'.$thirdparty->email.
'>';
230 } elseif ($val ==
'contact') {
231 $tmparray[] =
dol_string_nospecial($contact->getFullName($langs),
' ', array(
",")).
' <'.$contact->email.
'>';
232 $sendtoid[] = $contact->id;
233 } elseif ($val &&
$object->element ==
'project' && empty(
$object->socid)) {
235 $ret = $contact->fetch((
int) $val);
236 if ($ret > 0 && !empty($contact->socid)) {
237 $thirdparty =
new Societe($db);
238 $thirdparty->fetch($contact->socid);
239 $tmparray[] = $thirdparty->contact_get_property((
int) $val,
'email');
240 $sendtoid[] = ((int) $val);
243 $tmparray[] = $thirdparty->contact_get_property((
int) $val,
'email');
244 $sendtoid[] = ((int) $val);
250 $receiveruser =
GETPOST(
'receiveruser',
'alphawithlgt');
251 if (is_array($receiveruser) && count($receiveruser) > 0) {
252 $fuserdest =
new User($db);
253 foreach ($receiveruser as $key => $val) {
254 $tmparray[] = $fuserdest->user_get_property($val,
'email');
255 $sendtouserid[] = $val;
260 $sendto = implode(
',', $tmparray);
263 $receivercc =
GETPOST(
'receivercc',
'alphawithlgt');
264 if (!is_array($receivercc)) {
265 if ($receivercc ==
'-1') {
266 $receivercc = array();
268 $receivercc = array($receivercc);
272 if (trim(
GETPOST(
'sendtocc',
'alphawithlgt'))) {
273 $tmparray[] = trim(
GETPOST(
'sendtocc',
'alphawithlgt'));
275 if (count($receivercc) > 0) {
276 foreach ($receivercc as $key => $val) {
277 if ($val ==
'thirdparty') {
279 $tmparray[] =
dol_string_nospecial((
string) $thirdparty->name,
' ', array(
",")).
' <'.$thirdparty->email.
'>';
280 } elseif ($val ==
'contact') {
282 $tmparray[] =
dol_string_nospecial((
string) $contact->name,
' ', array(
",")).
' <'.$contact->email.
'>';
285 $tmparray[] = $thirdparty->contact_get_property((
int) $val,
'email');
291 $receiverccuser =
GETPOST(
'receiverccuser',
'alphawithlgt');
293 if (is_array($receiverccuser) && count($receiverccuser) > 0) {
294 $fuserdest =
new User($db);
295 foreach ($receiverccuser as $key => $val) {
296 $tmparray[] = $fuserdest->user_get_property($val,
'email');
297 $sendtoccuserid[] = $val;
301 $sendtocc = implode(
',', $tmparray);
306 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
309 require_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
311 $langs->load(
"commercial");
314 $fromtype =
GETPOST(
'fromtype',
'alpha');
315 $emailsendersignature =
'';
316 if ($fromtype ===
'robot') {
318 } elseif ($fromtype ===
'user') {
319 $from =
dol_string_nospecial($user->getFullName($langs),
' ', array(
",")).
' <'.$user->email.
'>';
320 } elseif ($fromtype ===
'company') {
322 } elseif (preg_match(
'/user_aliases_(\d+)/', $fromtype, $reg)) {
323 $tmp = explode(
',', $user->email_aliases);
324 $from = trim($tmp[((
int) $reg[1] - 1)]);
325 } elseif (preg_match(
'/global_aliases_(\d+)/', $fromtype, $reg)) {
327 $from = trim($tmp[((
int) $reg[1] - 1)]);
328 } elseif (preg_match(
'/senderprofile_(\d+)_(\d+)/', $fromtype, $reg)) {
329 $sql =
'SELECT rowid, label, email, signature FROM '.MAIN_DB_PREFIX.
'c_email_senderprofile';
330 $sql .=
' WHERE rowid = '.(int) $reg[1];
331 $resql = $db->query($sql);
332 $obj = $db->fetch_object($resql);
335 $emailsendersignature = $obj->signature;
337 } elseif (preg_match(
'/from_template_(\d+)/', $fromtype, $reg)) {
338 $sql =
'SELECT rowid, email_from FROM '.MAIN_DB_PREFIX.
'c_email_templates';
339 $sql .=
' WHERE rowid = '.(int) $reg[1];
340 $resql = $db->query($sql);
341 $obj = $db->fetch_object($resql);
343 $from = $obj->email_from;
352 $replyto .= ($replyto ?
' ' :
'').
'<'.
GETPOST(
'replytomail').
'>';
355 $message =
GETPOST(
'message',
'restricthtml');
356 $subject =
GETPOST(
'subject',
'restricthtml');
362 $message = preg_replace(
'/(<img.*src=")[^\"]*viewimage\.php([^\"]*)modulepart=medias([^\"]*)file=([^\"]*)("[^\/]*\/>)/',
'\1'.$urlwithroot.
'/viewimage.php\2modulepart=medias\3file=\4\5', $message);
364 $sendtobcc =
GETPOST(
'sendtoccc',
'alphawithlgt');
367 if (!empty($autocopy)) {
371 $deliveryreceipt =
GETPOSTINT(
'deliveryreceipt') ? 1 : 0;
373 if ($action ==
'send' || $action ==
'relance') {
388 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
390 $formmail->trackid = $trackid;
392 $attachedfiles = $formmail->get_attached_files();
393 $filepath = $attachedfiles[
'paths'];
394 $filename = $attachedfiles[
'names'];
395 $mimetype = $attachedfiles[
'mimes'];
398 $substitutionarray = getCommonSubstitutionArray($langs, 0,
null,
$object);
400 $substitutionarray[
'__SENDEREMAIL_SIGNATURE__'] = (empty($emailsendersignature) ? $user->signature : $emailsendersignature);
401 $substitutionarray[
'__EMAIL__'] = $sendto;
402 $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"/>' :
'';
404 $parameters = array(
'mode' =>
'formemail');
410 if (is_object(
$object) && method_exists(
$object,
'makeSubstitution')) {
411 $subject =
$object->makeSubstitution($subject);
412 $message =
$object->makeSubstitution($message);
416 if (empty($sendcontext)) {
417 $sendcontext =
'standard';
419 $mailfile =
new CMailFile($subject, $sendto, $from, $message, $filepath, $mimetype, $filename, $sendtocc, $sendtobcc, $deliveryreceipt, -1,
'',
'', $trackid,
'', $sendcontext, $replyto, $upload_dir_tmp);
421 if (!empty($mailfile->error) || !empty($mailfile->errors)) {
425 $result = $mailfile->sendfile();
431 if (empty($actiontypecode)) {
432 $actiontypecode =
'AC_OTH_AUTO';
437 $object->actiontypecode = $actiontypecode;
439 $object->actionmsg2 = $actionmsg2;
441 $object->actionmsg2 = $subject;
447 if (is_array($attachedfiles) && count($attachedfiles) > 0) {
448 $object->attachedfiles = $attachedfiles;
450 if (is_array($sendtouserid) && count($sendtouserid) > 0 &&
getDolGlobalString(
'MAIN_MAIL_ENABLED_USER_DEST_SELECT')) {
451 $object->sendtouserid = $sendtouserid;
455 $object->context[
'email_msgid'] = $mailfile->msgid;
456 $object->context[
'email_from'] = $from;
457 $object->context[
'email_subject'] = $subject;
458 $object->context[
'email_to'] = $sendto;
459 $object->context[
'email_tocc'] = $sendtocc;
460 $object->context[
'email_tobcc'] = $sendtobcc;
462 $object->email_msgid = $mailfile->msgid;
464 $object->email_subject = $subject;
466 $object->email_tocc = $sendtocc;
467 $object->email_tobcc = $sendtobcc;
470 if (!empty($triggersendname)) {
471 if ($triggersendname ==
'BILL_SENTBYMAIL' &&
$object instanceof
Facture) {
475 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"facture SET email_sent_counter = email_sent_counter + 1";
476 $sql .=
" WHERE rowid = ".((int)
$object->id);
480 $object->email_sent_counter += 1;
483 $result =
$object->call_trigger($triggersendname, $user);
502 $mesg = $langs->trans(
'MailSuccessfulySent', $mailfile->getValidAddress($from, 2), $mailfile->getValidAddress($sendto, 2));
505 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?'.($paramname ??
'id').
'='.(is_object(
$object) ?
$object->id :
''));
508 $langs->load(
"other");
509 $mesg =
'<div class="error">';
510 if (!empty($mailfile->error) || !empty($mailfile->errors)) {
512 if (!empty($mailfile->error)) {
513 $mesg .=
'<br>'.$mailfile->error;
515 if (!empty($mailfile->errors) && is_array($mailfile->errors)) {
516 $mesg .=
'<br>'.implode(
'<br>', $mailfile->errors);
521 $mesg .=
'<br>Feature is disabled by option MAIN_DISABLE_ALL_MAILS';
523 $mesg .=
'<br>Unknown Error, please refer to your administrator';
533 $langs->load(
"errors");
534 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"MailTo")),
null,
'warnings');
535 dol_syslog(
'Try to send email with no recipient defined', LOG_WARNING);
539 $langs->load(
"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).
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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.
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...
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
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)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
dol_hash($chain, $type='0', $nosalt=0, $mode=0)
Returns a hash (non reversible encryption) of a string.