dolibarr  13.0.2
smtps.class.php
Go to the documentation of this file.
1 <?php
2 /*
3  * Copyright (C) Walter Torres <walter@torres.ws> [with a *lot* of help!]
4  * Copyright (C) 2005-2015 Laurent Destailleur <eldy@users.sourceforge.net>
5  * Copyright (C) 2006-2011 Regis Houssin
6  * Copyright (C) 2016 Jonathan TISSEAU <jonathan.tisseau@86dev.fr>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <https://www.gnu.org/licenses/>.
20  */
21 
46 class SMTPs
47 {
51  private $_smtpsHost = 'localhost';
52 
57  private $_smtpsPort = '25';
58 
63  private $_smtpsID = null;
64 
69  private $_smtpsPW = null;
70 
75  private $_msgFrom = null;
76 
81  private $_msgReplyTo = null;
82 
88  private $_msgRecipients = null;
89 
93  private $_msgSubject = null;
94 
98  private $_msgContent = null;
99 
103  private $_msgXheader = null;
104 
109  private $_smtpsCharSet = 'iso-8859-1';
110 
115  private $_msgSensitivity = 0;
116 
120  private $_arySensitivity = array(false,
121  'Personal',
122  'Private',
123  'Company Confidential');
124 
129  private $_msgPriority = 3;
130 
134  private $_aryPriority = array('Bulk',
135  'Highest',
136  'High',
137  'Normal',
138  'Low',
139  'Lowest');
140 
146 
150  private $_smtpsTransEncodeTypes = array('7bit', // Simple 7-bit ASCII
151  '8bit', // 8-bit coding with line termination characters
152  'base64', // 3 octets encoded into 4 sextets with offset
153  'binary', // Arbitrary binary stream
154  'mac-binhex40', // Macintosh binary to hex encoding
155  'quoted-printable', // Mostly 7-bit, with 8-bit characters encoded as "=HH"
156  'uuencode'); // UUENCODE encoding
157 
162  private $_smtpsTransEncode = '7bit';
163 
167  private $_smtpsBoundary = null;
168 
172  private $_smtpsRelatedBoundary = null;
173 
178 
186  private $_transportType = 0;
187 
192  private $_mailPath = '/usr/lib/sendmail';
193 
197  private $_smtpTimeout = 10;
198 
202  private $_smtpMD5 = false;
203 
207  private $_smtpsErrors = null;
208 
216  private $_log_level = 0;
217 
221  private $_debug = false;
222 
223 
224  // @CHANGE LDR
225  public $log = '';
226  private $_errorsTo = '';
227  private $_deliveryReceipt = 0;
228  private $_trackId = '';
229  private $_moreInHeader = '';
230 
234  private $_options = [];
235 
242  public function setOptions($_options = [])
243  {
244  $this->_options = $_options;
245  }
246 
253  public function setDeliveryReceipt($_val = 0)
254  {
255  $this->_deliveryReceipt = $_val;
256  }
257 
263  public function getDeliveryReceipt()
264  {
265  return $this->_deliveryReceipt;
266  }
267 
274  public function setTrackId($_val = '')
275  {
276  $this->_trackId = $_val;
277  }
278 
285  public function setMoreInHeader($_val = '')
286  {
287  $this->_moreinheader = $_val;
288  }
289 
295  public function getTrackId()
296  {
297  return $this->_trackId;
298  }
299 
305  public function getMoreInHeader()
306  {
307  return $this->_moreinheader;
308  }
309 
316  public function setErrorsTo($_strErrorsTo)
317  {
318  if ($_strErrorsTo)
319  $this->_errorsTo = $this->_strip_email($_strErrorsTo);
320  }
321 
328  public function getErrorsTo($_part = true)
329  {
330  $_retValue = '';
331 
332  if ($_part === true)
333  $_retValue = $this->_errorsTo;
334  else $_retValue = $this->_errorsTo[$_part];
335 
336  return $_retValue;
337  }
338 
345  public function setDebug($_vDebug = false)
346  {
347  $this->_debug = $_vDebug;
348  }
349 
355  public function buildRCPTlist()
356  {
357  // Pull TO list
358  $_aryToList = $this->getTO();
359  }
360 
361  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
367  private function _server_connect()
368  {
369  // phpcs:enable
370  // Default return value
371  $_retVal = true;
372 
373  // We have to make sure the HOST given is valid
374  // This is done here because '@fsockopen' will not give me this
375  // information if it failes to connect because it can't find the HOST
376  $host = $this->getHost();
377  $usetls = preg_match('@tls://@i', $host);
378 
379  $host = preg_replace('@tcp://@i', '', $host); // Remove prefix
380  $host = preg_replace('@ssl://@i', '', $host); // Remove prefix
381  $host = preg_replace('@tls://@i', '', $host); // Remove prefix
382 
383  // @CHANGE LDR
384  include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
385 
386  if ((!is_ip($host)) && ((gethostbyname($host)) == $host))
387  {
388  $this->_setErr(99, $host.' is either offline or is an invalid host name.');
389  $_retVal = false;
390  } else {
391  if (function_exists('stream_socket_client') && !empty($this->_options)) {
392  $socket_context = stream_context_create($this->_options); // An array of options for stream_context_create()
393  set_error_handler([$this, 'errorHandler']);
394  $this->socket = @stream_socket_client(
395  preg_replace('@tls://@i', '', $this->getHost()).// Host to 'hit', IP or domain
396  ':'.$this->getPort(), // which Port number to use
397  $this->errno, // actual system level error
398  $this->errstr, // and any text that goes with the error
399  $this->_smtpTimeout, // timeout for reading/writing data over the socket
400  STREAM_CLIENT_CONNECT,
401  $socket_context // Options for connection
402  );
403  } else {
404  $this->socket = @fsockopen(
405  preg_replace('@tls://@i', '', $this->getHost()), // Host to 'hit', IP or domain
406  $this->getPort(), // which Port number to use
407  $this->errno, // actual system level error
408  $this->errstr, // and any text that goes with the error
409  $this->_smtpTimeout // timeout for reading/writing data over the socket
410  );
411  }
412 
413  //See if we can connect to the SMTP server
414  if (is_resource($this->socket))
415  {
416  // Fix from PHP SMTP class by 'Chris Ryan'
417  // Sometimes the SMTP server takes a little longer to respond
418  // so we will give it a longer timeout for the first read
419  // Windows still does not have support for this timeout function
420  if (function_exists('stream_set_timeout')) stream_set_timeout($this->socket, $this->_smtpTimeout, 0);
421 
422  // Check response from Server
423  if ($_retVal = $this->server_parse($this->socket, "220"))
424  $_retVal = $this->socket;
425  }
426  // This connection attempt failed.
427  else {
428  // @CHANGE LDR
429  if (empty($this->errstr)) $this->errstr = 'Failed to connect with fsockopen host='.$this->getHost().' port='.$this->getPort();
430  $this->_setErr($this->errno, $this->errstr);
431  $_retVal = false;
432  }
433  }
434 
435  return $_retVal;
436  }
437 
438  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
444  private function _server_authenticate()
445  {
446  // phpcs:enable
447  global $conf;
448 
449  // Send the RFC2554 specified EHLO.
450  // This improvment as provided by 'SirSir' to
451  // accomodate both SMTP AND ESMTP capable servers
452  $host = $this->getHost();
453  $usetls = preg_match('@tls://@i', $host);
454 
455  $host = preg_replace('@tcp://@i', '', $host); // Remove prefix
456  $host = preg_replace('@ssl://@i', '', $host); // Remove prefix
457  $host = preg_replace('@tls://@i', '', $host); // Remove prefix
458 
459  if ($usetls && !empty($conf->global->MAIN_SMTPS_ADD_TLS_TO_HOST_FOR_HELO)) $host = 'tls://'.$host;
460 
461  $hosth = $host;
462 
463  if (!empty($conf->global->MAIL_SMTP_USE_FROM_FOR_HELO))
464  {
465  // If the from to is 'aaa <bbb@ccc.com>', we will keep 'ccc.com'
466  $hosth = $this->getFrom('addr');
467  $hosth = preg_replace('/^.*</', '', $hosth);
468  $hosth = preg_replace('/>.*$/', '', $hosth);
469  $hosth = preg_replace('/.*@/', '', $hosth);
470  }
471 
472  if ($_retVal = $this->socket_send_str('EHLO '.$hosth, '250'))
473  {
474  if ($usetls)
475  {
476  /*
477  The following dialog illustrates how a client and server can start a TLS STARTTLS session
478  S: <waits for connection on TCP port 25>
479  C: <opens connection>
480  S: 220 mail.imc.org SMTP service ready
481  C: EHLO mail.ietf.org
482  S: 250-mail.imc.org offers a warm hug of welcome
483  S: 250 STARTTLS
484  C: STARTTLS
485  S: 220 Go ahead
486  C: <starts TLS negotiation>
487  C & S: <negotiate a TLS session>
488  C & S: <check result of negotiation>
489  // Second pass EHLO
490  C: EHLO client-domain.com
491  S: 250-server-domain.com
492  S: 250 AUTH LOGIN
493  C: <continues by sending an SMTP command
494  */
495  if (!$_retVal = $this->socket_send_str('STARTTLS', 220))
496  {
497  $this->_setErr(131, 'STARTTLS connection is not supported.');
498  return $_retVal;
499  }
500 
501  // Before 5.6.7:
502  // STREAM_CRYPTO_METHOD_SSLv23_CLIENT = STREAM_CRYPTO_METHOD_SSLv2_CLIENT|STREAM_CRYPTO_METHOD_SSLv3_CLIENT
503  // STREAM_CRYPTO_METHOD_TLS_CLIENT = STREAM_CRYPTO_METHOD_TLSv1_0_CLIENT|STREAM_CRYPTO_METHOD_TLSv1_1_CLIENT|STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT
504  // PHP >= 5.6.7:
505  // STREAM_CRYPTO_METHOD_SSLv23_CLIENT = STREAM_CRYPTO_METHOD_TLSv1_0_CLIENT|STREAM_CRYPTO_METHOD_TLSv1_1_CLIENT|STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT
506  // STREAM_CRYPTO_METHOD_TLS_CLIENT = STREAM_CRYPTO_METHOD_TLSv1_0_CLIENT
507 
508  $crypto_method = STREAM_CRYPTO_METHOD_TLS_CLIENT;
509  if (defined('STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT')) {
510  $crypto_method |= STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT;
511  $crypto_method |= STREAM_CRYPTO_METHOD_TLSv1_1_CLIENT;
512  }
513 
514  if (!stream_socket_enable_crypto($this->socket, true, $crypto_method))
515  {
516  $this->_setErr(132, 'STARTTLS connection failed.');
517  return $_retVal;
518  }
519  // Most server servers expect a 2nd pass of EHLO after TLS is established to get another time
520  // the answer with list of supported AUTH methods. They may differs between non STARTTLS and with STARTTLS.
521  if (!$_retVal = $this->socket_send_str('EHLO '.$hosth, '250'))
522  {
523  $this->_setErr(126, '"'.$hosth.'" does not support authenticated connections.');
524  return $_retVal;
525  }
526  }
527 
528  // Default authentication method is LOGIN
529  if (empty($conf->global->MAIL_SMTP_AUTH_TYPE)) $conf->global->MAIL_SMTP_AUTH_TYPE = 'LOGIN';
530 
531  // Send Authentication to Server
532  // Check for errors along the way
533  switch ($conf->global->MAIL_SMTP_AUTH_TYPE) {
534  case 'PLAIN':
535  $this->socket_send_str('AUTH PLAIN', '334');
536  // The error here just means the ID/password combo doesn't work.
537  $_retVal = $this->socket_send_str(base64_encode("\0".$this->_smtpsID."\0".$this->_smtpsPW), '235');
538  break;
539  case 'LOGIN': // most common case
540  default:
541  $this->socket_send_str('AUTH LOGIN', '334');
542  // User name will not return any error, server will take anything we give it.
543  $this->socket_send_str(base64_encode($this->_smtpsID), '334');
544  // The error here just means the ID/password combo doesn't work.
545  // There is not a method to determine which is the problem, ID or password
546  $_retVal = $this->socket_send_str(base64_encode($this->_smtpsPW), '235');
547  break;
548  }
549  if (!$_retVal) {
550  $this->_setErr(130, 'Invalid Authentication Credentials.');
551  }
552  } else {
553  $this->_setErr(126, '"'.$host.'" does not support authenticated connections.');
554  }
555 
556  return $_retVal;
557  }
558 
564  public function sendMsg()
565  {
566  global $conf;
567 
571  $_retVal = false;
572 
573  // Connect to Server
574  if ($this->socket = $this->_server_connect())
575  {
576  // If a User ID *and* a password is given, assume Authentication is desired
577  if (!empty($this->_smtpsID) && !empty($this->_smtpsPW))
578  {
579  // Send the RFC2554 specified EHLO.
580  $_retVal = $this->_server_authenticate();
581  }
582 
583  // This is a "normal" SMTP Server "handshack"
584  else {
585  // Send the RFC821 specified HELO.
586  $host = $this->getHost();
587  $usetls = preg_match('@tls://@i', $host);
588 
589  $host = preg_replace('@tcp://@i', '', $host); // Remove prefix
590  $host = preg_replace('@ssl://@i', '', $host); // Remove prefix
591  $host = preg_replace('@tls://@i', '', $host); // Remove prefix
592 
593  if ($usetls && !empty($conf->global->MAIN_SMTPS_ADD_TLS_TO_HOST_FOR_HELO)) $host = 'tls://'.$host;
594 
595  $hosth = $host;
596 
597  if (!empty($conf->global->MAIL_SMTP_USE_FROM_FOR_HELO))
598  {
599  // If the from to is 'aaa <bbb@ccc.com>', we will keep 'ccc.com'
600  $hosth = $this->getFrom('addr');
601  $hosth = preg_replace('/^.*</', '', $hosth);
602  $hosth = preg_replace('/>.*$/', '', $hosth);
603  $hosth = preg_replace('/.*@/', '', $hosth);
604  }
605 
606  $_retVal = $this->socket_send_str('HELO '.$hosth, '250');
607  }
608 
609  // Well, did we get to the server?
610  if ($_retVal)
611  {
612  // From this point onward most server response codes should be 250
613  // Specify who the mail is from....
614  // This has to be the raw email address, strip the "name" off
615  $resultmailfrom = $this->socket_send_str('MAIL FROM: '.$this->getFrom('addr'), '250');
616  if (!$resultmailfrom) {
617  fclose($this->socket);
618  return false;
619  }
620 
621  // 'RCPT TO:' must be given a single address, so this has to loop
622  // through the list of addresses, regardless of TO, CC or BCC
623  // and send it out "single file"
624  foreach ($this->get_RCPT_list() as $_address)
625  {
626  /* Note:
627  * BCC email addresses must be listed in the RCPT TO command list,
628  * but the BCC header should not be printed under the DATA command.
629  * http://stackoverflow.com/questions/2750211/sending-bcc-emails-using-a-smtp-server
630  */
631 
632  /*
633  * TODO
634  * After each 'RCPT TO:' is sent, we need to make sure it was kosher,
635  * if not, the whole message will fail
636  * If any email address fails, we will need to RESET the connection,
637  * mark the last address as "bad" and start the address loop over again.
638  * If any address fails, the entire message fails.
639  */
640  $this->socket_send_str('RCPT TO: <'.$_address.'>', '250');
641  }
642 
643  // Tell the server we are ready to start sending data
644  // with any custom headers...
645  // This is the last response code we look for until the end of the message.
646  $this->socket_send_str('DATA', '354');
647 
648  // Now we are ready for the message...
649  // Ok, all the ingredients are mixed in let's cook this puppy...
650  $this->socket_send_str($this->getHeader().$this->getBodyContent()."\r\n".'.', '250');
651 
652  // Now tell the server we are done and close the socket...
653  fputs($this->socket, 'QUIT');
654  fclose($this->socket);
655  }
656  }
657 
658  return $_retVal;
659  }
660 
661  // =============================================================
662  // ** Setter & Getter methods
663 
664  // ** Basic System configuration
665 
691  public function setConfig($_strConfigPath = null)
692  {
697  $_retVal = true;
698 
699  // if we have a path...
700  if (!empty($_strConfigPath))
701  {
702  // If the path is not valid, this will NOT generate an error,
703  // it will simply return false.
704  if (!@include $_strConfigPath)
705  {
706  $this->_setErr(110, '"'.$_strConfigPath.'" is not a valid path.');
707  $_retVal = false;
708  }
709  }
710 
711  // Read the Systems php.ini file
712  else {
713  // Set these properties ONLY if they are set in the php.ini file.
714  // Otherwise the default values will be used.
715  if ($_host = ini_get('SMTPs'))
716  $this->setHost($_host);
717 
718  if ($_port = ini_get('smtp_port'))
719  $this->setPort($_port);
720 
721  if ($_from = ini_get('sendmail_from'))
722  $this->setFrom($_from);
723  }
724 
725  // Send back what we have
726  return $_retVal;
727  }
728 
738  public function setTransportType($_type = 0)
739  {
740  if ((is_numeric($_type)) && (($_type >= 0) && ($_type <= 3))) {
741  $this->_transportType = $_type;
742  }
743  }
744 
753  public function getTransportType()
754  {
755  return $this->_transportType;
756  }
757 
765  public function setMailPath($_path)
766  {
767  // This feature is not yet implemented
768  return true;
769 
770  //if ( $_path ) $this->_mailPath = $_path;
771  }
772 
781  public function setHost($_strHost)
782  {
783  if ($_strHost)
784  $this->_smtpsHost = $_strHost;
785  }
786 
793  public function getHost()
794  {
795  return $this->_smtpsHost;
796  }
797 
806  public function setPort($_intPort)
807  {
808  if ((is_numeric($_intPort)) &&
809  (($_intPort >= 1) && ($_intPort <= 65536)))
810  $this->_smtpsPort = $_intPort;
811  }
812 
819  public function getPort()
820  {
821  return $this->_smtpsPort;
822  }
823 
830  public function setID($_strID)
831  {
832  $this->_smtpsID = $_strID;
833  }
834 
840  public function getID()
841  {
842  return $this->_smtpsID;
843  }
844 
851  public function setPW($_strPW)
852  {
853  $this->_smtpsPW = $_strPW;
854  }
855 
861  public function getPW()
862  {
863  return $this->_smtpsPW;
864  }
865 
873  public function setCharSet($_strCharSet)
874  {
875  if ($_strCharSet)
876  $this->_smtpsCharSet = $_strCharSet;
877  }
878 
884  public function getCharSet()
885  {
886  return $this->_smtpsCharSet;
887  }
888 
904  public function setTransEncode($_strTransEncode)
905  {
906  if (array_search($_strTransEncode, $this->_smtpsTransEncodeTypes))
907  $this->_smtpsTransEncode = $_strTransEncode;
908  }
909 
915  public function getTransEncode()
916  {
918  }
919 
936  public function setTransEncodeType($_strTransEncodeType)
937  {
938  if (array_search($_strTransEncodeType, $this->_smtpsTransEncodeTypes))
939  $this->_smtpsTransEncodeType = $_strTransEncodeType;
940  }
941 
947  public function getTransEncodeType()
948  {
949  return $this->_smtpsTransEncodeTypes[$this->_smtpsTransEncodeType];
950  }
951 
952 
953  // ** Message Construction
954 
961  public function setFrom($_strFrom)
962  {
963  if ($_strFrom)
964  $this->_msgFrom = $this->_strip_email($_strFrom);
965  }
966 
973  public function getFrom($_part = true)
974  {
975  $_retValue = '';
976 
977  if ($_part === true)
978  $_retValue = $this->_msgFrom;
979  else $_retValue = $this->_msgFrom[$_part];
980 
981  return $_retValue;
982  }
983 
990  public function setReplyTo($_strReplyTo)
991  {
992  if ($_strReplyTo)
993  $this->_msgReplyTo = $this->_strip_email($_strReplyTo);
994  }
995 
1002  public function getReplyTo($_part = true)
1003  {
1004  $_retValue = '';
1005 
1006  if ($_part === true)
1007  $_retValue = $this->_msgReplyTo;
1008  else $_retValue = $this->_msgReplyTo[$_part];
1009 
1010  return $_retValue;
1011  }
1012 
1025  private function _buildAddrList($_type, $_addrList)
1026  {
1027  // Pull existing list
1028  $aryHost = $this->_msgRecipients;
1029 
1030  // Only run this if we have something
1031  if (!empty($_addrList))
1032  {
1033  // $_addrList can be a STRING or an array
1034  if (is_string($_addrList))
1035  {
1036  // This could be a COMMA delimited string
1037  if (strstr($_addrList, ','))
1038  // "explode "list" into an array
1039  $_addrList = explode(',', $_addrList);
1040 
1041  // Stick it in an array
1042  else $_addrList = array($_addrList);
1043  }
1044 
1045  // take the array of addresses and split them further
1046  foreach ($_addrList as $_strAddr)
1047  {
1048  // Strip off the end '>'
1049  $_strAddr = str_replace('>', '', $_strAddr);
1050 
1051  // Seperate "Real Name" from eMail address
1052  $_tmpaddr = null;
1053  $_tmpaddr = explode('<', $_strAddr);
1054 
1055  // We have a "Real Name" and eMail address
1056  if (count($_tmpaddr) == 2)
1057  {
1058  $_tmpHost = explode('@', $_tmpaddr[1]);
1059  $_tmpaddr[0] = trim($_tmpaddr[0], ' ">');
1060  $aryHost[$_tmpHost[1]][$_type][$_tmpHost[0]] = $_tmpaddr[0];
1061  }
1062  // We only have an eMail address
1063  else {
1064  // Strip off the beggining '<'
1065  $_strAddr = str_replace('<', '', $_strAddr);
1066 
1067  $_tmpHost = explode('@', $_strAddr);
1068  $_tmpHost[0] = trim($_tmpHost[0]);
1069  $_tmpHost[1] = trim($_tmpHost[1]);
1070 
1071  $aryHost[$_tmpHost[1]][$_type][$_tmpHost[0]] = '';
1072  }
1073  }
1074  }
1075  // replace list
1076  $this->_msgRecipients = $aryHost;
1077  }
1078 
1079  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1096  private function _strip_email($_strAddr)
1097  {
1098  // phpcs:enable
1099  // Keep the orginal
1100  $_aryEmail['org'] = $_strAddr;
1101 
1102  // Set entire string to Lower Case
1103  $_strAddr = strtolower($_strAddr);
1104 
1105  // Drop "stuff' off the end
1106  $_strAddr = trim($_strAddr, ' ">');
1107 
1108  // Seperate "Real Name" from eMail address, if we have one
1109  $_tmpAry = explode('<', $_strAddr);
1110 
1111  // Do we have a "Real name"
1112  if (count($_tmpAry) == 2)
1113  {
1114  // We may not really have a "Real Name"
1115  if ($_tmpAry[0])
1116  $_aryEmail['real'] = trim($_tmpAry[0], ' ">');
1117 
1118  $_aryEmail['addr'] = $_tmpAry[1];
1119  } else $_aryEmail['addr'] = $_tmpAry[0];
1120 
1121  // Pull User Name and Host.tld apart
1122  list($_aryEmail['user'], $_aryEmail['host']) = explode('@', $_aryEmail['addr']);
1123 
1124  // Put the brackets back around the address
1125  $_aryEmail['addr'] = '<'.$_aryEmail['addr'].'>';
1126 
1127  return $_aryEmail;
1128  }
1129 
1130  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1138  public function get_RCPT_list()
1139  {
1140  // phpcs:enable
1144  $_RCPT_list = array();
1145 
1146  // walk down Recipients array and pull just email addresses
1147  foreach ($this->_msgRecipients as $_host => $_list)
1148  {
1149  foreach ($_list as $_subList)
1150  {
1151  foreach ($_subList as $_name => $_addr)
1152  {
1153  // build RCPT list
1154  $_RCPT_list[] = $_name.'@'.$_host;
1155  }
1156  }
1157  }
1158 
1159  return $_RCPT_list;
1160  }
1161 
1162  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1169  public function get_email_list($_which = null)
1170  {
1171  // phpcs:enable
1172  // We need to know which address segment to pull
1173  if ($_which)
1174  {
1175  // Make sure we have addresses to process
1176  if ($this->_msgRecipients)
1177  {
1178  $_RCPT_list = array();
1179  // walk down Recipients array and pull just email addresses
1180  foreach ($this->_msgRecipients as $_host => $_list)
1181  {
1182  if ($this->_msgRecipients[$_host][$_which])
1183  {
1184  foreach ($this->_msgRecipients[$_host][$_which] as $_addr => $_realName)
1185  {
1186  if ($_realName) // @CHANGE LDR
1187  {
1188  $_realName = '"'.$_realName.'"';
1189  $_RCPT_list[] = $_realName.' <'.$_addr.'@'.$_host.'>';
1190  } else {
1191  $_RCPT_list[] = $_addr.'@'.$_host;
1192  }
1193  }
1194  }
1195  }
1196 
1197  return implode(', ', $_RCPT_list);
1198  } else {
1199  $this->_setErr(101, 'No eMail Address for message to be sent to.');
1200  return false;
1201  }
1202  } else {
1203  $this->_setErr(102, 'eMail type not defined.');
1204  return false;
1205  }
1206  }
1207 
1214  public function setTO($_addrTo)
1215  {
1216  if ($_addrTo)
1217  $this->_buildAddrList('to', $_addrTo);
1218  }
1219 
1225  public function getTo()
1226  {
1227  return $this->get_email_list('to');
1228  }
1229 
1236  public function setCC($_strCC)
1237  {
1238  if ($_strCC)
1239  $this->_buildAddrList('cc', $_strCC);
1240  }
1241 
1247  public function getCC()
1248  {
1249  return $this->get_email_list('cc');
1250  }
1251 
1258  public function setBCC($_strBCC)
1259  {
1260  if ($_strBCC)
1261  $this->_buildAddrList('bcc', $_strBCC);
1262  }
1263 
1269  public function getBCC()
1270  {
1271  return $this->get_email_list('bcc');
1272  }
1273 
1280  public function setSubject($_strSubject = '')
1281  {
1282  if ($_strSubject)
1283  $this->_msgSubject = $_strSubject;
1284  }
1285 
1291  public function getSubject()
1292  {
1293  return $this->_msgSubject;
1294  }
1295 
1301  public function getHeader()
1302  {
1303  global $conf;
1304 
1305  $_header = 'From: '.$this->getFrom('org')."\r\n"
1306  . 'To: '.$this->getTO()."\r\n";
1307 
1308  if ($this->getCC())
1309  $_header .= 'Cc: '.$this->getCC()."\r\n";
1310 
1311  /* Note:
1312  * BCC email addresses must be listed in the RCPT TO command list,
1313  * but the BCC header should not be printed under the DATA command.
1314  * So it is included into the function sendMsg() but not here.
1315  * http://stackoverflow.com/questions/2750211/sending-bcc-emails-using-a-smtp-server
1316  */
1317  /*
1318  if ( $this->getBCC() )
1319  $_header .= 'Bcc: ' . $this->getBCC() . "\r\n";
1320  */
1321 
1322  $host = dol_getprefix('email');
1323 
1324  //NOTE: Message-ID should probably contain the username of the user who sent the msg
1325  $_header .= 'Subject: '.$this->getSubject()."\r\n";
1326  $_header .= 'Date: '.date("r")."\r\n";
1327 
1328  $trackid = $this->getTrackId();
1329  if ($trackid)
1330  {
1331  // References is kept in response and Message-ID is returned into In-Reply-To:
1332  $_header .= 'Message-ID: <'.time().'.SMTPs-dolibarr-'.$trackid.'@'.$host.">\r\n";
1333  $_header .= 'References: <'.time().'.SMTPs-dolibarr-'.$trackid.'@'.$host.">\r\n";
1334  $_header .= 'X-Dolibarr-TRACKID: '.$trackid.'@'.$host."\r\n";
1335  } else {
1336  $_header .= 'Message-ID: <'.time().'.SMTPs@'.$host.">\r\n";
1337  }
1338  if (!empty($_SERVER['REMOTE_ADDR'])) $_header .= "X-RemoteAddr: ".$_SERVER['REMOTE_ADDR']."\r\n";
1339  if ($this->getMoreInHeader())
1340  $_header .= $this->getMoreInHeader(); // Value must include the "\r\n";
1341 
1342  //$_header .=
1343  // 'Read-Receipt-To: ' . $this->getFrom( 'org' ) . "\r\n"
1344  // 'Return-Receipt-To: ' . $this->getFrom( 'org' ) . "\r\n";
1345 
1346  if ($this->getSensitivity())
1347  $_header .= 'Sensitivity: '.$this->getSensitivity()."\r\n";
1348 
1349  if ($this->_msgPriority != 3)
1350  $_header .= $this->getPriority();
1351 
1352 
1353  // @CHANGE LDR
1354  if ($this->getDeliveryReceipt())
1355  $_header .= 'Disposition-Notification-To: '.$this->getFrom('addr')."\r\n";
1356  if ($this->getErrorsTo())
1357  $_header .= 'Errors-To: '.$this->getErrorsTo('addr')."\r\n";
1358  if ($this->getReplyTo())
1359  $_header .= "Reply-To: ".$this->getReplyTo('addr')."\r\n";
1360 
1361  $_header .= 'X-Mailer: Dolibarr version '.DOL_VERSION.' (using SMTPs Mailer)'."\r\n";
1362  $_header .= 'X-Dolibarr-Option: '.($conf->global->MAIN_MAIL_USE_MULTI_PART ? 'MAIN_MAIL_USE_MULTI_PART' : 'No MAIN_MAIL_USE_MULTI_PART')."\r\n";
1363  $_header .= 'Mime-Version: 1.0'."\r\n";
1364 
1365 
1366  return $_header;
1367  }
1368 
1376  public function setBodyContent($strContent, $strType = 'plain')
1377  {
1378  //if ( $strContent )
1379  //{
1380  if ($strType == 'html')
1381  $strMimeType = 'text/html';
1382  else $strMimeType = 'text/plain';
1383 
1384  // Make RFC821 Compliant, replace bare linefeeds
1385  $strContent = preg_replace("/(?<!\r)\n/si", "\r\n", $strContent);
1386 
1387  $strContentAltText = '';
1388  if ($strType == 'html')
1389  {
1390  // Similar code to forge a text from html is also in CMailFile.class.php
1391  $strContentAltText = preg_replace('/<head><title>.*<\/style><\/head>/', '', $strContent);
1392  $strContentAltText = preg_replace("/<br\s*[^>]*>/", " ", $strContentAltText);
1393  $strContentAltText = html_entity_decode(strip_tags($strContentAltText));
1394  $strContentAltText = trim(wordwrap($strContentAltText, 75, "\r\n"));
1395  }
1396 
1397  // Make RFC2045 Compliant
1398  //$strContent = rtrim(chunk_split($strContent)); // Function chunck_split seems ko if not used on a base64 content
1399  $strContent = rtrim(wordwrap($strContent, 75, "\r\n")); // TODO Using this method creates unexpected line break on text/plain content.
1400 
1401  $this->_msgContent[$strType] = array();
1402 
1403  $this->_msgContent[$strType]['mimeType'] = $strMimeType;
1404  $this->_msgContent[$strType]['data'] = $strContent;
1405  $this->_msgContent[$strType]['dataText'] = $strContentAltText;
1406 
1407  if ($this->getMD5flag())
1408  $this->_msgContent[$strType]['md5'] = dol_hash($strContent, 3);
1409  //}
1410  }
1411 
1417  public function getBodyContent()
1418  {
1419  global $conf;
1420 
1421  // Generate a new Boundary string
1422  $this->_setBoundary();
1423 
1424  // What type[s] of content do we have
1425  $_types = array_keys($this->_msgContent);
1426 
1427  // How many content types do we have
1428  $keyCount = count($_types);
1429 
1430  // If we have ZERO, we have a problem
1431  if ($keyCount === 0)
1432  die("Sorry, no content");
1433 
1434  // If we have ONE, we can use the simple format
1435  elseif ($keyCount === 1 && empty($conf->global->MAIN_MAIL_USE_MULTI_PART))
1436  {
1437  $_msgData = $this->_msgContent;
1438  $_msgData = $_msgData[$_types[0]];
1439 
1440  $content = 'Content-Type: '.$_msgData['mimeType'].'; charset="'.$this->getCharSet().'"'."\r\n"
1441  . 'Content-Transfer-Encoding: '.$this->getTransEncodeType()."\r\n"
1442  . 'Content-Disposition: inline'."\r\n"
1443  . 'Content-Description: Message'."\r\n";
1444 
1445  if ($this->getMD5flag())
1446  $content .= 'Content-MD5: '.$_msgData['md5']."\r\n";
1447 
1448  $content .= "\r\n"
1449  . $_msgData['data']."\r\n";
1450  }
1451 
1452  // If we have more than ONE, we use the multi-part format
1453  elseif ($keyCount >= 1 || !empty($conf->global->MAIN_MAIL_USE_MULTI_PART))
1454  {
1455  // Since this is an actual multi-part message
1456  // We need to define a content message Boundary
1457  // NOTE: This was 'multipart/alternative', but Windows based mail servers have issues with this.
1458 
1459  //$content = 'Content-Type: multipart/related; boundary="' . $this->_getBoundary() . '"' . "\r\n";
1460  $content = 'Content-Type: multipart/mixed; boundary="'.$this->_getBoundary('mixed').'"'."\r\n";
1461 
1462  // . "\r\n"
1463  // . 'This is a multi-part message in MIME format.' . "\r\n";
1464  $content .= "Content-Transfer-Encoding: 8bit\r\n";
1465  $content .= "\r\n";
1466 
1467  $content .= "--".$this->_getBoundary('mixed')."\r\n";
1468 
1469  if (key_exists('image', $this->_msgContent)) // If inline image found
1470  {
1471  $content .= 'Content-Type: multipart/alternative; boundary="'.$this->_getBoundary('alternative').'"'."\r\n";
1472  $content .= "\r\n";
1473  $content .= "--".$this->_getBoundary('alternative')."\r\n";
1474  }
1475 
1476 
1477  // $this->_msgContent must be sorted with key 'text' or 'html' first then 'image' then 'attachment'
1478 
1479 
1480  // Loop through message content array
1481  foreach ($this->_msgContent as $type => $_content)
1482  {
1483  if ($type == 'attachment')
1484  {
1485  // loop through all attachments
1486  foreach ($_content as $_file => $_data)
1487  {
1488  $content .= "--".$this->_getBoundary('mixed')."\r\n"
1489  . 'Content-Disposition: attachment; filename="'.$_data['fileName'].'"'."\r\n"
1490  . 'Content-Type: '.$_data['mimeType'].'; name="'.$_data['fileName'].'"'."\r\n"
1491  . 'Content-Transfer-Encoding: base64'."\r\n"
1492  . 'Content-Description: '.$_data['fileName']."\r\n";
1493 
1494  if ($this->getMD5flag())
1495  $content .= 'Content-MD5: '.$_data['md5']."\r\n";
1496 
1497  $content .= "\r\n".$_data['data']."\r\n\r\n";
1498  }
1499  }
1500  // @CHANGE LDR
1501  elseif ($type == 'image')
1502  {
1503  // loop through all images
1504  foreach ($_content as $_image => $_data)
1505  {
1506  $content .= "--".$this->_getBoundary('related')."\r\n"; // always related for an inline image
1507 
1508  $content .= 'Content-Type: '.$_data['mimeType'].'; name="'.$_data['imageName'].'"'."\r\n"
1509  . 'Content-Transfer-Encoding: base64'."\r\n"
1510  . 'Content-Disposition: inline; filename="'.$_data['imageName'].'"'."\r\n"
1511  . 'Content-ID: <'.$_data['cid'].'> '."\r\n";
1512 
1513  if ($this->getMD5flag())
1514  $content .= 'Content-MD5: '.$_data['md5']."\r\n";
1515 
1516  $content .= "\r\n"
1517  . $_data['data']."\r\n";
1518  }
1519 
1520  // always end related and end alternative after inline images
1521  $content .= "--".$this->_getBoundary('related')."--\r\n";
1522  $content .= "\r\n--".$this->_getBoundary('alternative')."--\r\n";
1523  $content .= "\r\n";
1524  } else {
1525  if (key_exists('image', $this->_msgContent))
1526  {
1527  $content .= "Content-Type: text/plain; charset=".$this->getCharSet()."\r\n";
1528  $content .= "\r\n".($_content['dataText'] ? $_content['dataText'] : strip_tags($_content['data']))."\r\n"; // Add plain text message
1529  $content .= "--".$this->_getBoundary('alternative')."\r\n";
1530  $content .= 'Content-Type: multipart/related; boundary="'.$this->_getBoundary('related').'"'."\r\n";
1531  $content .= "\r\n";
1532  $content .= "--".$this->_getBoundary('related')."\r\n";
1533  }
1534 
1535  if (!key_exists('image', $this->_msgContent) && $_content['dataText'] && !empty($conf->global->MAIN_MAIL_USE_MULTI_PART)) // Add plain text message part before html part
1536  {
1537  $content .= 'Content-Type: multipart/alternative; boundary="'.$this->_getBoundary('alternative').'"'."\r\n";
1538  $content .= "\r\n";
1539  $content .= "--".$this->_getBoundary('alternative')."\r\n";
1540 
1541  $content .= "Content-Type: text/plain; charset=".$this->getCharSet()."\r\n";
1542  $content .= "\r\n".$_content['dataText']."\r\n";
1543  $content .= "--".$this->_getBoundary('alternative')."\r\n";
1544  }
1545 
1546  $content .= 'Content-Type: '.$_content['mimeType'].'; charset='.$this->getCharSet();
1547 
1548  $content .= "\r\n";
1549 
1550  if ($this->getMD5flag()) {
1551  $content .= 'Content-MD5: '.$_content['md5']."\r\n";
1552  }
1553 
1554  $content .= "\r\n".$_content['data']."\r\n";
1555 
1556  if (!key_exists('image', $this->_msgContent) && $_content['dataText'] && !empty($conf->global->MAIN_MAIL_USE_MULTI_PART)) // Add plain text message part after html part
1557  {
1558  $content .= "--".$this->_getBoundary('alternative')."--\r\n";
1559  }
1560 
1561  $content .= "\r\n";
1562  }
1563  }
1564 
1565  $content .= "--".$this->_getBoundary('mixed').'--'."\r\n";
1566  }
1567 
1568  return $content;
1569  }
1570 
1580  public function setAttachment($strContent, $strFileName = 'unknown', $strMimeType = 'unknown')
1581  {
1582  if ($strContent)
1583  {
1584  $strContent = rtrim(chunk_split(base64_encode($strContent), 76, "\r\n")); // 76 max is defined into http://tools.ietf.org/html/rfc2047
1585 
1586  $this->_msgContent['attachment'][$strFileName]['mimeType'] = $strMimeType;
1587  $this->_msgContent['attachment'][$strFileName]['fileName'] = $strFileName;
1588  $this->_msgContent['attachment'][$strFileName]['data'] = $strContent;
1589 
1590  if ($this->getMD5flag())
1591  $this->_msgContent['attachment'][$strFileName]['md5'] = dol_hash($strContent, 3);
1592  }
1593  }
1594 
1595 
1596  // @CHANGE LDR
1597 
1608  public function setImageInline($strContent, $strImageName = 'unknown', $strMimeType = 'unknown', $strImageCid = 'unknown')
1609  {
1610  if ($strContent)
1611  {
1612  $this->_msgContent['image'][$strImageName]['mimeType'] = $strMimeType;
1613  $this->_msgContent['image'][$strImageName]['imageName'] = $strImageName;
1614  $this->_msgContent['image'][$strImageName]['cid'] = $strImageCid;
1615  $this->_msgContent['image'][$strImageName]['data'] = $strContent;
1616 
1617  if ($this->getMD5flag())
1618  $this->_msgContent['image'][$strImageName]['md5'] = dol_hash($strContent, 3);
1619  }
1620  }
1621  // END @CHANGE LDR
1622 
1623 
1635  public function setSensitivity($_value = 0)
1636  {
1637  if ((is_numeric($_value)) &&
1638  (($_value >= 0) && ($_value <= 3)))
1639  $this->_msgSensitivity = $_value;
1640  }
1641 
1652  public function getSensitivity()
1653  {
1654  return $this->_arySensitivity[$this->_msgSensitivity];
1655  }
1656 
1670  public function setPriority($_value = 3)
1671  {
1672  if ((is_numeric($_value)) &&
1673  (($_value >= 0) && ($_value <= 5)))
1674  $this->_msgPriority = $_value;
1675  }
1676 
1689  public function getPriority()
1690  {
1691  return 'Importance: '.$this->_aryPriority[$this->_msgPriority]."\r\n"
1692  . 'Priority: '.$this->_aryPriority[$this->_msgPriority]."\r\n"
1693  . 'X-Priority: '.$this->_msgPriority.' ('.$this->_aryPriority[$this->_msgPriority].')'."\r\n";
1694  }
1695 
1702  public function setMD5flag($_flag = false)
1703  {
1704  $this->_smtpMD5 = $_flag;
1705  }
1706 
1712  public function getMD5flag()
1713  {
1714  return $this->_smtpMD5;
1715  }
1716 
1725  public function setXheader($strXdata)
1726  {
1727  if ($strXdata)
1728  $this->_msgXheader[] = $strXdata;
1729  }
1730 
1736  public function getXheader()
1737  {
1738  return $this->_msgXheader;
1739  }
1740 
1746  private function _setBoundary()
1747  {
1748  $this->_smtpsBoundary = "multipart_x.".time().".x_boundary";
1749  $this->_smtpsRelatedBoundary = 'mul_'.dol_hash(uniqid("dolibarr2"), 3);
1750  $this->_smtpsAlternativeBoundary = 'mul_'.dol_hash(uniqid("dolibarr3"), 3);
1751  }
1752 
1759  private function _getBoundary($type = 'mixed')
1760  {
1761  if ($type == 'mixed') return $this->_smtpsBoundary;
1762  elseif ($type == 'related') return $this->_smtpsRelatedBoundary;
1763  elseif ($type == 'alternative') return $this->_smtpsAlternativeBoundary;
1764  }
1765 
1766  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1775  public function server_parse($socket, $response)
1776  {
1777  // phpcs:enable
1782  $_retVal = true;
1783 
1784  $server_response = '';
1785 
1786  // avoid infinite loop
1787  $limit = 0;
1788 
1789  while (substr($server_response, 3, 1) != ' ' && $limit < 100)
1790  {
1791  if (!($server_response = fgets($socket, 256)))
1792  {
1793  $this->_setErr(121, "Couldn't get mail server response codes");
1794  $_retVal = false;
1795  break;
1796  }
1797  $this->log .= $server_response;
1798  $limit++;
1799  }
1800 
1801  if (!(substr($server_response, 0, 3) == $response))
1802  {
1803  $this->_setErr(120, "Ran into problems sending Mail.\r\nResponse: $server_response");
1804  $_retVal = false;
1805  }
1806 
1807  return $_retVal;
1808  }
1809 
1810  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1819  public function socket_send_str($_strSend, $_returnCode = null, $CRLF = "\r\n")
1820  {
1821  // phpcs:enable
1822  if ($this->_debug) $this->log .= $_strSend; // @CHANGE LDR for log
1823  fputs($this->socket, $_strSend.$CRLF);
1824  if ($this->_debug) $this->log .= ' ('.$_returnCode.')'.$CRLF;
1825 
1826  if ($_returnCode)
1827  return $this->server_parse($this->socket, $_returnCode);
1828  }
1829 
1830  // =============================================================
1831  // ** Error handling methods
1832 
1840  private function _setErr($_errNum, $_errMsg)
1841  {
1842  $this->_smtpsErrors[] = array(
1843  'num' => $_errNum,
1844  'msg' => $_errMsg,
1845  );
1846  }
1847 
1853  public function getErrors()
1854  {
1855  $_errMsg = array();
1856 
1857  if (is_array($this->_smtpsErrors))
1858  {
1859  foreach ($this->_smtpsErrors as $_err => $_info)
1860  {
1861  $_errMsg[] = 'Error ['.$_info['num'].']: '.$_info['msg'];
1862  }
1863  }
1864 
1865  return implode("\n", $_errMsg);
1866  }
1867 }
1868 
1869 
1870 // =============================================================
1871 // ** CSV Version Control Info
1872 
setDebug($_vDebug=false)
Set debug.
getID()
Retrieves the User Name for authentication on Mail Server.
$_debug
Place Class in&quot; debug&quot; mode.
$_smtpsPW
Secure SMTP Server access Password This can be defined via a INI file or via a setter method...
Definition: smtps.class.php:69
$_transportType
Determines the method inwhich the message are to be sent.
getTransportType()
Return the method inwhich the message is to be sent.
dol_hash($chain, $type= '0')
Returns a hash of a string.
getPW()
Retrieves the User Password for authentication on Mail Server.
setSensitivity($_value=0)
Message Content Sensitivity Message Sensitivity values:
getTransEncodeType()
Retrieves the Content-Transfer-Encoding.
setBodyContent($strContent, $strType= 'plain')
Message Content.
setTransEncodeType($_strTransEncodeType)
Content-Transfer-Encoding, Defaulted to &#39;0&#39; [ZERO] This can be changed for 2byte characers sets Known...
setCharSet($_strCharSet)
Character set used for current message Character set is defaulted to &#39;iso-8859-1&#39;;.
$_msgFrom
Who sent the Message This can be defined via a INI file or via a setter method.
Definition: smtps.class.php:75
setFrom($_strFrom)
FROM Address from which mail will be sent.
$_msgRecipients
Who will the Message be sent to; TO, CC, BCC Multi-diminsional array containg addresses the message w...
Definition: smtps.class.php:88
getSensitivity()
Returns Message Content Sensitivity string Message Sensitivity values:
$_smtpsID
Secure SMTP Server access ID This can be defined via a INI file or via a setter method.
Definition: smtps.class.php:63
getCharSet()
Retrieves the Character set used for current message.
buildRCPTlist()
build RECIPIENT List, all addresses who will recieve this message
Class to construct and send SMTP compliant email, even to a secure SMTP server, regardless of platfor...
Definition: smtps.class.php:46
setMoreInHeader($_val= '')
Set moreInHeader.
setXheader($strXdata)
Message X-Header Content This is a simple &quot;insert&quot;.
getFrom($_part=true)
Retrieves the Address from which mail will be sent.
_server_authenticate()
Attempt mail server authentication for a secure connection.
getHeader()
Constructes and returns message header.
setTrackId($_val= '')
Set trackid.
$_msgXheader
Custom X-Headers.
$_smtpTimeout
Sets the SMTP server timeout in seconds.
$_msgContent
Message Content.
Definition: smtps.class.php:98
setBCC($_strBCC)
BCC Address[es] inwhich to send mail to.
$_smtpMD5
Determines whether to calculate message MD5 checksum.
get_email_list($_which=null)
Returns an array of addresses for a specific type; TO, CC or BCC.
$_smtpsTransEncodeTypes
Content-Transfer-Encoding.
getMoreInHeader()
get moreInHeader
getMD5flag()
Gets flag which determines whether to calculate message MD5 checksum.
setTransEncode($_strTransEncode)
Content-Transfer-Encoding, Defaulted to &#39;7bit&#39; This can be changed for 2byte characers sets Known Enc...
getBodyContent()
Retrieves the Message Content.
get_RCPT_list()
Returns an array of bares addresses for use with &#39;RCPT TO:&#39; This is a &quot;build as you go&quot; method...
setHost($_strHost)
Defines the Host Name or IP of the Mail Server to use.
getTo()
Retrieves the TO Address[es] inwhich to send mail to.
setErrorsTo($_strErrorsTo)
Set errors to.
_buildAddrList($_type, $_addrList)
Inserts given addresses into structured format.
$_arySensitivity
Message Sensitivity.
$_log_level
Defines log level 0 - no logging 1 - connectivity logging 2 - message generation logging 3 - detail l...
setCC($_strCC)
CC Address[es] inwhich to send mail to.
$_options
An array of options for stream_context_create()
_server_connect()
Attempt a connection to mail server.
$_msgReplyTo
Where are replies and errors to be sent to This can be defined via a INI file or via a setter method...
Definition: smtps.class.php:81
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...
setPort($_intPort)
Defines the Port Number of the Mail Server to use This is defaulted to &#39;25&#39; This is used only with &#39;s...
getBCC()
Retrieves the BCC Address[es] inwhich to send mail to.
$_smtpsHost
Host Name or IP of SMTP Server to use.
Definition: smtps.class.php:51
$_smtpsAlternativeBoundary
Alternative Boundary.
socket_send_str($_strSend, $_returnCode=null, $CRLF="\r\n")
Send str.
$_smtpsTransEncode
Content-Transfer-Encoding Defaulted to &#39;7bit&#39;.
setOptions($_options=[])
Set delivery receipt.
setAttachment($strContent, $strFileName= 'unknown', $strMimeType= 'unknown')
File attachments are added to the content array as sub-arrays, allowing for multiple attachments for ...
setReplyTo($_strReplyTo)
Reply-To Address from which mail will be the reply-to.
getTrackId()
get trackid
server_parse($socket, $response)
This function has been modified as provided by SirSir to allow multiline responses when using SMTP Ex...
getErrors()
Returns errors codes and messages for Class.
getPort()
Retrieves the Port Number of the Mail Server to use This is used only with &#39;socket&#39; based mail transm...
setTO($_addrTo)
TO Address[es] inwhich to send mail to.
is_ip($ip)
This function evaluates a string that should be a valid IPv4 Note: For ip 169.254.0.0, it returns 0 with some PHP (5.6.24) and 2 with some minor patchs of PHP (5.6.25).
$_smtpsRelatedBoundary
Related Boundary.
setTransportType($_type=0)
Determines the method inwhich the messages are to be sent.
getHost()
Retrieves the Host Name or IP of the Mail Server to use This is used only with &#39;socket&#39; based mail tr...
getXheader()
Retrieves the Message X-Header Content.
$_aryPriority
Message Priority.
print $_SERVER["PHP_SELF"]
Edit parameters.
getPriority()
Message Content Priority Message Priority values:
getCC()
Retrieves the CC Address[es] inwhich to send mail to.
$_smtpsTransEncodeType
Content-Transfer-Encoding Defaulted to 0 - 7bit.
getSubject()
Retrieves the Message Subject.
$_msgSensitivity
Message Sensitivity Defaults to ZERO - None.
getDeliveryReceipt()
get delivery receipt
_strip_email($_strAddr)
Returns an array of the various parts of an email address This assumes a well formed address: ...
sendMsg()
Now send the message.
$_smtpsCharSet
Character set Defaulted to &#39;iso-8859-1&#39;.
$_smtpsErrors
Class error codes and messages.
getErrorsTo($_part=true)
Get errors to.
getReplyTo($_part=true)
Retrieves the Address from which mail will be the reply-to.
setPW($_strPW)
User Password for authentication on Mail Server.
setSubject($_strSubject= '')
Message Subject.
$_mailPath
If &#39;$_transportType&#39; is set to &#39;1&#39;, then this variable is used to define the UNIX file system path to...
setConfig($_strConfigPath=null)
setConfig() is used to populate select class properties from either a user defined INI file or the sy...
$_msgSubject
Message Subject.
Definition: smtps.class.php:93
$_msgPriority
Message Sensitivity Defaults to 3 - Normal.
setDeliveryReceipt($_val=0)
Set delivery receipt.
$_smtpsBoundary
Boundary String for MIME seperation.
_getBoundary($type= 'mixed')
Retrieves the MIME message Boundary.
_setBoundary()
Generates Random string for MIME message Boundary.
getTransEncode()
Retrieves the Content-Transfer-Encoding.
setMailPath($_path)
Path to the sendmail execuable.
$_smtpsPort
SMTP Server Port definition.
Definition: smtps.class.php:57
setID($_strID)
User Name for authentication on Mail Server.
_setErr($_errNum, $_errMsg)
Defines errors codes and messages for Class.
setPriority($_value=3)
Message Content Priority Message Priority values:
setMD5flag($_flag=false)
Set flag which determines whether to calculate message MD5 checksum.