53 private $_smtpsHost =
'localhost';
61 private $_smtpsPort = 25;
67 private $_smtpsID =
null;
73 private $_smtpsPW =
null;
78 private $_smtpsToken =
null;
83 private $_msgId =
null;
88 private $_smtpsAuthType =
'';
94 private $_msgFrom =
null;
100 private $_msgReplyTo =
null;
105 private $_msgInReplyTo =
null;
110 private $_msgReferences =
null;
117 private $_msgRecipients =
null;
122 private $_msgSubject =
null;
129 private $_msgContent = array();
134 private $_msgXheader = array();
141 private $_smtpsCharSet =
'iso-8859-1';
148 private $_msgSensitivity = 0;
153 private $_arySensitivity = array(
false,
156 'Company Confidential');
162 private $_msgPriority = 3;
167 private $_aryPriority = array(
'Bulk',
178 private $_smtpsTransEncodeType = 0;
183 private $_smtpsTransEncodeTypes = array(
'7bit',
196 private $_smtpsTransEncode =
'7bit';
201 private $_smtpsBoundary =
null;
206 private $_smtpsRelatedBoundary =
null;
211 private $_smtpsAlternativeBoundary =
null;
221 private $_transportType = 0;
227 private $_mailPath =
'/usr/lib/sendmail';
232 private $_smtpTimeout = 10;
237 private $_smtpMD5 =
false;
242 private $_smtpsErrors = array();
251 private $_log_level = 0;
256 private $_debug =
false;
267 public $lastretval =
'';
287 private $_errorsTo = array();
291 private $_deliveryReceipt = 0;
295 private $_trackId =
'';
299 private $_moreinheader =
'';
304 private $_options = array();
315 $this->_msgId = $_msgId;
326 $this->_options = $_options;
337 $this->_deliveryReceipt = $_val;
347 return $this->_deliveryReceipt;
358 $this->_smtpTimeout = $timeout;
368 return $this->_smtpTimeout;
379 $this->_trackId = $_val;
390 $this->_moreinheader = $_val;
400 return $this->_trackId;
410 return $this->_moreinheader;
436 if ($_part ===
true || !array_key_exists($_part, $this->_errorsTo)) {
437 $_retValue = $this->_errorsTo;
439 $_retValue = $this->_errorsTo[$_part];
453 $this->_debug = $_vDebug;
464 $_aryToList = $this->
getTo();
483 $usetls = preg_match(
'@tls://@i', $host);
485 $host = preg_replace(
'@tcp://@i',
'', $host);
486 $host = preg_replace(
'@ssl://@i',
'', $host);
487 $host = preg_replace(
'@tls://@i',
'', $host);
490 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
492 if ((!
is_ip($host)) && ((gethostbyname($host)) == $host)) {
493 $this->
_setErr(99, $host.
' is either offline or is an invalid host name.');
496 if (function_exists(
'stream_socket_client') && !empty($this->_options)) {
497 $socket_context = stream_context_create($this->_options);
498 $this->socket = @stream_socket_client(
499 preg_replace(
'@tls://@i',
'', $this->
getHost()).
504 STREAM_CLIENT_CONNECT,
508 $this->socket = @fsockopen(
509 preg_replace(
'@tls://@i',
'', $this->
getHost()),
518 if (is_resource($this->socket)) {
523 if (function_exists(
'stream_set_timeout')) {
524 stream_set_timeout($this->socket, $this->_smtpTimeout, 0);
528 if ($_retVal = $this->
server_parse($this->socket,
"220")) {
529 $_retVal = $this->socket;
534 if (empty($this->errstr)) {
535 $this->errstr =
'Failed to connect with stream_context_create or fsockopen host='.$this->getHost().
' port='.$this->
getPort();
537 $this->
_setErr($this->errno, $this->errstr);
554 require_once DOL_DOCUMENT_ROOT.
'/core/lib/geturl.lib.php';
559 $usetls = preg_match(
'@tls://@i', $host);
561 $host = preg_replace(
'@tcp://@i',
'', $host);
562 $host = preg_replace(
'@ssl://@i',
'', $host);
563 $host = preg_replace(
'@tls://@i',
'', $host);
566 $host =
'tls://'.$host;
578 $hosth = (string) $this->
getFrom(
'addr');
579 $hosth = preg_replace(
'/^.*</',
'', $hosth);
580 $hosth = preg_replace(
'/>.*$/',
'', $hosth);
581 $hosth = preg_replace(
'/.*@/',
'', $hosth);
644 $this->
_setErr(131,
'STARTTLS connection is not supported.');
655 $crypto_method = STREAM_CRYPTO_METHOD_TLS_CLIENT;
656 if (defined(
'STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT')) {
657 $crypto_method |= STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT;
658 $crypto_method |= STREAM_CRYPTO_METHOD_TLSv1_1_CLIENT;
661 if (!stream_socket_enable_crypto($this->socket,
true, $crypto_method)) {
662 $this->
_setErr(132,
'STARTTLS connection failed.');
668 $this->
_setErr(126,
'"'.$hosth.
'" does not support authenticated connections or temporary error. Error after 2nd sending EHLO '.$hosth.
' : '.$this->lastretval);
675 $authtype = $this->_smtpsAuthType ? $this->_smtpsAuthType :
getDolGlobalString(
'MAIN_MAIL_SMTPS_AUTH_TYPE',
'LOGIN');
688 $this->
_setErr(130,
'Error when asking for AUTH PLAIN');
691 $_retVal = $this->
socket_send_str(base64_encode(
"\0".$this->_smtpsID.
"\0".$this->_smtpsPW),
'235');
696 $user = $this->_smtpsID;
697 $token = $this->_smtpsToken;
698 $initRes =
"user=".$user.
"\001auth=Bearer ".$token.
"\001\001";
699 $_retVal = $this->
socket_send_str(
'AUTH XOAUTH2 '.base64_encode($initRes),
'235');
701 $this->
_setErr(130,
'Error when asking for AUTH XOAUTH2');
708 $this->
_setErr(130,
'Error when asking for AUTH LOGIN');
711 $this->
socket_send_str(base64_encode((
string) $this->_smtpsID),
'334');
714 $_retVal = $this->
socket_send_str(base64_encode((
string) $this->_smtpsPW),
'235');
719 $this->
_setErr(130,
'Invalid Authentication Credentials.');
722 $this->
_setErr(126,
'"'.$host.
'" refused the EHLO command. Error after sending EHLO '.$hosth.
' : '.$this->lastretval);
735 require_once DOL_DOCUMENT_ROOT.
'/core/lib/geturl.lib.php';
743 if (!empty($this->_smtpsID) && (!empty($this->_smtpsPW) || !empty($this->_smtpsToken))) {
750 $usetls = preg_match(
'@tls://@i', $host);
752 $host = preg_replace(
'@tcp://@i',
'', $host);
753 $host = preg_replace(
'@ssl://@i',
'', $host);
754 $host = preg_replace(
'@tls://@i',
'', $host);
757 $host =
'tls://'.$host;
769 $hosth = (string) $this->
getFrom(
'addr');
770 $hosth = preg_replace(
'/^.*</',
'', $hosth);
771 $hosth = preg_replace(
'/>.*$/',
'', $hosth);
772 $hosth = preg_replace(
'/.*@/',
'', $hosth);
790 if (!$resultmailfrom) {
791 fclose($this->socket);
815 fclose($this->socket);
824 fclose($this->socket);
838 fclose($this->socket);
883 if (!empty($_strConfigPath)) {
886 if (!@include $_strConfigPath) {
887 $this->
_setErr(110,
'"'.$_strConfigPath.
'" is not a valid path.');
894 if ($_host = ini_get(
'SMTPs')) {
898 if ($_port = ini_get(
'smtp_port')) {
902 if ($_from = ini_get(
'sendmail_from')) {
922 if ((is_numeric($_type)) && (($_type >= 0) && ($_type <= 3))) {
923 $this->_transportType = $_type;
937 return $this->_transportType;
965 $this->_smtpsHost = $_strHost;
977 return $this->_smtpsHost;
990 if ((is_numeric($_intPort)) &&
991 (($_intPort >= 1) && ($_intPort <= 65536))) {
992 $this->_smtpsPort = (int) $_intPort;
1004 return (
int) $this->_smtpsPort;
1015 $this->_smtpsID = $_strID;
1025 return $this->_smtpsID;
1036 $this->_smtpsPW = $_strPW;
1046 return $this->_smtpsPW;
1057 $this->_smtpsToken = $_strToken;
1068 $this->_smtpsAuthType = (string) $_strAuthType;
1078 return $this->_smtpsToken;
1091 $this->_smtpsCharSet = $_strCharSet;
1102 return $this->_smtpsCharSet;
1122 if (array_search($_strTransEncode, $this->_smtpsTransEncodeTypes)) {
1123 $this->_smtpsTransEncode = $_strTransEncode;
1134 return $this->_smtpsTransEncode;
1154 if (array_search($_strTransEncodeType, $this->_smtpsTransEncodeTypes)) {
1155 $this->_smtpsTransEncodeType = $_strTransEncodeType;
1166 return $this->_smtpsTransEncodeTypes[$this->_smtpsTransEncodeType];
1195 if ($_part ===
true || $this->_msgFrom ===
null) {
1196 $_retValue = $this->_msgFrom;
1198 $_retValue = $this->_msgFrom[$_part];
1213 $this->_msgReplyTo = $this->
_strip_email($_strReplyTo);
1227 if ($_part ===
true) {
1228 $_retValue = $this->_msgReplyTo;
1230 $_retValue = $this->_msgReplyTo[$_part];
1244 if ($_strInReplyTo) {
1245 $this->_msgInReplyTo = $_strInReplyTo;
1256 $_retValue = $this->_msgInReplyTo;
1269 if ($_strReferences) {
1270 $this->_msgReferences = $_strReferences;
1281 $_retValue = $this->_msgReferences;
1298 $aryHost = $this->_msgRecipients;
1301 if (!empty($_addrList)) {
1303 if (is_string($_addrList)) {
1305 if (strstr($_addrList,
',')) {
1307 $_addrList = explode(
',', $_addrList);
1310 $_addrList = array($_addrList);
1315 foreach ($_addrList as $_strAddr) {
1317 $_strAddr = str_replace(
'>',
'', $_strAddr);
1321 $_tmpaddr = explode(
'<', $_strAddr);
1324 if (count($_tmpaddr) == 2) {
1325 $_tmpHost = explode(
'@', $_tmpaddr[1]);
1326 $_tmpaddr[0] = trim($_tmpaddr[0],
' ">');
1327 $aryHost[$_tmpHost[1]][$_type][$_tmpHost[0]] = $_tmpaddr[0];
1331 $_strAddr = str_replace(
'<',
'', $_strAddr);
1333 $_tmpHost = explode(
'@', $_strAddr);
1334 $_tmpHost[0] = trim($_tmpHost[0]);
1335 $_tmpHost[1] = trim($_tmpHost[1]);
1337 $aryHost[$_tmpHost[1]][$_type][$_tmpHost[0]] =
'';
1342 $this->_msgRecipients = $aryHost;
1365 $_aryEmail = array();
1367 $_aryEmail[
'org'] = $_strAddr;
1370 $_strAddr = strtolower($_strAddr);
1373 $_strAddr = trim($_strAddr,
' ">');
1376 $_tmpAry = explode(
'<', $_strAddr);
1379 if (count($_tmpAry) == 2) {
1382 $_aryEmail[
'real'] = trim($_tmpAry[0],
' ">');
1385 $_aryEmail[
'addr'] = $_tmpAry[1];
1387 $_aryEmail[
'addr'] = $_tmpAry[0];
1391 $_tmpHost = explode(
'@', $_aryEmail[
'addr']);
1392 $_aryEmail[
'user'] = $_tmpHost[0];
1393 $_aryEmail[
'host'] = $_tmpHost[1];
1396 $_aryEmail[
'addr'] =
'<'.$_aryEmail[
'addr'].
'>';
1415 $_RCPT_list = array();
1418 foreach ($this->_msgRecipients as $_host => $_list) {
1419 foreach ($_list as $_subList) {
1420 foreach ($_subList as $_name => $_addr) {
1422 $_RCPT_list[] = $_name.
'@'.$_host;
1443 if ($this->_msgRecipients) {
1444 $_RCPT_list = array();
1446 foreach ($this->_msgRecipients as $_host => $_list) {
1447 if (!empty($this->_msgRecipients[$_host][$_which])) {
1448 foreach ($this->_msgRecipients[$_host][$_which] as $_addr => $_realName) {
1450 $_realName =
'"'.$_realName.
'"';
1451 $_RCPT_list[] = $_realName.
' <'.$_addr.
'@'.$_host.
'>';
1453 $_RCPT_list[] = $_addr.
'@'.$_host;
1459 return implode(
', ', $_RCPT_list);
1461 $this->
_setErr(101,
'No eMail Address for message to be sent to.');
1465 $this->
_setErr(102,
'eMail type not defined.');
1548 $this->_msgSubject = $_strSubject;
1559 return $this->_msgSubject;
1569 $_header =
'From: '.$this->getFrom(
'org').
"\r\n"
1570 .
'To: '.$this->getTo().
"\r\n";
1572 if ($this->
getCC()) {
1573 $_header .=
'Cc: '.$this->getCC().
"\r\n";
1587 $host = dol_getprefix(
'email');
1589 $_header .=
'Subject: '.$this->getSubject().
"\r\n";
1590 $_header .=
'Date: '.date(
"r").
"\r\n";
1594 $_header .=
'Message-ID: <'.(empty($this->_msgId) ? uniqid().
'.SMTPs-dolibarr-'.$trackid.
'@'.$host : $this->_msgId).
">\r\n";
1595 $_header .=
'X-Dolibarr-TRACKID: '.$trackid.
'@'.$host.
"\r\n";
1597 $_header .=
'Message-ID: <'.(empty($this->_msgId) ? uniqid().
'.SMTPs@'.$host : $this->_msgId).
">\r\n";
1599 if (!empty($_SERVER[
'REMOTE_ADDR'])) {
1600 $_header .=
"X-RemoteAddr: ".$_SERVER[
'REMOTE_ADDR'].
"\r\n";
1604 $_header .= preg_replace(
'/(?<!\r)\n/',
"\r\n", $this->
getMoreInHeader());
1608 $_header .=
'Sensitivity: '.$this->getSensitivity().
"\r\n";
1611 if ($this->_msgPriority != 3) {
1618 $_header .=
'Disposition-Notification-To: '.$this->getFrom(
'addr').
"\r\n";
1621 $_header .=
'Errors-To: '.$this->getErrorsTo(
'addr').
"\r\n";
1624 $_header .=
"Reply-To: ".$this->getReplyTo(
'addr').
"\r\n";
1627 $_header .=
'X-Mailer: Dolibarr version '.DOL_VERSION.
' (using SMTPs Mailer)'.
"\r\n";
1628 $_header .=
'X-Dolibarr-Option: '.(getDolGlobalString(
'MAIN_MAIL_USE_MULTI_PART') ?
'MAIN_MAIL_USE_MULTI_PART' :
'No MAIN_MAIL_USE_MULTI_PART').
"\r\n";
1629 $_header .=
'Mime-Version: 1.0'.
"\r\n";
1633 $_header .=
"In-Reply-To: ".$this->getInReplyTo().
"\r\n";
1639 $_header .=
"References: ".implode(
' ', $references).
"\r\n";
1656 if ($strType ==
'html') {
1657 $strMimeType =
'text/html';
1659 $strMimeType =
'text/plain';
1663 $strContent = preg_replace(
"/(?<!\r)\n/si",
"\r\n", $strContent);
1665 $strContentAltText =
'';
1666 if ($strType ==
'html') {
1668 $strContentAltText = preg_replace(
'/<head><title>.*<\/style><\/head>/',
'', $strContent);
1669 $strContentAltText = preg_replace(
"/<br\s*[^>]*>/",
" ", $strContentAltText);
1670 $strContentAltText = html_entity_decode(strip_tags($strContentAltText));
1671 $strContentAltText = trim(wordwrap($strContentAltText, 75,
"\r\n"));
1676 $strContent = rtrim(wordwrap($strContent, 75,
"\r\n"));
1678 $this->_msgContent[$strType] = array();
1680 $this->_msgContent[$strType][
'mimeType'] = $strMimeType;
1681 $this->_msgContent[$strType][
'data'] = $strContent;
1682 $this->_msgContent[$strType][
'dataText'] = $strContentAltText;
1685 $this->_msgContent[$strType][
'md5'] =
dol_hash($strContent,
'3');
1703 $_types = array_keys($this->_msgContent);
1706 $keyCount = count($_types);
1709 if ($keyCount === 0) {
1710 die(
"Sorry, no content");
1713 $_msgData = $this->_msgContent;
1714 $_msgData = $_msgData[$_types[0]];
1716 $content =
'Content-Type: '.$_msgData[
'mimeType'].
'; charset="'.$this->
getCharSet().
'"'.
"\r\n"
1717 .
'Content-Transfer-Encoding: '.$this->getTransEncodeType().
"\r\n"
1718 .
'Content-Disposition: inline'.
"\r\n"
1719 .
'Content-Description: Message'.
"\r\n";
1722 $content .=
'Content-MD5: '.$_msgData[
'md5'].
"\r\n";
1726 . $_msgData[
'data'].
"\r\n";
1734 $content =
'Content-Type: multipart/mixed; boundary="'.$this->_getBoundary(
'mixed').
'"'.
"\r\n";
1738 $content .=
"Content-Transfer-Encoding: 8bit\r\n";
1741 $content .=
"--".$this->_getBoundary(
'mixed').
"\r\n";
1743 if (array_key_exists(
'image', $this->_msgContent)) {
1744 $content .=
'Content-Type: multipart/alternative; boundary="'.$this->_getBoundary(
'alternative').
'"'.
"\r\n";
1746 $content .=
"--".$this->_getBoundary(
'alternative').
"\r\n";
1754 foreach ($this->_msgContent as $type => $_content) {
1755 if ($type ==
'attachment') {
1757 foreach ($_content as $_file => $_data) {
1758 $content .=
"--".$this->_getBoundary(
'mixed').
"\r\n"
1759 .
'Content-Disposition: attachment; filename="'.$_data[
'fileName'].
'"'.
"\r\n"
1760 .
'Content-Type: '.$_data[
'mimeType'].
'; name="'.$_data[
'fileName'].
'"'.
"\r\n"
1761 .
'Content-Transfer-Encoding: base64'.
"\r\n"
1762 .
'Content-Description: '.$_data[
'fileName'].
"\r\n";
1763 if (!empty($_data[
'cid'])) {
1764 $content .=
"X-Attachment-Id: ".$_data[
'cid'].
"\r\n";
1765 $content .=
"Content-ID: <".$_data[
'cid'].
">\r\n";
1768 $content .=
'Content-MD5: '.$_data[
'md5'].
"\r\n";
1771 $content .=
"\r\n".$_data[
'data'].
"\r\n\r\n";
1773 } elseif ($type ==
'image') {
1776 foreach ($_content as $_image => $_data) {
1777 $content .=
"--".$this->_getBoundary(
'related').
"\r\n";
1779 $content .=
'Content-Type: '.$_data[
'mimeType'].
'; name="'.$_data[
'imageName'].
'"'.
"\r\n"
1780 .
'Content-Transfer-Encoding: base64'.
"\r\n"
1781 .
'Content-Disposition: inline; filename="'.$_data[
'imageName'].
'"'.
"\r\n"
1782 .
'Content-ID: <'.$_data[
'cid'].
'> '.
"\r\n";
1785 $content .=
'Content-MD5: '.$_data[
'md5'].
"\r\n";
1789 . $_data[
'data'].
"\r\n";
1793 $content .=
"--".$this->_getBoundary(
'related').
"--\r\n";
1794 $content .=
"\r\n--".$this->_getBoundary(
'alternative').
"--\r\n";
1797 if (array_key_exists(
'image', $this->_msgContent)) {
1798 $content .=
"Content-Type: text/plain; charset=".$this->getCharSet().
"\r\n";
1799 $content .=
"\r\n".($_content[
'dataText'] ? $_content[
'dataText'] : strip_tags($_content[
'data'])).
"\r\n";
1800 $content .=
"--".$this->_getBoundary(
'alternative').
"\r\n";
1801 $content .=
'Content-Type: multipart/related; boundary="'.$this->_getBoundary(
'related').
'"'.
"\r\n";
1803 $content .=
"--".$this->_getBoundary(
'related').
"\r\n";
1806 if (!array_key_exists(
'image', $this->_msgContent) && $_content[
'dataText'] &&
getDolGlobalString(
'MAIN_MAIL_USE_MULTI_PART')) {
1808 $content .=
'Content-Type: multipart/alternative; boundary="'.$this->_getBoundary(
'alternative').
'"'.
"\r\n";
1810 $content .=
"--".$this->_getBoundary(
'alternative').
"\r\n";
1812 $content .=
"Content-Type: text/plain; charset=".$this->getCharSet().
"\r\n";
1813 $content .=
"\r\n".$_content[
'dataText'].
"\r\n";
1814 $content .=
"--".$this->_getBoundary(
'alternative').
"\r\n";
1817 $content .=
'Content-Type: '.$_content[
'mimeType'].
'; charset='.$this->
getCharSet();
1822 $content .=
'Content-MD5: '.$_content[
'md5'].
"\r\n";
1825 $content .=
"\r\n".$_content[
'data'].
"\r\n";
1827 if (!array_key_exists(
'image', $this->_msgContent) && $_content[
'dataText'] &&
getDolGlobalString(
'MAIN_MAIL_USE_MULTI_PART')) {
1829 $content .=
"--".$this->_getBoundary(
'alternative').
"--\r\n";
1836 $content .=
"--".$this->_getBoundary(
'mixed').
'--'.
"\r\n";
1838 die(
"Sorry, no content");
1854 public function setAttachment($strContent, $strFileName =
'unknown', $strMimeType =
'unknown', $strCid =
'')
1857 $strContent = rtrim(chunk_split(base64_encode($strContent), 76,
"\r\n"));
1861 $attachmentkey = $strFileName.
'-'.
dol_hash($strContent,
'sha256');
1863 $this->_msgContent[
'attachment'][$attachmentkey][
'mimeType'] = $strMimeType;
1864 $this->_msgContent[
'attachment'][$attachmentkey][
'fileName'] = $strFileName;
1865 $this->_msgContent[
'attachment'][$attachmentkey][
'data'] = $strContent;
1866 $this->_msgContent[
'attachment'][$attachmentkey][
'cid'] = $strCid;
1869 $this->_msgContent[
'attachment'][$attachmentkey][
'md5'] =
dol_hash($strContent,
'3');
1887 public function setImageInline($strContent, $strImageName =
'unknown', $strMimeType =
'unknown', $strImageCid =
'unknown')
1890 $this->_msgContent[
'image'][$strImageName][
'mimeType'] = $strMimeType;
1891 $this->_msgContent[
'image'][$strImageName][
'imageName'] = $strImageName;
1892 $this->_msgContent[
'image'][$strImageName][
'data'] = $strContent;
1893 $this->_msgContent[
'image'][$strImageName][
'cid'] = $strImageCid;
1896 $this->_msgContent[
'image'][$strImageName][
'md5'] =
dol_hash($strContent,
'3');
1916 if ((is_numeric($_value)) &&
1917 (($_value >= 0) && ($_value <= 3))) {
1918 $this->_msgSensitivity = $_value;
1934 return $this->_arySensitivity[$this->_msgSensitivity];
1952 if ((is_numeric($_value)) &&
1953 (($_value >= 0) && ($_value <= 5))) {
1954 $this->_msgPriority = $_value;
1972 return 'Importance: '.$this->_aryPriority[$this->_msgPriority].
"\r\n"
1973 .
'Priority: '.$this->_aryPriority[$this->_msgPriority].
"\r\n"
1974 .
'X-Priority: '.$this->_msgPriority.
' ('.$this->_aryPriority[$this->_msgPriority].
')'.
"\r\n";
1985 $this->_smtpMD5 = $_flag;
1995 return $this->_smtpMD5;
2009 $this->_msgXheader[] = $strXdata;
2020 return $this->_msgXheader;
2030 $this->_smtpsBoundary =
"multipart_x.".time().
".x_boundary";
2031 $this->_smtpsRelatedBoundary =
'mul_'.dol_hash(uniqid(
"dolibarr2"),
'3');
2032 $this->_smtpsAlternativeBoundary =
'mul_'.dol_hash(uniqid(
"dolibarr3"),
'3');
2043 if ($type ==
'mixed') {
2044 return $this->_smtpsBoundary;
2045 } elseif ($type ==
'related') {
2046 return $this->_smtpsRelatedBoundary;
2047 } elseif ($type ==
'alternative') {
2048 return $this->_smtpsAlternativeBoundary;
2073 $server_response =
'';
2078 while (substr($server_response, 3, 1) !=
' ' && $limit < 100) {
2080 if (!($server_response = fgets($socket))) {
2081 $this->
_setErr(121,
"Couldn't get mail server response codes");
2085 $this->log .= $server_response;
2089 $this->lastretval = substr($server_response, 0, 3);
2091 if (!(substr($server_response, 0, 3) == $response)) {
2092 $this->
_setErr(120,
"Ran into problems sending Mail.\r\nResponse: ".$server_response);
2111 if ($this->_debug) {
2112 $this->log .= $_strSend;
2114 fwrite($this->socket, $_strSend.$CRLF);
2115 if ($this->_debug) {
2116 $this->log .=
' ('.$_returnCode.
')'.$CRLF;
2120 return $this->
server_parse($this->socket, $_returnCode);
2138 $this->_smtpsErrors[] = array(
2153 if (is_array($this->_smtpsErrors)) {
2154 foreach ($this->_smtpsErrors as $_err => $_info) {
2155 $_errMsg[] =
'Error ['.$_info[
'num'].
']: '.$_info[
'msg'];
2159 return implode(
"\n", $_errMsg);
global $dolibarr_main_url_root
Class to construct and send SMTP compliant email, even to a secure SMTP server, regardless of platfor...
_getBoundary($type='mixed')
Retrieves the MIME message Boundary.
setConfig($_strConfigPath=null)
setConfig() is used to populate select class properties from either a user defined INI file or the sy...
sendMsg()
Now send the message.
getErrors()
Returns applicative errors codes and messages for Class (not the SMTP error code)
setCharSet($_strCharSet)
Character set used for current message Character set is defaulted to 'iso-8859-1';.
setSubject($_strSubject='')
Message Subject.
getPriority()
Message Content Priority Message Priority values:
setAuthType($_strAuthType)
Authentication method to use (the one of the send context)
setReferences($_strReferences)
Set References in the list of Msg-Id.
getMD5flag()
Gets flag which determines whether to calculate message MD5 checksum.
socket_send_str($_strSend, $_returnCode=null, $CRLF="\r\n")
Send str.
_strip_email($_strAddr)
Returns an array of the various parts of an email address This assumes a well formed address:
getTransEncodeType()
Retrieves the Content-Transfer-Encoding.
setTrackId($_val='')
Set trackid.
setToken($_strToken)
User token for OAUTH2.
setInReplyTo($_strInReplyTo)
Set References in the list of Msg-Id.
buildRCPTlist()
build RECIPIENT List, all addresses who will receive this message
getBodyContent()
Retrieves the Message Content.
_buildAddrList($_type, $_addrList)
Inserts given addresses into structured format.
getInReplyTo()
Retrieves the InReplyTo from which mail we reply to.
setOptions($_options=array())
Set options.
_server_connect()
Attempt a connection to mail server.
setBodyContent($strContent, $strType='plain')
Message Content.
server_parse($socket, $response)
This function has been modified as provided by SirSir to allow multiline responses when using SMTP Ex...
setTransportType($_type=0)
Determines the method inwhich the messages are to be sent.
getBCC()
Retrieves the BCC Address[es] inwhich to send mail to.
setAttachment($strContent, $strFileName='unknown', $strMimeType='unknown', $strCid='')
File attachments are added to the content array as sub-arrays, allowing for multiple attachments for ...
_setBoundary()
Generates Random string for MIME message Boundary.
getTo()
Retrieves the TO Address[es] inwhich to send mail to.
setPort($_intPort)
Defines the Port Number of the Mail Server to use The default is 25 This is used only with 'socket' b...
getID()
Retrieves the User Name for authentication on Mail Server.
setBCC($_strBCC)
BCC Address[es] inwhich to send mail to.
setReplyTo($_strReplyTo)
Reply-To Address from which mail will be the reply-to.
getToken()
Retrieves the User token for OAUTH2.
setSensitivity($_value=0)
Message Content Sensitivity Message Sensitivity values:
setCC($_strCC)
CC Address[es] inwhich to send mail to.
getSMTPTimeout()
Get socket timeout.
setTO($_addrTo)
TO Address[es] inwhich to send mail to.
setTransEncodeType($_strTransEncodeType)
Content-Transfer-Encoding, Defaulted to '0' [ZERO] This can be changed for 2byte characters sets Know...
get_email_list($_which=null)
Returns an array of addresses for a specific type; TO, CC or BCC.
setMD5flag($_flag=false)
Set flag which determines whether to calculate message MD5 checksum.
getCharSet()
Retrieves the Character set used for current message.
getCC()
Retrieves the CC Address[es] inwhich to send mail to.
getDeliveryReceipt()
get delivery receipt
setFrom($_strFrom)
FROM Address from which mail will be sent.
get_RCPT_list()
Returns an array of bare addresses for use with 'RCPT TO:' This is a "build as you go" method.
_server_authenticate()
Attempt mail server authentication for a secure connection.
setID($_strID)
User Name for authentication on Mail Server.
getMoreInHeader()
get moreInHeader
getPW()
Retrieves the User Password for authentication on Mail Server.
getSubject()
Retrieves the Message Subject.
getXheader()
Retrieves the Message X-Header Content.
setErrorsTo($_strErrorsTo)
Set errors to.
setImageInline($strContent, $strImageName='unknown', $strMimeType='unknown', $strImageCid='unknown')
Image attachments are added to the content array as sub-arrays, allowing for multiple images for each...
setMessageID($_msgId='')
Set Message-ID.
setHost($_strHost)
Defines the Host Name or IP of the Mail Server to use.
getFrom($_part=true)
Retrieves the Address from which mail will be sent.
getHost()
Retrieves the Host Name or IP of the Mail Server to use This is used only with 'socket' based mail tr...
setPW($_strPW)
User Password for authentication on Mail Server.
getReplyTo($_part=true)
Retrieves the Address from which mail will be the reply-to.
setPriority($_value=3)
Message Content Priority Message Priority values:
setMoreInHeader($_val='')
Set moreInHeader.
getErrorsTo($_part=true)
Get errors to.
getSensitivity()
Returns Message Content Sensitivity string Message Sensitivity values:
setSMTPTimeout($timeout)
Set socket timeout.
getPort()
Retrieves the Port Number of the Mail Server to use This is used only with 'socket' based mail transm...
getTransportType()
Return the method inwhich the message is to be sent.
setMailPath($_path)
Path to the sendmail executable.
getTransEncode()
Retrieves the Content-Transfer-Encoding.
getReferences()
Retrieves the References from which mail will be the reply-to.
setTransEncode($_strTransEncode)
Content-Transfer-Encoding, Defaulted to '7bit' This can be changed for 2byte characters sets Known En...
setDebug($_vDebug=false)
Set debug.
setDeliveryReceipt($_val=0)
Set delivery receipt.
_setErr($_errNum, $_errMsg)
Defines errors codes and messages for Class.
getHeader()
Constructs and returns message header.
setXheader($strXdata)
Message X-Header Content This is a simple "insert".
is_ip($ip)
This function evaluates a string that should be a valid IPv4 Note: For ip 169.254....
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
getDomainFromURL($url, $mode=0)
Function get second level domain name.
dol_hash($chain, $type='0', $nosalt=0, $mode=0)
Returns a hash (non reversible encryption) of a string.