59 public $mixed_boundary;
60 public $related_boundary;
61 public $alternative_boundary;
62 public $deliveryreceipt;
64 public $atleastonefile;
92 public $filename_list = array();
96 public $mimetype_list = array();
100 public $mimefilename_list = array();
104 public $image_boundary;
105 public $atleastoneimage = 0;
106 public $html_images = array();
107 public $images_encoded = array();
108 public $image_types = array(
109 'gif' =>
'image/gif',
110 'jpg' =>
'image/jpeg',
111 'jpeg' =>
'image/jpeg',
112 'jpe' =>
'image/jpeg',
113 'bmp' =>
'image/bmp',
114 'png' =>
'image/png',
115 'tif' =>
'image/tiff',
116 'tiff' =>
'image/tiff',
141 public function __construct($subject, $to, $from, $msg, $filename_list = array(), $mimetype_list = array(), $mimefilename_list = array(), $addr_cc =
"", $addr_bcc =
"", $deliveryreceipt = 0, $msgishtml = 0, $errors_to =
'', $css =
'', $trackid =
'', $moreinheader =
'', $sendcontext =
'standard', $replyto =
'')
143 global $conf, $dolibarr_main_data_root, $user;
146 if (is_array($mimefilename_list)) {
147 foreach ($mimefilename_list as $key => $val) {
152 $this->sendcontext = $sendcontext;
155 $this->sendmode =
'';
156 if (!empty($this->sendcontext)) {
157 $smtpContextKey = strtoupper($this->sendcontext);
158 $keyForSMTPSendMode =
'MAIN_MAIL_SENDMODE_'.$smtpContextKey;
159 $smtpContextSendMode = empty($conf->global->{$keyForSMTPSendMode}) ?
'' : $conf->global->{$keyForSMTPSendMode};
160 if (!empty($smtpContextSendMode) && $smtpContextSendMode !=
'default') {
161 $this->sendmode = $smtpContextSendMode;
164 if (empty($this->sendmode)) {
165 $this->sendmode = (!empty($conf->global->MAIN_MAIL_SENDMODE) ? $conf->global->MAIN_MAIL_SENDMODE :
'mail');
171 $this->eol2 =
"\r\n";
172 if (!empty($conf->global->MAIN_FIX_FOR_BUGGED_MTA)) {
175 $moreinheader = str_replace(
"\r\n",
"\n", $moreinheader);
179 $this->mixed_boundary =
"multipart_x.".time().
".x_boundary";
182 $this->related_boundary =
'mul_'.dol_hash(uniqid(
"dolibarr2"), 3);
185 $this->alternative_boundary =
'mul_'.dol_hash(uniqid(
"dolibarr3"), 3);
187 dol_syslog(
"CMailFile::CMailfile: sendmode=".$this->sendmode.
" charset=".$conf->file->character_set_client.
" from=$from, to=$to, addr_cc=$addr_cc, addr_bcc=$addr_bcc, errors_to=$errors_to, replyto=$replyto trackid=$trackid sendcontext=$sendcontext", LOG_DEBUG);
188 dol_syslog(
"CMailFile::CMailfile: subject=".$subject.
", deliveryreceipt=".$deliveryreceipt.
", msgishtml=".$msgishtml, LOG_DEBUG);
190 if (empty($subject)) {
191 dol_syslog(
"CMailFile::CMailfile: Try to send an email with empty subject");
192 $this->error =
'ErrorSubjectIsRequired';
196 dol_syslog(
"CMailFile::CMailfile: Try to send an email with empty body");
201 if ($msgishtml == -1) {
202 $this->msgishtml = 0;
204 $this->msgishtml = 1;
207 $this->msgishtml = $msgishtml;
210 global $dolibarr_main_url_root;
213 $urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim($dolibarr_main_url_root));
214 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
218 $msg = preg_replace(
'/src="'.preg_quote(DOL_URL_ROOT,
'/').
'\/viewimage\.php/ims',
'src="'.$urlwithroot.
'/viewimage.php', $msg, -1);
220 if (!empty($conf->global->MAIN_MAIL_FORCE_CONTENT_TYPE_TO_HTML)) {
221 $this->msgishtml = 1;
225 if ($this->msgishtml) {
229 if (!empty($conf->global->MAIN_MAIL_ADD_INLINE_IMAGES_IF_IN_MEDIAS)) {
230 $findimg = $this->findHtmlImages($dolibarr_main_data_root.
'/medias');
235 foreach ($this->html_images as $i => $val) {
236 if ($this->html_images[$i]) {
237 $this->atleastoneimage = 1;
238 dol_syslog(
"CMailFile::CMailfile: html_images[$i]['name']=".$this->html_images[$i][
'name'], LOG_DEBUG);
245 if (is_array($filename_list)) {
246 foreach ($filename_list as $i => $val) {
247 if ($filename_list[$i]) {
248 $this->atleastonefile = 1;
249 dol_syslog(
"CMailFile::CMailfile: filename_list[$i]=".$filename_list[$i].
", mimetype_list[$i]=".$mimetype_list[$i].
" mimefilename_list[$i]=".$mimefilename_list[$i], LOG_DEBUG);
256 if (!empty($conf->global->MAIN_MAIL_AUTOCOPY_TO)) {
257 $listofemailstoadd = explode(
',', $conf->global->MAIN_MAIL_AUTOCOPY_TO);
258 foreach ($listofemailstoadd as $key => $val) {
259 $emailtoadd = $listofemailstoadd[$key];
260 if (trim($emailtoadd) ==
'__USER_EMAIL__') {
261 if (!empty($user) && !empty($user->email)) {
262 $emailtoadd = $user->email;
267 if ($emailtoadd && preg_match(
'/'.preg_quote($emailtoadd,
'/').
'/i', $to)) {
271 $listofemailstoadd[$key] = $emailtoadd;
273 unset($listofemailstoadd[$key]);
276 if (!empty($listofemailstoadd)) {
277 $addr_bcc .= ($addr_bcc ?
', ' :
'').join(
', ', $listofemailstoadd);
281 $this->subject = $subject;
282 $this->addr_to = $to;
283 $this->addr_from = $from;
285 $this->filename_list = $filename_list;
286 $this->mimetype_list = $mimetype_list;
287 $this->mimefilename_list = $mimefilename_list;
288 $this->addr_cc = $addr_cc;
289 $this->addr_bcc = $addr_bcc;
290 $this->deliveryreceipt = $deliveryreceipt;
291 if (empty($replyto)) {
294 $this->reply_to = $replyto;
295 $this->errors_to = $errors_to;
296 $this->trackid = $trackid;
297 $this->filename_list = $filename_list;
298 $this->mimetype_list = $mimetype_list;
299 $this->mimefilename_list = $mimefilename_list;
301 if (!empty($conf->global->MAIN_MAIL_FORCE_SENDTO)) {
302 $this->addr_to = $conf->global->MAIN_MAIL_FORCE_SENDTO;
304 $this->addr_bcc =
'';
307 $keyforsslseflsigned =
'MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED';
308 if (!empty($this->sendcontext)) {
309 $smtpContextKey = strtoupper($this->sendcontext);
310 $keyForSMTPSendMode =
'MAIN_MAIL_SENDMODE_'.$smtpContextKey;
311 $smtpContextSendMode = empty($conf->global->{$keyForSMTPSendMode}) ?
'' : $conf->global->{$keyForSMTPSendMode};
312 if (!empty($smtpContextSendMode) && $smtpContextSendMode !=
'default') {
313 $keyforsslseflsigned =
'MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED_'.$smtpContextKey;
319 if ($this->sendmode ==
'mail') {
329 $smtp_headers = $this->write_smtpheaders();
330 if (!empty($moreinheader)) {
331 $smtp_headers .= $moreinheader;
335 $mime_headers = $this->write_mimeheaders($filename_list, $mimefilename_list);
337 if (!empty($this->html)) {
347 $text_body = $this->write_body($msg);
350 if (!empty($this->atleastonefile)) {
351 $files_encoded = $this->write_files($filename_list, $mimetype_list, $mimefilename_list);
355 $this->headers = $smtp_headers.$mime_headers;
358 $this->headers = preg_replace(
"/([\r\n]+)$/i",
"", $this->headers);
361 $this->message =
'This is a message with multiple parts in MIME format.'.$this->eol;
362 $this->message .= $text_body.$files_encoded;
363 $this->message .=
"--".$this->mixed_boundary.
"--".$this->eol;
364 } elseif ($this->sendmode ==
'smtps') {
368 require_once DOL_DOCUMENT_ROOT.
'/core/class/smtps.class.php';
369 $smtps =
new SMTPs();
370 $smtps->setCharSet($conf->file->character_set_client);
373 $subjecttouse = $this->subject;
375 $subjecttouse = $this->encodetorfc2822($subjecttouse);
378 $smtps->setSubject($subjecttouse);
379 $smtps->setTO($this->getValidAddress($this->addr_to, 0, 1));
380 $smtps->setFrom($this->getValidAddress($this->addr_from, 0, 1));
381 $smtps->setTrackId($this->trackid);
382 $smtps->setReplyTo($this->getValidAddress($this->reply_to, 0, 1));
384 if (!empty($moreinheader)) {
385 $smtps->setMoreInHeader($moreinheader);
388 if (!empty($this->html)) {
394 $msg = $this->checkIfHTML($msg);
398 $msg = preg_replace(
'/(\r|\n)\.(\r|\n)/ims',
'\1..\2', $msg);
400 if ($this->msgishtml) {
401 $smtps->setBodyContent($msg,
'html');
403 $smtps->setBodyContent($msg,
'plain');
406 if ($this->atleastoneimage) {
407 foreach ($this->images_encoded as $img) {
408 $smtps->setImageInline($img[
'image_encoded'], $img[
'name'], $img[
'content_type'], $img[
'cid']);
412 if (!empty($this->atleastonefile)) {
413 foreach ($filename_list as $i => $val) {
414 $content = file_get_contents($filename_list[$i]);
415 $smtps->setAttachment($content, $mimefilename_list[$i], $mimetype_list[$i]);
419 $smtps->setCC($this->addr_cc);
420 $smtps->setBCC($this->addr_bcc);
421 $smtps->setErrorsTo($this->errors_to);
422 $smtps->setDeliveryReceipt($this->deliveryreceipt);
423 if (!empty($conf->global->$keyforsslseflsigned)) {
424 $smtps->setOptions(array(
'ssl' => array(
'verify_peer' =>
false,
'verify_peer_name' =>
false,
'allow_self_signed' =>
true)));
427 $host = dol_getprefix(
'email');
428 $this->msgid = time().
'.SMTPs-dolibarr-'.$this->trackid.
'@'.$host;
430 $this->smtps = $smtps;
431 } elseif ($this->sendmode ==
'swiftmailer') {
433 $host = dol_getprefix(
'email');
435 require_once DOL_DOCUMENT_ROOT.
'/includes/swiftmailer/lexer/lib/Doctrine/Common/Lexer/AbstractLexer.php';
438 require_once DOL_DOCUMENT_ROOT.
'/includes/swiftmailer/autoload.php';
440 require_once DOL_DOCUMENT_ROOT.
'/includes/swiftmailer/lib/swift_required.php';
444 $this->message =
new Swift_Message();
447 $headers = $this->message->getHeaders();
448 $headers->addTextHeader(
'X-Dolibarr-TRACKID', $this->trackid.
'@'.$host);
449 $this->msgid = time().
'.swiftmailer-dolibarr-'.$this->trackid.
'@'.$host;
450 $headerID = $this->msgid;
451 $msgid = $headers->get(
'Message-ID');
452 $msgid->setId($headerID);
453 $headers->addIdHeader(
'References', $headerID);
458 $result = $this->message->setSubject($this->subject);
460 $this->errors[] = $e->getMessage();
465 if (!empty($this->addr_from)) {
467 if (!empty($conf->global->MAIN_FORCE_DISABLE_MAIL_SPOOFING)) {
469 $regexp =
'/([a-z0-9_\.\-\+])+\@(([a-z0-9\-])+\.)+([a-z0-9]{2,4})+/i';
470 $emailMatchs = preg_match_all($regexp, $from, $adressEmailFrom);
471 $adressEmailFrom = reset($adressEmailFrom);
472 if ($emailMatchs !==
false && filter_var($conf->global->MAIN_MAIL_SMTPS_ID, FILTER_VALIDATE_EMAIL) && $conf->global->MAIN_MAIL_SMTPS_ID !== $adressEmailFrom) {
473 $result = $this->message->setFrom($conf->global->MAIN_MAIL_SMTPS_ID);
475 $result = $this->message->setFrom($this->getArrayAddress($this->addr_from));
478 $result = $this->message->setFrom($this->getArrayAddress($this->addr_from));
481 $this->errors[] = $e->getMessage();
486 if (!empty($this->addr_to)) {
488 $result = $this->message->setTo($this->getArrayAddress($this->addr_to));
490 $this->errors[] = $e->getMessage();
494 if (!empty($this->reply_to)) {
496 $result = $this->message->SetReplyTo($this->getArrayAddress($this->reply_to));
498 $this->errors[] = $e->getMessage();
503 $result = $this->message->setCharSet($conf->file->character_set_client);
505 $this->errors[] = $e->getMessage();
508 if (!empty($this->html)) {
514 $msg = $this->checkIfHTML($msg);
517 if ($this->atleastoneimage) {
518 foreach ($this->images_encoded as $img) {
520 $attachment = Swift_Image::fromPath($img[
'fullpath']);
522 $imgcid = $this->message->embed($attachment);
524 $msg = str_replace(
"cid:".$img[
'cid'], $imgcid, $msg);
528 if ($this->msgishtml) {
529 $this->message->setBody($msg,
'text/html');
531 $this->message->addPart(html_entity_decode(strip_tags($msg)),
'text/plain');
533 $this->message->setBody($msg,
'text/plain');
535 $this->message->addPart(
dol_nl2br($msg),
'text/html');
538 if (!empty($this->atleastonefile)) {
539 foreach ($filename_list as $i => $val) {
541 $attachment = Swift_Attachment::fromPath($filename_list[$i], $mimetype_list[$i]);
542 if (!empty($mimefilename_list[$i])) {
543 $attachment->setFilename($mimefilename_list[$i]);
545 $this->message->attach($attachment);
549 if (!empty($this->addr_cc)) {
550 $this->message->setCc($this->getArrayAddress($this->addr_cc));
552 if (!empty($this->addr_bcc)) {
553 $this->message->setBcc($this->getArrayAddress($this->addr_bcc));
556 if (isset($this->deliveryreceipt) && $this->deliveryreceipt == 1) {
557 $this->message->setReadReceiptTo($this->getArrayAddress($this->addr_from));
562 $this->error =
'Bad value for sendmode';
574 global $conf, $db, $langs;
576 $errorlevel = error_reporting();
581 if (empty($conf->global->MAIN_DISABLE_ALL_MAILS)) {
582 require_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
584 $hookmanager->initHooks(array(
'mail'));
586 $parameters = array();
588 $reshook = $hookmanager->executeHooks(
'sendMail', $parameters, $this, $action);
590 $this->error =
"Error in hook maildao sendMail ".$reshook;
591 dol_syslog(
"CMailFile::sendfile: mail end error=".$this->error, LOG_ERR);
599 $sendingmode = $this->sendmode;
600 if ($this->sendcontext ==
'emailing' && !empty($conf->global->MAILING_NO_USING_PHPMAIL) && $sendingmode ==
'mail') {
602 $listofmethods = array();
603 $listofmethods[
'mail'] =
'PHP mail function';
605 $listofmethods[
'smtps'] =
'SMTP/SMTPS socket library';
609 $linktoadminemailbefore =
'<a href="'.DOL_URL_ROOT.
'/admin/mails.php">';
610 $linktoadminemailend =
'</a>';
611 $this->error = $langs->trans(
"MailSendSetupIs", $listofmethods[$sendingmode]);
612 $this->errors[] = $langs->trans(
"MailSendSetupIs", $listofmethods[$sendingmode]);
613 $this->error .=
'<br>'.$langs->trans(
"MailSendSetupIs2", $linktoadminemailbefore, $linktoadminemailend, $langs->transnoentitiesnoconv(
"MAIN_MAIL_SENDMODE"), $listofmethods[
'smtps']);
614 $this->errors[] = $langs->trans(
"MailSendSetupIs2", $linktoadminemailbefore, $linktoadminemailend, $langs->transnoentitiesnoconv(
"MAIN_MAIL_SENDMODE"), $listofmethods[
'smtps']);
615 if (!empty($conf->global->MAILING_SMTP_SETUP_EMAILS_FOR_QUESTIONS)) {
616 $this->error .=
'<br>'.$langs->trans(
"MailSendSetupIs3", $conf->global->MAILING_SMTP_SETUP_EMAILS_FOR_QUESTIONS);
617 $this->errors[] = $langs->trans(
"MailSendSetupIs3", $conf->global->MAILING_SMTP_SETUP_EMAILS_FOR_QUESTIONS);
623 if (empty($conf->global->MAIL_MAX_NB_OF_RECIPIENTS_TO_IN_SAME_EMAIL)) {
624 $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_TO_IN_SAME_EMAIL = 10;
626 $tmparray1 = explode(
',', $this->addr_to);
627 if (count($tmparray1) > $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_TO_IN_SAME_EMAIL) {
628 $this->error =
'Too much recipients in to:';
629 dol_syslog(
"CMailFile::sendfile: mail end error=".$this->error, LOG_WARNING);
632 if (empty($conf->global->MAIL_MAX_NB_OF_RECIPIENTS_CC_IN_SAME_EMAIL)) {
633 $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_CC_IN_SAME_EMAIL = 10;
635 $tmparray2 = explode(
',', $this->addr_cc);
636 if (count($tmparray2) > $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_CC_IN_SAME_EMAIL) {
637 $this->error =
'Too much recipients in cc:';
638 dol_syslog(
"CMailFile::sendfile: mail end error=".$this->error, LOG_WARNING);
641 if (empty($conf->global->MAIL_MAX_NB_OF_RECIPIENTS_BCC_IN_SAME_EMAIL)) {
642 $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_BCC_IN_SAME_EMAIL = 10;
644 $tmparray3 = explode(
',', $this->addr_bcc);
645 if (count($tmparray3) > $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_BCC_IN_SAME_EMAIL) {
646 $this->error =
'Too much recipients in bcc:';
647 dol_syslog(
"CMailFile::sendfile: mail end error=".$this->error, LOG_WARNING);
650 if (empty($conf->global->MAIL_MAX_NB_OF_RECIPIENTS_IN_SAME_EMAIL)) {
651 $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_IN_SAME_EMAIL = 10;
653 if ((count($tmparray1) + count($tmparray2) + count($tmparray3)) > $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_IN_SAME_EMAIL) {
654 $this->error =
'Too much recipients in to:, cc:, bcc:';
655 dol_syslog(
"CMailFile::sendfile: mail end error=".$this->error, LOG_WARNING);
659 $keyforsmtpserver =
'MAIN_MAIL_SMTP_SERVER';
660 $keyforsmtpport =
'MAIN_MAIL_SMTP_PORT';
661 $keyforsmtpid =
'MAIN_MAIL_SMTPS_ID';
662 $keyforsmtppw =
'MAIN_MAIL_SMTPS_PW';
663 $keyfortls =
'MAIN_MAIL_EMAIL_TLS';
664 $keyforstarttls =
'MAIN_MAIL_EMAIL_STARTTLS';
665 $keyforsslseflsigned =
'MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED';
666 if (!empty($this->sendcontext)) {
667 $smtpContextKey = strtoupper($this->sendcontext);
668 $keyForSMTPSendMode =
'MAIN_MAIL_SENDMODE_'.$smtpContextKey;
669 $smtpContextSendMode = empty($conf->global->{$keyForSMTPSendMode}) ?
'' : $conf->global->{$keyForSMTPSendMode};
670 if (!empty($smtpContextSendMode) && $smtpContextSendMode !=
'default') {
671 $keyforsmtpserver =
'MAIN_MAIL_SMTP_SERVER_'.$smtpContextKey;
672 $keyforsmtpport =
'MAIN_MAIL_SMTP_PORT_'.$smtpContextKey;
673 $keyforsmtpid =
'MAIN_MAIL_SMTPS_ID_'.$smtpContextKey;
674 $keyforsmtppw =
'MAIN_MAIL_SMTPS_PW_'.$smtpContextKey;
675 $keyfortls =
'MAIN_MAIL_EMAIL_TLS_'.$smtpContextKey;
676 $keyforstarttls =
'MAIN_MAIL_EMAIL_STARTTLS_'.$smtpContextKey;
677 $keyforsslseflsigned =
'MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED_'.$smtpContextKey;
682 if ($this->sendmode ==
'mail') {
685 dol_syslog(
"CMailFile::sendfile addr_to=".$this->addr_to.
", subject=".$this->subject, LOG_DEBUG);
686 dol_syslog(
"CMailFile::sendfile header=\n".$this->headers, LOG_DEBUG);
690 if (isset($_SERVER[
"WINDIR"])) {
691 if (empty($this->addr_from)) {
692 $this->addr_from =
'robot@example.com';
694 @ini_set(
'sendmail_from', $this->getValidAddress($this->addr_from, 2));
699 if (!empty($conf->global->$keyforsmtpserver)) {
700 ini_set(
'SMTP', $conf->global->$keyforsmtpserver);
702 if (!empty($conf->global->$keyforsmtpport)) {
703 ini_set(
'smtp_port', $conf->global->$keyforsmtpport);
707 if ($res && !$this->subject) {
708 $this->error =
"Failed to send mail with php mail to HOST=".ini_get(
'SMTP').
", PORT=".ini_get(
'smtp_port').
"<br>Subject is empty";
709 dol_syslog(
"CMailFile::sendfile: mail end error=".$this->error, LOG_ERR);
712 $dest = $this->getValidAddress($this->addr_to, 2);
713 if ($res && !$dest) {
714 $this->error =
"Failed to send mail with php mail to HOST=".ini_get(
'SMTP').
", PORT=".ini_get(
'smtp_port').
"<br>Recipient address '$dest' invalid";
715 dol_syslog(
"CMailFile::sendfile: mail end error=".$this->error, LOG_ERR);
720 $additionnalparam =
'';
721 if (!empty($conf->global->MAIN_MAIL_ALLOW_SENDMAIL_F)) {
726 $additionnalparam .= ($additionnalparam ?
' ' :
'').(!empty($conf->global->MAIN_MAIL_ERRORS_TO) ?
'-f'.$this->getValidAddress($conf->global->MAIN_MAIL_ERRORS_TO, 2) : ($this->addr_from !=
'' ?
'-f'.$this->getValidAddress($this->addr_from, 2) :
''));
728 if (!empty($conf->global->MAIN_MAIL_SENDMAIL_FORCE_BA)) {
729 $additionnalparam .= ($additionnalparam ?
' ' :
'').
'-ba';
732 if (!empty($conf->global->MAIN_MAIL_SENDMAIL_FORCE_ADDPARAM)) {
733 $additionnalparam .= ($additionnalparam ?
' ' :
'').
'-U '.$additionnalparam;
737 if (preg_match(
'/^win/i', PHP_OS)) {
740 if (preg_match(
'/^mac/i', PHP_OS)) {
744 dol_syslog(
"CMailFile::sendfile: mail start".($linuxlike ?
'' :
" HOST=".ini_get(
'SMTP').
", PORT=".ini_get(
'smtp_port')).
", additionnal_parameters=".$additionnalparam, LOG_DEBUG);
746 $this->message = stripslashes($this->message);
748 if (!empty($conf->global->MAIN_MAIL_DEBUG)) {
753 $subjecttouse = $this->subject;
755 $subjecttouse = $this->encodetorfc2822($subjecttouse);
758 if (!empty($additionnalparam)) {
759 $res = mail($dest, $subjecttouse, $this->message, $this->headers, $additionnalparam);
761 $res = mail($dest, $subjecttouse, $this->message, $this->headers);
765 $langs->load(
"errors");
766 $this->error =
"Failed to send mail with php mail";
768 $this->error .=
" to HOST=".ini_get(
'SMTP').
", PORT=".ini_get(
'smtp_port');
770 $this->error .=
".<br>";
771 $this->error .= $langs->trans(
"ErrorPhpMailDelivery");
772 dol_syslog(
"CMailFile::sendfile: mail end error=".$this->error, LOG_ERR);
774 dol_syslog(
"CMailFile::sendfile: mail end success", LOG_DEBUG);
778 if (isset($_SERVER[
"WINDIR"])) {
779 @ini_restore(
'sendmail_from');
783 if (!empty($conf->global->$keyforsmtpserver)) {
786 if (!empty($conf->global->$keyforsmtpport)) {
787 ini_restore(
'smtp_port');
789 } elseif ($this->sendmode ==
'smtps') {
790 if (!is_object($this->smtps)) {
791 $this->error =
"Failed to send mail with smtps lib to HOST=".$server.
", PORT=".$conf->global->$keyforsmtpport.
"<br>Constructor of object CMailFile was not initialized without errors.";
792 dol_syslog(
"CMailFile::sendfile: mail end error=".$this->error, LOG_ERR);
798 $this->smtps->setTransportType(0);
801 if (empty($conf->global->$keyforsmtpserver)) {
802 $conf->global->$keyforsmtpserver = ini_get(
'SMTP');
804 if (empty($conf->global->$keyforsmtpport)) {
805 $conf->global->$keyforsmtpport = ini_get(
'smtp_port');
809 $server = $conf->global->$keyforsmtpserver;
811 if (!empty($conf->global->$keyfortls) && function_exists(
'openssl_open')) {
814 if (!empty($conf->global->$keyforstarttls) && function_exists(
'openssl_open')) {
817 $server = ($secure ? $secure.
'://' :
'').$server;
819 $port = $conf->global->$keyforsmtpport;
821 $this->smtps->setHost($server);
822 $this->smtps->setPort($port);
826 if (!empty($conf->global->$keyforsmtpid)) {
827 $loginid = $conf->global->$keyforsmtpid;
828 $this->smtps->setID($loginid);
830 if (!empty($conf->global->$keyforsmtppw)) {
831 $loginpass = $conf->global->$keyforsmtppw;
832 $this->smtps->setPW($loginpass);
836 $from = $this->smtps->getFrom(
'org');
837 if ($res && !$from) {
838 $this->error =
"Failed to send mail with smtps lib to HOST=".$server.
", PORT=".$conf->global->$keyforsmtpport.
" - Sender address '$from' invalid";
839 dol_syslog(
"CMailFile::sendfile: mail end error=".$this->error, LOG_ERR);
842 $dest = $this->smtps->getTo();
843 if ($res && !$dest) {
844 $this->error =
"Failed to send mail with smtps lib to HOST=".$server.
", PORT=".$conf->global->$keyforsmtpport.
" - Recipient address '$dest' invalid";
845 dol_syslog(
"CMailFile::sendfile: mail end error=".$this->error, LOG_ERR);
850 if (!empty($conf->global->MAIN_MAIL_DEBUG)) {
851 $this->smtps->setDebug(
true);
854 $result = $this->smtps->sendMsg();
857 if (!empty($conf->global->MAIN_MAIL_DEBUG)) {
861 $result = $this->smtps->getErrors();
862 if (empty($this->error) && empty($result)) {
863 dol_syslog(
"CMailFile::sendfile: mail end success", LOG_DEBUG);
866 if (empty($this->error)) {
867 $this->error = $result;
869 dol_syslog(
"CMailFile::sendfile: mail end error with smtps lib to HOST=".$server.
", PORT=".$conf->global->$keyforsmtpport.
" - ".$this->error, LOG_ERR);
873 } elseif ($this->sendmode ==
'swiftmailer') {
876 require_once DOL_DOCUMENT_ROOT.
'/includes/swiftmailer/lib/swift_required.php';
879 if (empty($conf->global->$keyforsmtpserver)) {
880 $conf->global->$keyforsmtpserver = ini_get(
'SMTP');
882 if (empty($conf->global->$keyforsmtpport)) {
883 $conf->global->$keyforsmtpport = ini_get(
'smtp_port');
887 $server = $conf->global->$keyforsmtpserver;
889 if (!empty($conf->global->$keyfortls) && function_exists(
'openssl_open')) {
892 if (!empty($conf->global->$keyforstarttls) && function_exists(
'openssl_open')) {
896 $this->transport =
new Swift_SmtpTransport($server, $conf->global->$keyforsmtpport, $secure);
898 if (!empty($conf->global->$keyforsmtpid)) {
899 $this->transport->setUsername($conf->global->$keyforsmtpid);
901 if (!empty($conf->global->$keyforsmtppw)) {
902 $this->transport->setPassword($conf->global->$keyforsmtppw);
904 if (!empty($conf->global->$keyforsslseflsigned)) {
905 $this->transport->setStreamOptions(array(
'ssl' => array(
'allow_self_signed' =>
true,
'verify_peer' =>
false)));
910 $contentEncoderBase64 =
new Swift_Mime_ContentEncoder_Base64ContentEncoder();
911 $this->message->setEncoder($contentEncoderBase64);
914 $this->mailer =
new Swift_Mailer($this->transport);
917 if ($conf->global->MAIN_MAIL_EMAIL_DKIM_ENABLED) {
918 $privateKey = $conf->global->MAIN_MAIL_EMAIL_DKIM_PRIVATE_KEY;
919 $domainName = $conf->global->MAIN_MAIL_EMAIL_DKIM_DOMAIN;
920 $selector = $conf->global->MAIN_MAIL_EMAIL_DKIM_SELECTOR;
921 $signer =
new Swift_Signers_DKIMSigner($privateKey, $domainName, $selector);
922 $this->message->attachSigner($signer->ignoreHeader(
'Return-Path'));
925 if (!empty($conf->global->MAIN_MAIL_DEBUG)) {
927 $this->logger =
new Swift_Plugins_Loggers_ArrayLogger();
930 $this->mailer->registerPlugin(
new Swift_Plugins_LoggerPlugin($this->logger));
934 $result = $this->mailer->send($this->message, $failedRecipients);
936 $this->error = $e->getMessage();
938 if (!empty($conf->global->MAIN_MAIL_DEBUG)) {
943 if (!empty($this->error) || !$result) {
944 if (!empty($failedRecipients)) {
945 $this->error =
'Transport failed for the following addresses: "' . join(
'", "', $failedRecipients) .
'".';
947 dol_syslog(
"CMailFile::sendfile: mail end error=".$this->error, LOG_ERR);
950 dol_syslog(
"CMailFile::sendfile: mail end success", LOG_DEBUG);
956 return 'Bad value for sendmode';
959 $parameters = array();
961 $reshook = $hookmanager->executeHooks(
'sendMailAfter', $parameters, $this, $action);
963 $this->error =
"Error in hook maildao sendMailAfter ".$reshook;
964 dol_syslog(
"CMailFile::sendfile: mail end error=".$this->error, LOG_ERR);
969 $this->error =
'No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS';
970 dol_syslog(
"CMailFile::sendfile: ".$this->error, LOG_WARNING);
973 error_reporting($errorlevel);
987 return '=?'.$conf->file->character_set_client.
'?B?'.base64_encode($stringtoencode).
'?=';
1002 if (is_readable($newsourcefile)) {
1003 $contents = file_get_contents($newsourcefile);
1004 $encoded = chunk_split(base64_encode($contents), 76, $this->eol);
1007 $this->error =
"Error: Can't read file '".$sourcefile.
"' into _encode_file";
1008 dol_syslog(
"CMailFile::encode_file: ".$this->error, LOG_ERR);
1025 global $conf, $dolibarr_main_data_root;
1027 if (@is_writeable($dolibarr_main_data_root)) {
1028 $outputfile = $dolibarr_main_data_root.
"/dolibarr_mail.log";
1029 $fp = fopen($outputfile,
"w");
1031 if ($this->sendmode ==
'mail') {
1032 fputs($fp, $this->headers);
1033 fputs($fp, $this->eol);
1034 fputs($fp, $this->message);
1035 } elseif ($this->sendmode ==
'smtps') {
1036 fputs($fp, $this->smtps->log);
1037 } elseif ($this->sendmode ==
'swiftmailer') {
1038 fputs($fp, $this->logger->dump());
1042 if (!empty($conf->global->MAIN_UMASK)) {
1043 @chmod($outputfile, octdec($conf->global->MAIN_UMASK));
1057 if (!preg_match(
'/^[\s\t]*<html/i', $msg)) {
1058 $out =
"<html><head><title></title>";
1059 if (!empty($this->styleCSS)) {
1060 $out .= $this->styleCSS;
1062 $out .=
"</head><body";
1063 if (!empty($this->bodyCSS)) {
1064 $out .= $this->bodyCSS;
1068 $out .=
"</body></html>";
1083 if (!empty($this->css)) {
1085 $this->styleCSS =
'<style type="text/css">';
1086 $this->styleCSS .=
'body {';
1088 if ($this->css[
'bgcolor']) {
1089 $this->styleCSS .=
' background-color: '.$this->css[
'bgcolor'].
';';
1090 $this->bodyCSS .=
' bgcolor="'.$this->css[
'bgcolor'].
'"';
1092 if ($this->css[
'bgimage']) {
1094 $this->styleCSS .=
' background-image: url("cid:'.$this->css[
'bgimage_cid'].
'");';
1096 $this->styleCSS .=
'}';
1097 $this->styleCSS .=
'</style>';
1114 $host = dol_getprefix(
'email');
1118 $out .=
"From: ".$this->getValidAddress($this->addr_from, 3, 1).$this->eol2;
1119 if (!empty($conf->global->MAIN_MAIL_SENDMAIL_FORCE_BA)) {
1120 $out .=
"To: ".$this->getValidAddress($this->addr_to, 0, 1).$this->eol2;
1123 $out .=
"Return-Path: ".$this->getValidAddress($this->addr_from, 0, 1).$this->eol2;
1124 if (isset($this->reply_to) && $this->reply_to) {
1125 $out .=
"Reply-To: ".$this->getValidAddress($this->reply_to, 2).$this->eol2;
1127 if (isset($this->errors_to) && $this->errors_to) {
1128 $out .=
"Errors-To: ".$this->getValidAddress($this->errors_to, 2).$this->eol2;
1132 if (isset($this->addr_cc) && $this->addr_cc) {
1133 $out .=
"Cc: ".$this->getValidAddress($this->addr_cc, 2).$this->eol2;
1135 if (isset($this->addr_bcc) && $this->addr_bcc) {
1136 $out .=
"Bcc: ".$this->getValidAddress($this->addr_bcc, 2).$this->eol2;
1140 if (isset($this->deliveryreceipt) && $this->deliveryreceipt == 1) {
1141 $out .=
"Disposition-Notification-To: ".$this->getValidAddress($this->addr_from, 2).$this->eol2;
1146 $out .=
'Date: '.date(
"r").$this->eol2;
1148 $trackid = $this->trackid;
1151 $this->msgid = time().
'.phpmail-dolibarr-'.$trackid.
'@'.$host;
1152 $out .=
'Message-ID: <'.$this->msgid.
">".$this->eol2;
1153 $out .=
'References: <'.$this->msgid.
">".$this->eol2;
1154 $out .=
'X-Dolibarr-TRACKID: '.$trackid.
'@'.$host.$this->eol2;
1156 $this->msgid = time().
'.phpmail@'.$host;
1157 $out .=
'Message-ID: <'.$this->msgid.
">".$this->eol2;
1160 if (!empty($_SERVER[
'REMOTE_ADDR'])) {
1161 $out .=
"X-RemoteAddr: ".$_SERVER[
'REMOTE_ADDR'].$this->eol2;
1163 $out .=
"X-Mailer: Dolibarr version ".DOL_VERSION.
" (using php mail)".$this->eol2;
1164 $out .=
"Mime-Version: 1.0".$this->eol2;
1168 $out .=
"Content-Type: multipart/mixed;".$this->eol2.
" boundary=\"".$this->mixed_boundary.
"\"".$this->eol2;
1169 $out .=
"Content-Transfer-Encoding: 8bit".$this->eol2;
1171 dol_syslog(
"CMailFile::write_smtpheaders smtp_header=\n".$out);
1190 if (is_array($filename_list)) {
1191 $filename_list_size = count($filename_list);
1192 for ($i = 0; $i < $filename_list_size; $i++) {
1193 if ($filename_list[$i]) {
1194 if ($mimefilename_list[$i]) {
1195 $filename_list[$i] = $mimefilename_list[$i];
1197 $out .=
"X-attachments: $filename_list[$i]".$this->eol2;
1202 dol_syslog(
"CMailFile::write_mimeheaders mime_header=\n".$out, LOG_DEBUG);
1220 $out .=
"--".$this->mixed_boundary.$this->eol;
1222 if ($this->atleastoneimage) {
1223 $out .=
"Content-Type: multipart/alternative;".$this->eol.
" boundary=\"".$this->alternative_boundary.
"\"".$this->eol;
1225 $out .=
"--".$this->alternative_boundary.$this->eol;
1229 $strContent = preg_replace(
"/(?<!\r)\n/si",
"\r\n", $msgtext);
1230 if (!empty($conf->global->MAIN_FIX_FOR_BUGGED_MTA)) {
1231 $strContent = preg_replace(
"/\r\n/si",
"\n", $strContent);
1234 $strContentAltText =
'';
1235 if ($this->msgishtml) {
1237 $strContentAltText = preg_replace(
"/<br\s*[^>]*>/",
" ", $strContent);
1238 $strContentAltText = html_entity_decode(strip_tags($strContentAltText));
1239 $strContentAltText = trim(wordwrap($strContentAltText, 75, empty($conf->global->MAIN_FIX_FOR_BUGGED_MTA) ?
"\r\n" :
"\n"));
1242 $strContent = $this->checkIfHTML($strContent);
1248 $strContent = rtrim(wordwrap($strContent, 75, empty($conf->global->MAIN_FIX_FOR_BUGGED_MTA) ?
"\r\n" :
"\n"));
1250 if ($this->msgishtml) {
1251 if ($this->atleastoneimage) {
1252 $out .=
"Content-Type: text/plain; charset=".$conf->file->character_set_client.$this->eol;
1254 $out .= $this->eol.($strContentAltText ? $strContentAltText : strip_tags($strContent)).$this->eol;
1255 $out .=
"--".$this->alternative_boundary.$this->eol;
1256 $out .=
"Content-Type: multipart/related;".$this->eol.
" boundary=\"".$this->related_boundary.
"\"".$this->eol;
1258 $out .=
"--".$this->related_boundary.$this->eol;
1261 if (!$this->atleastoneimage && $strContentAltText && !empty($conf->global->MAIN_MAIL_USE_MULTI_PART)) {
1262 $out .=
"Content-Type: multipart/alternative;".$this->eol.
" boundary=\"".$this->alternative_boundary.
"\"".$this->eol;
1264 $out .=
"--".$this->alternative_boundary.$this->eol;
1265 $out .=
"Content-Type: text/plain; charset=".$conf->file->character_set_client.$this->eol;
1267 $out .= $this->eol.$strContentAltText.$this->eol;
1268 $out .=
"--".$this->alternative_boundary.$this->eol;
1271 $out .=
"Content-Type: text/html; charset=".$conf->file->character_set_client.$this->eol;
1273 $out .= $this->eol.$strContent.$this->eol;
1275 if (!$this->atleastoneimage && $strContentAltText && !empty($conf->global->MAIN_MAIL_USE_MULTI_PART)) {
1276 $out .=
"--".$this->alternative_boundary.
"--".$this->eol;
1279 $out .=
"Content-Type: text/plain; charset=".$conf->file->character_set_client.$this->eol;
1281 $out .= $this->eol.$strContent.$this->eol;
1287 if ($this->atleastoneimage) {
1288 $out .= $this->write_images($this->images_encoded);
1290 $out .=
"--".$this->related_boundary.
"--".$this->eol;
1291 $out .= $this->eol.
"--".$this->alternative_boundary.
"--".$this->eol;
1307 public function write_files($filename_list, $mimetype_list, $mimefilename_list)
1312 $filename_list_size = count($filename_list);
1313 for ($i = 0; $i < $filename_list_size; $i++) {
1314 if ($filename_list[$i]) {
1316 $encoded = $this->_encode_file($filename_list[$i]);
1317 if ($encoded >= 0) {
1318 if ($mimefilename_list[$i]) {
1319 $filename_list[$i] = $mimefilename_list[$i];
1321 if (!$mimetype_list[$i]) {
1322 $mimetype_list[$i] =
"application/octet-stream";
1325 $out .=
"--".$this->mixed_boundary.$this->eol;
1326 $out .=
"Content-Disposition: attachment; filename=\"".$filename_list[$i].
"\"".$this->eol;
1327 $out .=
"Content-Type: ".$mimetype_list[$i].
"; name=\"".$filename_list[$i].
"\"".$this->eol;
1328 $out .=
"Content-Transfer-Encoding: base64".$this->eol;
1329 $out .=
"Content-Description: ".$filename_list[$i].$this->eol;
1356 if (is_array($images_list)) {
1357 foreach ($images_list as $img) {
1358 dol_syslog(
"CMailFile::write_images: ".$img[
"name"]);
1360 $out .=
"--".$this->related_boundary.$this->eol;
1361 $out .=
"Content-Type: ".$img[
"content_type"].
"; name=\"".$img[
"name"].
"\"".$this->eol;
1362 $out .=
"Content-Transfer-Encoding: base64".$this->eol;
1363 $out .=
"Content-Disposition: inline; filename=\"".$img[
"name"].
"\"".$this->eol;
1364 $out .=
"Content-ID: <".$img[
"cid"].
">".$this->eol;
1366 $out .= $img[
"image_encoded"];
1391 if (function_exists(
'fsockopen')) {
1392 $keyforsmtpserver =
'MAIN_MAIL_SMTP_SERVER';
1393 $keyforsmtpport =
'MAIN_MAIL_SMTP_PORT';
1394 $keyforsmtpid =
'MAIN_MAIL_SMTPS_ID';
1395 $keyforsmtppw =
'MAIN_MAIL_SMTPS_PW';
1396 $keyfortls =
'MAIN_MAIL_EMAIL_TLS';
1397 $keyforstarttls =
'MAIN_MAIL_EMAIL_STARTTLS';
1398 if ($this->sendcontext ==
'emailing' && !empty($conf->global->MAIN_MAIL_SENDMODE_EMAILING) && $conf->global->MAIN_MAIL_SENDMODE_EMAILING !=
'default') {
1399 $keyforsmtpserver =
'MAIN_MAIL_SMTP_SERVER_EMAILING';
1400 $keyforsmtpport =
'MAIN_MAIL_SMTP_PORT_EMAILING';
1401 $keyforsmtpid =
'MAIN_MAIL_SMTPS_ID_EMAILING';
1402 $keyforsmtppw =
'MAIN_MAIL_SMTPS_PW_EMAILING';
1403 $keyfortls =
'MAIN_MAIL_EMAIL_TLS_EMAILING';
1404 $keyforstarttls =
'MAIN_MAIL_EMAIL_STARTTLS_EMAILING';
1408 if (!empty($conf->global->$keyfortls) && function_exists(
'openssl_open')) {
1409 $host =
'ssl://'.$host;
1414 dol_syslog(
"Try socket connection to host=".$host.
" port=".$port);
1416 if ($socket = @fsockopen(
1424 if (function_exists(
'stream_set_timeout')) {
1425 stream_set_timeout($socket, $timeout, 0);
1431 if ($_retVal = $this->server_parse($socket,
"220")) {
1435 $this->error =
utf8_check(
'Error '.$errno.
' - '.$errstr) ?
'Error '.$errno.
' - '.$errstr : utf8_encode(
'Error '.$errno.
' - '.$errstr);
1454 $server_response =
'';
1456 while (substr($server_response, 3, 1) !=
' ') {
1457 if (!($server_response = fgets($socket, 256))) {
1458 $this->error =
"Couldn't get mail server response codes";
1463 if (!(substr($server_response, 0, 3) == $response)) {
1464 $this->error =
"Ran into problems sending Mail.\r\nResponse: $server_response";
1480 $extensions = array_keys($this->image_types);
1483 preg_match_all(
'/(?:"|\')([^"\']+\.('.implode(
'|', $extensions).
'))(?:"|\')/Ui', $this->html, $matches);
1485 if (!empty($matches)) {
1487 foreach ($matches[1] as $full) {
1488 if (preg_match(
'/file=([A-Za-z0-9_\-\/]+[\.]?[A-Za-z0-9]+)?$/i', $full, $regs)) {
1491 if (file_exists($images_dir.
'/'.$img)) {
1493 $src = preg_quote($full,
'/');
1496 $this->html_images[$i][
"fullpath"] = $images_dir.
'/'.$img;
1499 $this->html_images[$i][
"name"] = $img;
1502 if (preg_match(
'/^.+\.(\w{3,4})$/', $img, $reg)) {
1503 $ext = strtolower($reg[1]);
1504 $this->html_images[$i][
"content_type"] = $this->image_types[$ext];
1508 $this->html_images[$i][
"cid"] =
dol_hash(uniqid(time()), 3);
1509 $this->html = preg_replace(
"/src=\"$src\"|src='$src'/i",
"src=\"cid:".$this->html_images[$i][
"cid"].
"\"", $this->html);
1515 if (!empty($this->html_images)) {
1520 foreach ($this->html_images as $img) {
1521 $fullpath = $images_dir.
'/'.$img[
"name"];
1524 if (!in_array($fullpath, $inline)) {
1526 if ($image = file_get_contents($fullpath)) {
1528 preg_match(
'/([A-Za-z0-9_-]+[\.]?[A-Za-z0-9]+)?$/i', $img[
"name"], $regs);
1529 $imgName = $regs[1];
1531 $this->images_encoded[$i][
'name'] = $imgName;
1532 $this->images_encoded[$i][
'fullpath'] = $fullpath;
1533 $this->images_encoded[$i][
'content_type'] = $img[
"content_type"];
1534 $this->images_encoded[$i][
'cid'] = $img[
"cid"];
1536 $this->images_encoded[$i][
"image_encoded"] = chunk_split(base64_encode($image), 68, $this->eol);
1537 $inline[] = $fullpath;
1567 public static function getValidAddress($address, $format, $encode = 0, $maxnumberofemail = 0)
1573 $arrayaddress = explode(
',', $address);
1577 foreach ($arrayaddress as $val) {
1579 if (preg_match(
'/^(.*)<(.*)>$/i', trim($val), $regs)) {
1580 $name = trim($regs[1]);
1581 $email = trim($regs[2]);
1584 $email = trim($val);
1592 $newemail = $name ? $name : $email;
1593 $newemail =
'<a href="mailto:'.$email.
'">'.$newemail.
'</a>';
1596 $newemail = $name ? $name : $email;
1601 if ($format == 1 || $format == 3) {
1602 $newemail =
'<'.$email.
'>';
1604 if ($format == 0 || $format == 3) {
1605 if (!empty($conf->global->MAIN_MAIL_NO_FULL_EMAIL)) {
1606 $newemail =
'<'.$email.
'>';
1608 $newemail =
'<'.$email.
'>';
1610 $newemail = ($format == 3 ?
'"' :
'').($encode ?self::encodetorfc2822($name) : $name).($format == 3 ?
'"' :
'').
' <'.$email.
'>';
1614 $ret = ($ret ? $ret.
',' :
'').$newemail;
1617 if ($maxnumberofemail && $i >= $maxnumberofemail) {
1618 if (count($arrayaddress) > $maxnumberofemail) {
1642 $arrayaddress = explode(
',', $address);
1645 foreach ($arrayaddress as $val) {
1646 if (preg_match(
'/^(.*)<(.*)>$/i', trim($val), $regs)) {
1647 $name = trim($regs[1]);
1648 $email = trim($regs[2]);
1651 $email = trim($val);
1654 $ret[$email] = empty($conf->global->MAIN_MAIL_NO_FULL_EMAIL) ? $name : null;
checkIfHTML($msg)
Correct an uncomplete html string.
dol_osencode($str)
Return a string encoded into OS filesystem encoding.
dol_hash($chain, $type= '0')
Returns a hash of a string.
write_body($msgtext)
Return email content (mode = 'mail')
findHtmlImages($images_dir)
Seearch images into html message and init array this->images_encoded if found.
Class to construct and send SMTP compliant email, even to a secure SMTP server, regardless of platfor...
write_images($images_list)
Attach an image to email (mode = 'mail')
__construct($subject, $to, $from, $msg, $filename_list=array(), $mimetype_list=array(), $mimefilename_list=array(), $addr_cc="", $addr_bcc="", $deliveryreceipt=0, $msgishtml=0, $errors_to= '', $css= '', $trackid= '', $moreinheader= '', $sendcontext= 'standard', $replyto= '')
CMailFile.
dol_nl2br($stringtoencode, $nl2brmode=0, $forxml=false)
Replace CRLF in string with a HTML BR tag.
write_mimeheaders($filename_list, $mimefilename_list)
Create header MIME (mode = 'mail')
write_files($filename_list, $mimetype_list, $mimefilename_list)
Attach file to email (mode = 'mail')
$bodyCSS
Defined background directly in body tag.
server_parse($socket, $response)
This function has been modified as provided by SirSir to allow multiline responses when using SMTP Ex...
static getValidAddress($address, $format, $encode=0, $maxnumberofemail=0)
Return a formatted address string for SMTP protocol.
Class to send emails (with attachments or not) Usage: $mailfile = new CMailFile($subject,$sendto,$replyto,$message,$filepath,$mimetype,$filename,$cc,$ccc,$deliveryreceipt,$msgishtml,$errors_to,$css,$trackid,$moreinheader,$sendcontext,$replyto); $mailfile->sendfile();.
$styleCSS
Defined css style for body background.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
static getArrayAddress($address)
Return a formatted array of address string for SMTP protocol.
dol_string_unaccent($str)
Clean a string from all accent characters to be used as ref, login or by dol_sanitizeFileName.
utf8_check($str)
Check if a string is in UTF8.
dump_mail()
Write content of a SMTP request into a dump file (mode = all) Used for debugging. ...
check_server_port($host, $port)
Try to create a socket connection.
static encodetorfc2822($stringtoencode)
Encode subject according to RFC 2822 - http://en.wikipedia.org/wiki/MIME#Encoded-Word.
sendfile()
Send mail that was prepared by constructor.
_encode_file($sourcefile)
Read a file on disk and return encoded content for emails (mode = 'mail')
write_smtpheaders()
Create SMTP headers (mode = 'mail')
ascii_check($str)
Check if a string is in ASCII.
buildCSS()
Build a css style (mode = all) into this->styleCSS and this->bodyCSS.
dol_textishtml($msg, $option=0)
Return if a text is a html content.