56 public $mixed_boundary;
57 public $related_boundary;
58 public $alternative_boundary;
59 public $deliveryreceipt;
61 public $atleastonefile;
89 public $filename_list = array();
93 public $mimetype_list = array();
97 public $mimefilename_list = array();
101 public $image_boundary;
102 public $atleastoneimage = 0;
103 public $html_images = array();
104 public $images_encoded = array();
105 public $image_types = array(
106 'gif' =>
'image/gif',
107 'jpg' =>
'image/jpeg',
108 'jpeg' =>
'image/jpeg',
109 'jpe' =>
'image/jpeg',
110 'bmp' =>
'image/bmp',
111 'png' =>
'image/png',
112 'tif' =>
'image/tiff',
113 'tiff' =>
'image/tiff',
138 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 =
'')
140 global $conf, $dolibarr_main_data_root;
143 if (is_array($mimefilename_list)) {
144 foreach ($mimefilename_list as $key => $val) {
150 if (!empty($conf->global->MAIN_MAIL_AUTOCOPY_TO) && !preg_match(
'/'.preg_quote($conf->global->MAIN_MAIL_AUTOCOPY_TO,
'/').
'/i', $to)) {
151 $addr_bcc .= ($addr_bcc ?
', ' :
'').$conf->global->MAIN_MAIL_AUTOCOPY_TO;
154 $this->subject = $subject;
155 $this->addr_to = $to;
156 $this->addr_from = $from;
158 $this->filename_list = $filename_list;
159 $this->mimetype_list = $mimetype_list;
160 $this->mimefilename_list = $mimefilename_list;
161 $this->addr_cc = $addr_cc;
162 $this->addr_bcc = $addr_bcc;
163 $this->deliveryreceipt = $deliveryreceipt;
164 if (empty($replyto)) $replyto = $from;
165 $this->reply_to = $replyto;
166 $this->errors_to = $errors_to;
167 $this->trackid = $trackid;
168 $this->sendcontext = $sendcontext;
169 $this->filename_list = $filename_list;
170 $this->mimetype_list = $mimetype_list;
171 $this->mimefilename_list = $mimefilename_list;
174 $this->sendmode =
'';
175 if (!empty($this->sendcontext)) {
176 $smtpContextKey = strtoupper($this->sendcontext);
177 $keyForSMTPSendMode =
'MAIN_MAIL_SENDMODE_'.$smtpContextKey;
178 $smtpContextSendMode = empty($conf->global->{$keyForSMTPSendMode}) ?
'' : $conf->global->{$keyForSMTPSendMode};
179 if (!empty($smtpContextSendMode) && $smtpContextSendMode !=
'default') {
180 $this->sendmode = $smtpContextSendMode;
183 if (empty($this->sendmode)) $this->sendmode = $conf->global->MAIN_MAIL_SENDMODE;
184 if (empty($this->sendmode)) $this->sendmode =
'mail';
189 $this->eol2 =
"\r\n";
190 if (!empty($conf->global->MAIN_FIX_FOR_BUGGED_MTA))
194 $moreinheader = str_replace(
"\r\n",
"\n", $moreinheader);
198 $this->mixed_boundary =
"multipart_x.".time().
".x_boundary";
201 $this->related_boundary =
'mul_'.dol_hash(uniqid(
"dolibarr2"), 3);
204 $this->alternative_boundary =
'mul_'.dol_hash(uniqid(
"dolibarr3"), 3);
206 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);
207 dol_syslog(
"CMailFile::CMailfile: subject=".$subject.
", deliveryreceipt=".$deliveryreceipt.
", msgishtml=".$msgishtml, LOG_DEBUG);
211 dol_syslog(
"CMailFile::CMailfile: Try to send an email with empty subject");
212 $this->error =
'ErrorSubjectIsRequired';
217 dol_syslog(
"CMailFile::CMailfile: Try to send an email with empty body");
222 if ($msgishtml == -1)
224 $this->msgishtml = 0;
227 $this->msgishtml = $msgishtml;
230 global $dolibarr_main_url_root;
233 $urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim($dolibarr_main_url_root));
234 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
238 $msg = preg_replace(
'/src="'.preg_quote(DOL_URL_ROOT,
'/').
'\/viewimage\.php/ims',
'src="'.$urlwithroot.
'/viewimage.php', $msg, -1);
240 if (!empty($conf->global->MAIN_MAIL_FORCE_CONTENT_TYPE_TO_HTML)) $this->msgishtml = 1;
243 if ($this->msgishtml)
248 if (!empty($conf->global->MAIN_MAIL_ADD_INLINE_IMAGES_IF_IN_MEDIAS))
250 $findimg = $this->findHtmlImages($dolibarr_main_data_root.
'/medias');
256 foreach ($this->html_images as $i => $val)
258 if ($this->html_images[$i])
260 $this->atleastoneimage = 1;
261 dol_syslog(
"CMailFile::CMailfile: html_images[$i]['name']=".$this->html_images[$i][
'name'], LOG_DEBUG);
268 if (is_array($filename_list))
270 foreach ($filename_list as $i => $val)
272 if ($filename_list[$i])
274 $this->atleastonefile = 1;
275 dol_syslog(
"CMailFile::CMailfile: filename_list[$i]=".$filename_list[$i].
", mimetype_list[$i]=".$mimetype_list[$i].
" mimefilename_list[$i]=".$mimefilename_list[$i], LOG_DEBUG);
281 if (!empty($conf->global->MAIN_MAIL_AUTOCOPY_TO) && !preg_match(
'/'.preg_quote($conf->global->MAIN_MAIL_AUTOCOPY_TO,
'/').
'/i', $to)) {
282 $addr_bcc .= ($addr_bcc ?
', ' :
'').$conf->global->MAIN_MAIL_AUTOCOPY_TO;
285 $this->addr_to = $to;
286 $this->addr_cc = $addr_cc;
287 $this->addr_bcc = $addr_bcc;
288 $this->reply_to = $replyto;
289 $this->addr_from = $from;
290 $this->subject = $subject;
291 $this->errors_to = $errors_to;
292 $this->deliveryreceipt = $deliveryreceipt;
293 $this->trackid = $trackid;
295 if (!empty($conf->global->MAIN_MAIL_FORCE_SENDTO))
297 $this->addr_to = $conf->global->MAIN_MAIL_FORCE_SENDTO;
299 $this->addr_bcc =
'';
302 $keyforsslseflsigned =
'MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED';
303 if (!empty($this->sendcontext)) {
304 $smtpContextKey = strtoupper($this->sendcontext);
305 $keyForSMTPSendMode =
'MAIN_MAIL_SENDMODE_'.$smtpContextKey;
306 $smtpContextSendMode = empty($conf->global->{$keyForSMTPSendMode}) ?
'' : $conf->global->{$keyForSMTPSendMode};
307 if (!empty($smtpContextSendMode) && $smtpContextSendMode !=
'default') {
308 $keyforsslseflsigned =
'MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED_'.$smtpContextKey;
314 if ($this->sendmode ==
'mail')
325 $smtp_headers = $this->write_smtpheaders();
326 if (!empty($moreinheader)) $smtp_headers .= $moreinheader;
329 $mime_headers = $this->write_mimeheaders($filename_list, $mimefilename_list);
331 if (!empty($this->html))
343 $text_body = $this->write_body($msg);
346 if (!empty($this->atleastonefile)) {
347 $files_encoded = $this->write_files($filename_list, $mimetype_list, $mimefilename_list);
351 $this->headers = $smtp_headers.$mime_headers;
354 $this->headers = preg_replace(
"/([\r\n]+)$/i",
"", $this->headers);
357 $this->message =
'This is a message with multiple parts in MIME format.'.$this->eol;
358 $this->message .= $text_body.$files_encoded;
359 $this->message .=
"--".$this->mixed_boundary.
"--".$this->eol;
360 } elseif ($this->sendmode ==
'smtps')
365 require_once DOL_DOCUMENT_ROOT.
'/core/class/smtps.class.php';
366 $smtps =
new SMTPs();
367 $smtps->setCharSet($conf->file->character_set_client);
370 $subjecttouse = $this->subject;
372 $subjecttouse = $this->encodetorfc2822($subjecttouse);
375 $smtps->setSubject($subjecttouse);
376 $smtps->setTO($this->getValidAddress($this->addr_to, 0, 1));
377 $smtps->setFrom($this->getValidAddress($this->addr_from, 0, 1));
378 $smtps->setTrackId($this->trackid);
379 $smtps->setReplyTo($this->getValidAddress($this->reply_to, 0, 1));
381 if (!empty($moreinheader)) $smtps->setMoreInHeader($moreinheader);
383 if (!empty($this->html))
391 $msg = $this->checkIfHTML($msg);
395 $msg = preg_replace(
'/(\r|\n)\.(\r|\n)/ims',
'\1..\2', $msg);
397 if ($this->msgishtml) $smtps->setBodyContent($msg,
'html');
398 else $smtps->setBodyContent($msg,
'plain');
400 if ($this->atleastoneimage)
402 foreach ($this->images_encoded as $img)
404 $smtps->setImageInline($img[
'image_encoded'], $img[
'name'], $img[
'content_type'], $img[
'cid']);
408 if (!empty($this->atleastonefile))
410 foreach ($filename_list as $i => $val)
412 $content = file_get_contents($filename_list[$i]);
413 $smtps->setAttachment($content, $mimefilename_list[$i], $mimetype_list[$i]);
417 $smtps->setCC($this->addr_cc);
418 $smtps->setBCC($this->addr_bcc);
419 $smtps->setErrorsTo($this->errors_to);
420 $smtps->setDeliveryReceipt($this->deliveryreceipt);
421 if (!empty($conf->global->$keyforsslseflsigned)) $smtps->setOptions(array(
'ssl' => array(
'verify_peer' =>
false,
'verify_peer_name' =>
false,
'allow_self_signed' =>
true)));
423 $host = dol_getprefix(
'email');
424 $this->msgid = time().
'.SMTPs-dolibarr-'.$this->trackid.
'@'.$host;
426 $this->smtps = $smtps;
427 } elseif ($this->sendmode ==
'swiftmailer') {
429 $host = dol_getprefix(
'email');
431 require_once DOL_DOCUMENT_ROOT.
'/includes/swiftmailer/lexer/lib/Doctrine/Common/Lexer/AbstractLexer.php';
434 require_once DOL_DOCUMENT_ROOT.
'/includes/swiftmailer/autoload.php';
436 require_once DOL_DOCUMENT_ROOT.
'/includes/swiftmailer/lib/swift_required.php';
440 $this->message =
new Swift_Message();
443 $headers = $this->message->getHeaders();
444 $headers->addTextHeader(
'X-Dolibarr-TRACKID', $this->trackid.
'@'.$host);
445 $this->msgid = time().
'.swiftmailer-dolibarr-'.$this->trackid.
'@'.$host;
446 $headerID = $this->msgid;
447 $msgid = $headers->get(
'Message-ID');
448 $msgid->setId($headerID);
449 $headers->addIdHeader(
'References', $headerID);
454 $result = $this->message->setSubject($this->subject);
456 $this->errors[] = $e->getMessage();
461 if (!empty($this->addr_from)) {
463 if (!empty($conf->global->MAIN_FORCE_DISABLE_MAIL_SPOOFING)) {
465 $regexp =
'/([a-z0-9_\.\-\+])+\@(([a-z0-9\-])+\.)+([a-z0-9]{2,4})+/i';
466 $emailMatchs = preg_match_all($regexp, $from, $adressEmailFrom);
467 $adressEmailFrom = reset($adressEmailFrom);
468 if ($emailMatchs !==
false && filter_var($conf->global->MAIN_MAIL_SMTPS_ID, FILTER_VALIDATE_EMAIL) && $conf->global->MAIN_MAIL_SMTPS_ID !== $adressEmailFrom)
470 $result = $this->message->setFrom($conf->global->MAIN_MAIL_SMTPS_ID);
472 $result = $this->message->setFrom($this->getArrayAddress($this->addr_from));
475 $result = $this->message->setFrom($this->getArrayAddress($this->addr_from));
478 $this->errors[] = $e->getMessage();
483 if (!empty($this->addr_to)) {
485 $result = $this->message->setTo($this->getArrayAddress($this->addr_to));
487 $this->errors[] = $e->getMessage();
491 if (!empty($this->reply_to)) {
493 $result = $this->message->SetReplyTo($this->getArrayAddress($this->reply_to));
495 $this->errors[] = $e->getMessage();
500 $result = $this->message->setCharSet($conf->file->character_set_client);
502 $this->errors[] = $e->getMessage();
505 if (!empty($this->html)) {
511 $msg = $this->checkIfHTML($msg);
514 if ($this->atleastoneimage)
516 foreach ($this->images_encoded as $img)
519 $attachment = Swift_Image::fromPath($img[
'fullpath']);
521 $imgcid = $this->message->embed($attachment);
523 $msg = str_replace(
"cid:".$img[
'cid'], $imgcid, $msg);
527 if ($this->msgishtml) {
528 $this->message->setBody($msg,
'text/html');
530 $this->message->addPart(html_entity_decode(strip_tags($msg)),
'text/plain');
532 $this->message->setBody($msg,
'text/plain');
534 $this->message->addPart(
dol_nl2br($msg),
'text/html');
537 if (!empty($this->atleastonefile))
539 foreach ($filename_list as $i => $val)
542 $attachment = Swift_Attachment::fromPath($filename_list[$i], $mimetype_list[$i]);
543 if (!empty($mimefilename_list[$i])) {
544 $attachment->setFilename($mimefilename_list[$i]);
546 $this->message->attach($attachment);
550 if (!empty($this->addr_cc)) $this->message->setCc($this->getArrayAddress($this->addr_cc));
551 if (!empty($this->addr_bcc)) $this->message->setBcc($this->getArrayAddress($this->addr_bcc));
553 if (isset($this->deliveryreceipt) && $this->deliveryreceipt == 1) $this->message->setReadReceiptTo($this->getArrayAddress($this->addr_from));
557 $this->error =
'Bad value for sendmode';
569 global $conf, $db, $langs;
571 $errorlevel = error_reporting();
576 if (empty($conf->global->MAIN_DISABLE_ALL_MAILS))
578 require_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
580 $hookmanager->initHooks(array(
'mail'));
582 $parameters = array(); $action =
'';
583 $reshook = $hookmanager->executeHooks(
'sendMail', $parameters, $this, $action);
586 $this->error =
"Error in hook maildao sendMail ".$reshook;
587 dol_syslog(
"CMailFile::sendfile: mail end error=".$this->error, LOG_ERR);
596 $sendingmode = $this->sendmode;
597 if ($this->context ==
'emailing' && !empty($conf->global->MAILING_NO_USING_PHPMAIL) && $sendingmode ==
'mail')
600 $listofmethods = array();
601 $listofmethods[
'mail'] =
'PHP mail function';
603 $listofmethods[
'smtps'] =
'SMTP/SMTPS socket library';
607 $linktoadminemailbefore =
'<a href="'.DOL_URL_ROOT.
'/admin/mails.php">';
608 $linktoadminemailend =
'</a>';
609 $this->error = $langs->trans(
"MailSendSetupIs", $listofmethods[$sendingmode]);
610 $this->errors[] = $langs->trans(
"MailSendSetupIs", $listofmethods[$sendingmode]);
611 $this->error .=
'<br>'.$langs->trans(
"MailSendSetupIs2", $linktoadminemailbefore, $linktoadminemailend, $langs->transnoentitiesnoconv(
"MAIN_MAIL_SENDMODE"), $listofmethods[
'smtps']);
612 $this->errors[] = $langs->trans(
"MailSendSetupIs2", $linktoadminemailbefore, $linktoadminemailend, $langs->transnoentitiesnoconv(
"MAIN_MAIL_SENDMODE"), $listofmethods[
'smtps']);
613 if (!empty($conf->global->MAILING_SMTP_SETUP_EMAILS_FOR_QUESTIONS))
615 $this->error .=
'<br>'.$langs->trans(
"MailSendSetupIs3", $conf->global->MAILING_SMTP_SETUP_EMAILS_FOR_QUESTIONS);
616 $this->errors[] = $langs->trans(
"MailSendSetupIs3", $conf->global->MAILING_SMTP_SETUP_EMAILS_FOR_QUESTIONS);
622 if (empty($conf->global->MAIL_MAX_NB_OF_RECIPIENTS_TO_IN_SAME_EMAIL)) $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_TO_IN_SAME_EMAIL = 10;
623 $tmparray1 = explode(
',', $this->addr_to);
624 if (count($tmparray1) > $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_TO_IN_SAME_EMAIL)
626 $this->error =
'Too much recipients in to:';
627 dol_syslog(
"CMailFile::sendfile: mail end error=".$this->error, LOG_WARNING);
630 if (empty($conf->global->MAIL_MAX_NB_OF_RECIPIENTS_CC_IN_SAME_EMAIL)) $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_CC_IN_SAME_EMAIL = 10;
631 $tmparray2 = explode(
',', $this->addr_cc);
632 if (count($tmparray2) > $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_CC_IN_SAME_EMAIL)
634 $this->error =
'Too much recipients in cc:';
635 dol_syslog(
"CMailFile::sendfile: mail end error=".$this->error, LOG_WARNING);
638 if (empty($conf->global->MAIL_MAX_NB_OF_RECIPIENTS_BCC_IN_SAME_EMAIL)) $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_BCC_IN_SAME_EMAIL = 10;
639 $tmparray3 = explode(
',', $this->addr_bcc);
640 if (count($tmparray3) > $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_BCC_IN_SAME_EMAIL)
642 $this->error =
'Too much recipients in bcc:';
643 dol_syslog(
"CMailFile::sendfile: mail end error=".$this->error, LOG_WARNING);
646 if (empty($conf->global->MAIL_MAX_NB_OF_RECIPIENTS_IN_SAME_EMAIL)) $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_IN_SAME_EMAIL = 10;
647 if ((count($tmparray1) + count($tmparray2) + count($tmparray3)) > $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_IN_SAME_EMAIL)
649 $this->error =
'Too much recipients in to:, cc:, bcc:';
650 dol_syslog(
"CMailFile::sendfile: mail end error=".$this->error, LOG_WARNING);
654 $keyforsmtpserver =
'MAIN_MAIL_SMTP_SERVER';
655 $keyforsmtpport =
'MAIN_MAIL_SMTP_PORT';
656 $keyforsmtpid =
'MAIN_MAIL_SMTPS_ID';
657 $keyforsmtppw =
'MAIN_MAIL_SMTPS_PW';
658 $keyfortls =
'MAIN_MAIL_EMAIL_TLS';
659 $keyforstarttls =
'MAIN_MAIL_EMAIL_STARTTLS';
660 $keyforsslseflsigned =
'MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED';
661 if (!empty($this->sendcontext)) {
662 $smtpContextKey = strtoupper($this->sendcontext);
663 $keyForSMTPSendMode =
'MAIN_MAIL_SENDMODE_'.$smtpContextKey;
664 $smtpContextSendMode = empty($conf->global->{$keyForSMTPSendMode}) ?
'' : $conf->global->{$keyForSMTPSendMode};
665 if (!empty($smtpContextSendMode) && $smtpContextSendMode !=
'default') {
666 $keyforsmtpserver =
'MAIN_MAIL_SMTP_SERVER_'.$smtpContextKey;
667 $keyforsmtpport =
'MAIN_MAIL_SMTP_PORT_'.$smtpContextKey;
668 $keyforsmtpid =
'MAIN_MAIL_SMTPS_ID_'.$smtpContextKey;
669 $keyforsmtppw =
'MAIN_MAIL_SMTPS_PW_'.$smtpContextKey;
670 $keyfortls =
'MAIN_MAIL_EMAIL_TLS_'.$smtpContextKey;
671 $keyforstarttls =
'MAIN_MAIL_EMAIL_STARTTLS_'.$smtpContextKey;
672 $keyforsslseflsigned =
'MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED_'.$smtpContextKey;
677 if ($this->sendmode ==
'mail')
681 dol_syslog(
"CMailFile::sendfile addr_to=".$this->addr_to.
", subject=".$this->subject, LOG_DEBUG);
682 dol_syslog(
"CMailFile::sendfile header=\n".$this->headers, LOG_DEBUG);
688 if (empty($this->addr_from)) $this->addr_from =
'robot@example.com';
689 @ini_set(
'sendmail_from', $this->getValidAddress($this->addr_from, 2));
694 if (!empty($conf->global->$keyforsmtpserver)) ini_set(
'SMTP', $conf->global->$keyforsmtpserver);
695 if (!empty($conf->global->$keyforsmtpport)) ini_set(
'smtp_port', $conf->global->$keyforsmtpport);
698 if ($res && !$this->subject)
700 $this->error =
"Failed to send mail with php mail to HOST=".ini_get(
'SMTP').
", PORT=".ini_get(
'smtp_port').
"<br>Subject is empty";
701 dol_syslog(
"CMailFile::sendfile: mail end error=".$this->error, LOG_ERR);
704 $dest = $this->getValidAddress($this->addr_to, 2);
707 $this->error =
"Failed to send mail with php mail to HOST=".ini_get(
'SMTP').
", PORT=".ini_get(
'smtp_port').
"<br>Recipient address '$dest' invalid";
708 dol_syslog(
"CMailFile::sendfile: mail end error=".$this->error, LOG_ERR);
714 $additionnalparam =
'';
715 if (!empty($conf->global->MAIN_MAIL_ALLOW_SENDMAIL_F))
721 $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) :
''));
723 if (!empty($conf->global->MAIN_MAIL_SENDMAIL_FORCE_BA))
725 $additionnalparam .= ($additionnalparam ?
' ' :
'').
'-ba';
728 if (!empty($conf->global->MAIN_MAIL_SENDMAIL_FORCE_ADDPARAM)) $additionnalparam .= ($additionnalparam ?
' ' :
'').
'-U '.$additionnalparam;
731 if (preg_match(
'/^win/i', PHP_OS)) $linuxlike = 0;
732 if (preg_match(
'/^mac/i', PHP_OS)) $linuxlike = 0;
734 dol_syslog(
"CMailFile::sendfile: mail start".($linuxlike ?
'' :
" HOST=".ini_get(
'SMTP').
", PORT=".ini_get(
'smtp_port')).
", additionnal_parameters=".$additionnalparam, LOG_DEBUG);
736 $this->message = stripslashes($this->message);
738 if (!empty($conf->global->MAIN_MAIL_DEBUG)) $this->dump_mail();
741 $subjecttouse = $this->subject;
743 $subjecttouse = $this->encodetorfc2822($subjecttouse);
746 if (!empty($additionnalparam)) $res = mail($dest, $subjecttouse, $this->message, $this->headers, $additionnalparam);
747 else $res = mail($dest, $subjecttouse, $this->message, $this->headers);
751 $langs->load(
"errors");
752 $this->error =
"Failed to send mail with php mail";
754 $this->error .=
" to HOST=".ini_get(
'SMTP').
", PORT=".ini_get(
'smtp_port');
756 $this->error .=
".<br>";
757 $this->error .= $langs->trans(
"ErrorPhpMailDelivery");
758 dol_syslog(
"CMailFile::sendfile: mail end error=".$this->error, LOG_ERR);
760 dol_syslog(
"CMailFile::sendfile: mail end success", LOG_DEBUG);
766 @ini_restore(
'sendmail_from');
770 if (!empty($conf->global->$keyforsmtpserver)) ini_restore(
'SMTP');
771 if (!empty($conf->global->$keyforsmtpport)) ini_restore(
'smtp_port');
772 } elseif ($this->sendmode ==
'smtps')
774 if (!is_object($this->smtps))
776 $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.";
777 dol_syslog(
"CMailFile::sendfile: mail end error=".$this->error, LOG_ERR);
783 $this->smtps->setTransportType(0);
786 if (empty($conf->global->$keyforsmtpserver)) $conf->global->$keyforsmtpserver = ini_get(
'SMTP');
787 if (empty($conf->global->$keyforsmtpport)) $conf->global->$keyforsmtpport = ini_get(
'smtp_port');
790 $server = $conf->global->$keyforsmtpserver;
792 if (!empty($conf->global->$keyfortls) && function_exists(
'openssl_open')) $secure =
'ssl';
793 if (!empty($conf->global->$keyforstarttls) && function_exists(
'openssl_open')) $secure =
'tls';
794 $server = ($secure ? $secure.
'://' :
'').$server;
796 $port = $conf->global->$keyforsmtpport;
798 $this->smtps->setHost($server);
799 $this->smtps->setPort($port);
801 $loginid =
''; $loginpass =
'';
802 if (!empty($conf->global->$keyforsmtpid))
804 $loginid = $conf->global->$keyforsmtpid;
805 $this->smtps->setID($loginid);
807 if (!empty($conf->global->$keyforsmtppw))
809 $loginpass = $conf->global->$keyforsmtppw;
810 $this->smtps->setPW($loginpass);
814 $from = $this->smtps->getFrom(
'org');
817 $this->error =
"Failed to send mail with smtps lib to HOST=".$server.
", PORT=".$conf->global->$keyforsmtpport.
" - Sender address '$from' invalid";
818 dol_syslog(
"CMailFile::sendfile: mail end error=".$this->error, LOG_ERR);
821 $dest = $this->smtps->getTo();
824 $this->error =
"Failed to send mail with smtps lib to HOST=".$server.
", PORT=".$conf->global->$keyforsmtpport.
" - Recipient address '$dest' invalid";
825 dol_syslog(
"CMailFile::sendfile: mail end error=".$this->error, LOG_ERR);
831 if (!empty($conf->global->MAIN_MAIL_DEBUG)) $this->smtps->setDebug(
true);
833 $result = $this->smtps->sendMsg();
836 if (!empty($conf->global->MAIN_MAIL_DEBUG)) $this->dump_mail();
838 $result = $this->smtps->getErrors();
839 if (empty($this->error) && empty($result))
841 dol_syslog(
"CMailFile::sendfile: mail end success", LOG_DEBUG);
844 if (empty($this->error)) $this->error = $result;
845 dol_syslog(
"CMailFile::sendfile: mail end error with smtps lib to HOST=".$server.
", PORT=".$conf->global->$keyforsmtpport.
" - ".$this->error, LOG_ERR);
849 } elseif ($this->sendmode ==
'swiftmailer')
853 require_once DOL_DOCUMENT_ROOT.
'/includes/swiftmailer/lib/swift_required.php';
856 if (empty($conf->global->$keyforsmtpserver)) $conf->global->$keyforsmtpserver = ini_get(
'SMTP');
857 if (empty($conf->global->$keyforsmtpport)) $conf->global->$keyforsmtpport = ini_get(
'smtp_port');
860 $server = $conf->global->$keyforsmtpserver;
862 if (!empty($conf->global->$keyfortls) && function_exists(
'openssl_open')) $secure =
'ssl';
863 if (!empty($conf->global->$keyforstarttls) && function_exists(
'openssl_open')) $secure =
'tls';
865 $this->transport =
new Swift_SmtpTransport($server, $conf->global->$keyforsmtpport, $secure);
867 if (!empty($conf->global->$keyforsmtpid)) $this->transport->setUsername($conf->global->$keyforsmtpid);
868 if (!empty($conf->global->$keyforsmtppw)) $this->transport->setPassword($conf->global->$keyforsmtppw);
869 if (!empty($conf->global->$keyforsslseflsigned)) $this->transport->setStreamOptions(array(
'ssl' => array(
'allow_self_signed' =>
true,
'verify_peer' =>
false)));
873 $contentEncoderBase64 =
new Swift_Mime_ContentEncoder_Base64ContentEncoder();
874 $this->message->setEncoder($contentEncoderBase64);
877 $this->mailer =
new Swift_Mailer($this->transport);
880 if ($conf->global->MAIN_MAIL_EMAIL_DKIM_ENABLED) {
881 $privateKey = $conf->global->MAIN_MAIL_EMAIL_DKIM_PRIVATE_KEY;
882 $domainName = $conf->global->MAIN_MAIL_EMAIL_DKIM_DOMAIN;
883 $selector = $conf->global->MAIN_MAIL_EMAIL_DKIM_SELECTOR;
884 $signer =
new Swift_Signers_DKIMSigner($privateKey, $domainName, $selector);
885 $this->message->attachSigner($signer->ignoreHeader(
'Return-Path'));
888 if (!empty($conf->global->MAIN_MAIL_DEBUG)) {
890 $this->logger =
new Swift_Plugins_Loggers_ArrayLogger();
893 $this->mailer->registerPlugin(
new Swift_Plugins_LoggerPlugin($this->logger));
897 $result = $this->mailer->send($this->message);
899 $this->error = $e->getMessage();
901 if (!empty($conf->global->MAIN_MAIL_DEBUG)) $this->dump_mail();
904 if (!empty($this->error) || !$result) {
905 dol_syslog(
"CMailFile::sendfile: mail end error=".$this->error, LOG_ERR);
908 dol_syslog(
"CMailFile::sendfile: mail end success", LOG_DEBUG);
914 return 'Bad value for sendmode';
917 $parameters = array(); $action =
'';
918 $reshook = $hookmanager->executeHooks(
'sendMailAfter', $parameters, $this, $action);
921 $this->error =
"Error in hook maildao sendMailAfter ".$reshook;
922 dol_syslog(
"CMailFile::sendfile: mail end error=".$this->error, LOG_ERR);
927 $this->error =
'No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS';
928 dol_syslog(
"CMailFile::sendfile: ".$this->error, LOG_WARNING);
931 error_reporting($errorlevel);
945 return '=?'.$conf->file->character_set_client.
'?B?'.base64_encode($stringtoencode).
'?=';
960 if (is_readable($newsourcefile))
962 $contents = file_get_contents($newsourcefile);
963 $encoded = chunk_split(base64_encode($contents), 76, $this->eol);
966 $this->error =
"Error: Can't read file '".$sourcefile.
"' into _encode_file";
967 dol_syslog(
"CMailFile::encode_file: ".$this->error, LOG_ERR);
984 global $conf, $dolibarr_main_data_root;
986 if (@is_writeable($dolibarr_main_data_root))
988 $outputfile = $dolibarr_main_data_root.
"/dolibarr_mail.log";
989 $fp = fopen($outputfile,
"w");
991 if ($this->sendmode ==
'mail')
993 fputs($fp, $this->headers);
994 fputs($fp, $this->eol);
995 fputs($fp, $this->message);
996 } elseif ($this->sendmode ==
'smtps')
998 fputs($fp, $this->smtps->log);
999 } elseif ($this->sendmode ==
'swiftmailer')
1001 fputs($fp, $this->logger->dump());
1005 if (!empty($conf->global->MAIN_UMASK))
1006 @chmod($outputfile, octdec($conf->global->MAIN_UMASK));
1019 if (!preg_match(
'/^[\s\t]*<html/i', $msg))
1021 $out =
"<html><head><title></title>";
1022 if (!empty($this->styleCSS)) $out .= $this->styleCSS;
1023 $out .=
"</head><body";
1024 if (!empty($this->bodyCSS)) $out .= $this->bodyCSS;
1027 $out .=
"</body></html>";
1042 if (!empty($this->css))
1045 $this->styleCSS =
'<style type="text/css">';
1046 $this->styleCSS .=
'body {';
1048 if ($this->css[
'bgcolor'])
1050 $this->styleCSS .=
' background-color: '.$this->css[
'bgcolor'].
';';
1051 $this->bodyCSS .=
' bgcolor="'.$this->css[
'bgcolor'].
'"';
1053 if ($this->css[
'bgimage'])
1056 $this->styleCSS .=
' background-image: url("cid:'.$this->css[
'bgimage_cid'].
'");';
1058 $this->styleCSS .=
'}';
1059 $this->styleCSS .=
'</style>';
1076 $host = dol_getprefix(
'email');
1080 $out .=
"From: ".$this->getValidAddress($this->addr_from, 3, 1).$this->eol2;
1081 if (!empty($conf->global->MAIN_MAIL_SENDMAIL_FORCE_BA))
1083 $out .=
"To: ".$this->getValidAddress($this->addr_to, 0, 1).$this->eol2;
1086 $out .=
"Return-Path: ".$this->getValidAddress($this->addr_from, 0, 1).$this->eol2;
1087 if (isset($this->reply_to) && $this->reply_to) $out .=
"Reply-To: ".$this->getValidAddress($this->reply_to, 2).$this->eol2;
1088 if (isset($this->errors_to) && $this->errors_to) $out .=
"Errors-To: ".$this->getValidAddress($this->errors_to, 2).$this->eol2;
1091 if (isset($this->addr_cc) && $this->addr_cc) $out .=
"Cc: ".$this->getValidAddress($this->addr_cc, 2).$this->eol2;
1092 if (isset($this->addr_bcc) && $this->addr_bcc) $out .=
"Bcc: ".$this->getValidAddress($this->addr_bcc, 2).$this->eol2;
1095 if (isset($this->deliveryreceipt) && $this->deliveryreceipt == 1) $out .=
"Disposition-Notification-To: ".$this->getValidAddress($this->addr_from, 2).$this->eol2;
1099 $out .=
'Date: '.date(
"r").$this->eol2;
1101 $trackid = $this->trackid;
1105 $this->msgid = time().
'.phpmail-dolibarr-'.$trackid.
'@'.$host;
1106 $out .=
'Message-ID: <'.$this->msgid.
">".$this->eol2;
1107 $out .=
'References: <'.$this->msgid.
">".$this->eol2;
1108 $out .=
'X-Dolibarr-TRACKID: '.$trackid.
'@'.$host.$this->eol2;
1110 $this->msgid = time().
'.phpmail@'.$host;
1111 $out .=
'Message-ID: <'.$this->msgid.
">".$this->eol2;
1114 if (!empty(
$_SERVER[
'REMOTE_ADDR'])) $out .=
"X-RemoteAddr: ".$_SERVER[
'REMOTE_ADDR'].$this->eol2;
1115 $out .=
"X-Mailer: Dolibarr version ".DOL_VERSION.
" (using php mail)".$this->eol2;
1116 $out .=
"Mime-Version: 1.0".$this->eol2;
1120 $out .=
"Content-Type: multipart/mixed;".$this->eol2.
" boundary=\"".$this->mixed_boundary.
"\"".$this->eol2;
1121 $out .=
"Content-Transfer-Encoding: 8bit".$this->eol2;
1123 dol_syslog(
"CMailFile::write_smtpheaders smtp_header=\n".$out);
1142 if (is_array($filename_list))
1144 $filename_list_size = count($filename_list);
1145 for ($i = 0; $i < $filename_list_size; $i++)
1147 if ($filename_list[$i])
1149 if ($mimefilename_list[$i]) $filename_list[$i] = $mimefilename_list[$i];
1150 $out .=
"X-attachments: $filename_list[$i]".$this->eol2;
1155 dol_syslog(
"CMailFile::write_mimeheaders mime_header=\n".$out, LOG_DEBUG);
1173 $out .=
"--".$this->mixed_boundary.$this->eol;
1175 if ($this->atleastoneimage)
1177 $out .=
"Content-Type: multipart/alternative;".$this->eol.
" boundary=\"".$this->alternative_boundary.
"\"".$this->eol;
1179 $out .=
"--".$this->alternative_boundary.$this->eol;
1183 $strContent = preg_replace(
"/(?<!\r)\n/si",
"\r\n", $msgtext);
1184 if (!empty($conf->global->MAIN_FIX_FOR_BUGGED_MTA))
1186 $strContent = preg_replace(
"/\r\n/si",
"\n", $strContent);
1189 $strContentAltText =
'';
1190 if ($this->msgishtml)
1193 $strContentAltText = preg_replace(
"/<br\s*[^>]*>/",
" ", $strContent);
1194 $strContentAltText = html_entity_decode(strip_tags($strContentAltText));
1195 $strContentAltText = trim(wordwrap($strContentAltText, 75, empty($conf->global->MAIN_FIX_FOR_BUGGED_MTA) ?
"\r\n" :
"\n"));
1198 $strContent = $this->checkIfHTML($strContent);
1204 $strContent = rtrim(wordwrap($strContent, 75, empty($conf->global->MAIN_FIX_FOR_BUGGED_MTA) ?
"\r\n" :
"\n"));
1206 if ($this->msgishtml)
1208 if ($this->atleastoneimage)
1210 $out .=
"Content-Type: text/plain; charset=".$conf->file->character_set_client.$this->eol;
1212 $out .= $this->eol.($strContentAltText ? $strContentAltText : strip_tags($strContent)).$this->eol;
1213 $out .=
"--".$this->alternative_boundary.$this->eol;
1214 $out .=
"Content-Type: multipart/related;".$this->eol.
" boundary=\"".$this->related_boundary.
"\"".$this->eol;
1216 $out .=
"--".$this->related_boundary.$this->eol;
1219 if (!$this->atleastoneimage && $strContentAltText && !empty($conf->global->MAIN_MAIL_USE_MULTI_PART))
1221 $out .=
"Content-Type: multipart/alternative;".$this->eol.
" boundary=\"".$this->alternative_boundary.
"\"".$this->eol;
1223 $out .=
"--".$this->alternative_boundary.$this->eol;
1224 $out .=
"Content-Type: text/plain; charset=".$conf->file->character_set_client.$this->eol;
1226 $out .= $this->eol.$strContentAltText.$this->eol;
1227 $out .=
"--".$this->alternative_boundary.$this->eol;
1230 $out .=
"Content-Type: text/html; charset=".$conf->file->character_set_client.$this->eol;
1232 $out .= $this->eol.$strContent.$this->eol;
1234 if (!$this->atleastoneimage && $strContentAltText && !empty($conf->global->MAIN_MAIL_USE_MULTI_PART))
1236 $out .=
"--".$this->alternative_boundary.
"--".$this->eol;
1239 $out .=
"Content-Type: text/plain; charset=".$conf->file->character_set_client.$this->eol;
1241 $out .= $this->eol.$strContent.$this->eol;
1247 if ($this->atleastoneimage)
1249 $out .= $this->write_images($this->images_encoded);
1251 $out .=
"--".$this->related_boundary.
"--".$this->eol;
1252 $out .= $this->eol.
"--".$this->alternative_boundary.
"--".$this->eol;
1268 public function write_files($filename_list, $mimetype_list, $mimefilename_list)
1273 $filename_list_size = count($filename_list);
1274 for ($i = 0; $i < $filename_list_size; $i++)
1276 if ($filename_list[$i])
1279 $encoded = $this->_encode_file($filename_list[$i]);
1282 if ($mimefilename_list[$i]) $filename_list[$i] = $mimefilename_list[$i];
1283 if (!$mimetype_list[$i]) {
1284 $mimetype_list[$i] =
"application/octet-stream";
1287 $out .=
"--".$this->mixed_boundary.$this->eol;
1288 $out .=
"Content-Disposition: attachment; filename=\"".$filename_list[$i].
"\"".$this->eol;
1289 $out .=
"Content-Type: ".$mimetype_list[$i].
"; name=\"".$filename_list[$i].
"\"".$this->eol;
1290 $out .=
"Content-Transfer-Encoding: base64".$this->eol;
1291 $out .=
"Content-Description: ".$filename_list[$i].$this->eol;
1318 if (is_array($images_list))
1320 foreach ($images_list as $img)
1322 dol_syslog(
"CMailFile::write_images: ".$img[
"name"]);
1324 $out .=
"--".$this->related_boundary.$this->eol;
1325 $out .=
"Content-Type: ".$img[
"content_type"].
"; name=\"".$img[
"name"].
"\"".$this->eol;
1326 $out .=
"Content-Transfer-Encoding: base64".$this->eol;
1327 $out .=
"Content-Disposition: inline; filename=\"".$img[
"name"].
"\"".$this->eol;
1328 $out .=
"Content-ID: <".$img[
"cid"].
">".$this->eol;
1330 $out .= $img[
"image_encoded"];
1355 if (function_exists(
'fsockopen'))
1357 $keyforsmtpserver =
'MAIN_MAIL_SMTP_SERVER';
1358 $keyforsmtpport =
'MAIN_MAIL_SMTP_PORT';
1359 $keyforsmtpid =
'MAIN_MAIL_SMTPS_ID';
1360 $keyforsmtppw =
'MAIN_MAIL_SMTPS_PW';
1361 $keyfortls =
'MAIN_MAIL_EMAIL_TLS';
1362 $keyforstarttls =
'MAIN_MAIL_EMAIL_STARTTLS';
1363 if ($this->sendcontext ==
'emailing' && !empty($conf->global->MAIN_MAIL_SENDMODE_EMAILING) && $conf->global->MAIN_MAIL_SENDMODE_EMAILING !=
'default')
1365 $keyforsmtpserver =
'MAIN_MAIL_SMTP_SERVER_EMAILING';
1366 $keyforsmtpport =
'MAIN_MAIL_SMTP_PORT_EMAILING';
1367 $keyforsmtpid =
'MAIN_MAIL_SMTPS_ID_EMAILING';
1368 $keyforsmtppw =
'MAIN_MAIL_SMTPS_PW_EMAILING';
1369 $keyfortls =
'MAIN_MAIL_EMAIL_TLS_EMAILING';
1370 $keyforstarttls =
'MAIN_MAIL_EMAIL_STARTTLS_EMAILING';
1374 if (!empty($conf->global->$keyfortls) && function_exists(
'openssl_open')) $host =
'ssl://'.$host;
1378 dol_syslog(
"Try socket connection to host=".$host.
" port=".$port);
1380 if ($socket = @fsockopen(
1388 if (function_exists(
'stream_set_timeout')) stream_set_timeout($socket, $timeout, 0);
1393 if ($_retVal = $this->server_parse($socket,
"220")) $_retVal = $socket;
1395 $this->error =
utf8_check(
'Error '.$errno.
' - '.$errstr) ?
'Error '.$errno.
' - '.$errstr : utf8_encode(
'Error '.$errno.
' - '.$errstr);
1414 $server_response =
'';
1416 while (substr($server_response, 3, 1) !=
' ')
1418 if (!($server_response = fgets($socket, 256)))
1420 $this->error =
"Couldn't get mail server response codes";
1425 if (!(substr($server_response, 0, 3) == $response))
1427 $this->error =
"Ran into problems sending Mail.\r\nResponse: $server_response";
1443 $extensions = array_keys($this->image_types);
1446 preg_match_all(
'/(?:"|\')([^"\']+\.('.implode(
'|', $extensions).
'))(?:"|\')/Ui', $this->html, $matches);
1448 if (!empty($matches))
1451 foreach ($matches[1] as $full)
1453 if (preg_match(
'/file=([A-Za-z0-9_\-\/]+[\.]?[A-Za-z0-9]+)?$/i', $full, $regs))
1457 if (file_exists($images_dir.
'/'.$img))
1460 $src = preg_quote($full,
'/');
1463 $this->html_images[$i][
"fullpath"] = $images_dir.
'/'.$img;
1466 $this->html_images[$i][
"name"] = $img;
1469 if (preg_match(
'/^.+\.(\w{3,4})$/', $img, $reg))
1471 $ext = strtolower($reg[1]);
1472 $this->html_images[$i][
"content_type"] = $this->image_types[$ext];
1476 $this->html_images[$i][
"cid"] =
dol_hash(uniqid(time()), 3);
1477 $this->html = preg_replace(
"/src=\"$src\"|src='$src'/i",
"src=\"cid:".$this->html_images[$i][
"cid"].
"\"", $this->html);
1483 if (!empty($this->html_images))
1489 foreach ($this->html_images as $img)
1491 $fullpath = $images_dir.
'/'.$img[
"name"];
1494 if (!in_array($fullpath, $inline))
1497 if ($image = file_get_contents($fullpath))
1500 preg_match(
'/([A-Za-z0-9_-]+[\.]?[A-Za-z0-9]+)?$/i', $img[
"name"], $regs);
1501 $imgName = $regs[1];
1503 $this->images_encoded[$i][
'name'] = $imgName;
1504 $this->images_encoded[$i][
'fullpath'] = $fullpath;
1505 $this->images_encoded[$i][
'content_type'] = $img[
"content_type"];
1506 $this->images_encoded[$i][
'cid'] = $img[
"cid"];
1508 $this->images_encoded[$i][
"image_encoded"] = chunk_split(base64_encode($image), 68, $this->eol);
1509 $inline[] = $fullpath;
1539 public static function getValidAddress($address, $format, $encode = 0, $maxnumberofemail = 0)
1545 $arrayaddress = explode(
',', $address);
1549 foreach ($arrayaddress as $val)
1552 if (preg_match(
'/^(.*)<(.*)>$/i', trim($val), $regs))
1554 $name = trim($regs[1]);
1555 $email = trim($regs[2]);
1558 $email = trim($val);
1567 $newemail = $name ? $name : $email;
1568 $newemail =
'<a href="mailto:'.$email.
'">'.$newemail.
'</a>';
1572 $newemail = $name ? $name : $email;
1578 if ($format == 1 || $format == 3)
1580 $newemail =
'<'.$email.
'>';
1582 if ($format == 0 || $format == 3)
1584 if (!empty($conf->global->MAIN_MAIL_NO_FULL_EMAIL)) $newemail =
'<'.$email.
'>';
1585 elseif (!$name) $newemail =
'<'.$email.
'>';
1586 else $newemail = ($format == 3 ?
'"' :
'').($encode ?self::encodetorfc2822($name) : $name).($format == 3 ?
'"' :
'').
' <'.$email.
'>';
1589 $ret = ($ret ? $ret.
',' :
'').$newemail;
1592 if ($maxnumberofemail && $i >= $maxnumberofemail)
1594 if (count($arrayaddress) > $maxnumberofemail) $ret .=
'...';
1616 $arrayaddress = explode(
',', $address);
1619 foreach ($arrayaddress as $val)
1621 if (preg_match(
'/^(.*)<(.*)>$/i', trim($val), $regs))
1623 $name = trim($regs[1]);
1624 $email = trim($regs[2]);
1627 $email = trim($val);
1630 $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.
getArrayAddress($address)
Return a formatted array of address string for SMTP protocol.
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.
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. ...
print $_SERVER["PHP_SELF"]
Edit parameters.
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.