dolibarr  16.0.1
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 = array();
235 
242  public function setOptions($_options = array())
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  }
322 
329  public function getErrorsTo($_part = true)
330  {
331  $_retValue = '';
332 
333  if ($_part === true) {
334  $_retValue = $this->_errorsTo;
335  } else {
336  $_retValue = $this->_errorsTo[$_part];
337  }
338 
339  return $_retValue;
340  }
341 
348  public function setDebug($_vDebug = false)
349  {
350  $this->_debug = $_vDebug;
351  }
352 
358  public function buildRCPTlist()
359  {
360  // Pull TO list
361  $_aryToList = $this->getTO();
362  }
363 
364  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
370  private function _server_connect()
371  {
372  // phpcs:enable
373  // Default return value
374  $_retVal = true;
375 
376  // We have to make sure the HOST given is valid
377  // This is done here because '@fsockopen' will not give me this
378  // information if it failes to connect because it can't find the HOST
379  $host = $this->getHost();
380  $usetls = preg_match('@tls://@i', $host);
381 
382  $host = preg_replace('@tcp://@i', '', $host); // Remove prefix
383  $host = preg_replace('@ssl://@i', '', $host); // Remove prefix
384  $host = preg_replace('@tls://@i', '', $host); // Remove prefix
385 
386  // @CHANGE LDR
387  include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
388 
389  if ((!is_ip($host)) && ((gethostbyname($host)) == $host)) {
390  $this->_setErr(99, $host.' is either offline or is an invalid host name.');
391  $_retVal = false;
392  } else {
393  if (function_exists('stream_socket_client') && !empty($this->_options)) {
394  $socket_context = stream_context_create($this->_options); // An array of options for stream_context_create()
395  $this->socket = @stream_socket_client(
396  preg_replace('@tls://@i', '', $this->getHost()).// Host to 'hit', IP or domain
397  ':'.$this->getPort(), // which Port number to use
398  $this->errno, // actual system level error
399  $this->errstr, // and any text that goes with the error
400  $this->_smtpTimeout, // timeout for reading/writing data over the socket
401  STREAM_CLIENT_CONNECT,
402  $socket_context // Options for connection
403  );
404  } else {
405  $this->socket = @fsockopen(
406  preg_replace('@tls://@i', '', $this->getHost()), // Host to 'hit', IP or domain
407  $this->getPort(), // which Port number to use
408  $this->errno, // actual system level error
409  $this->errstr, // and any text that goes with the error
410  $this->_smtpTimeout // timeout for reading/writing data over the socket
411  );
412  }
413 
414  //See if we can connect to the SMTP server
415  if (is_resource($this->socket)) {
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')) {
421  stream_set_timeout($this->socket, $this->_smtpTimeout, 0);
422  }
423 
424  // Check response from Server
425  if ($_retVal = $this->server_parse($this->socket, "220")) {
426  $_retVal = $this->socket;
427  }
428  } else {
429  // This connection attempt failed.
430  // @CHANGE LDR
431  if (empty($this->errstr)) {
432  $this->errstr = 'Failed to connect with fsockopen host='.$this->getHost().' port='.$this->getPort();
433  }
434  $this->_setErr($this->errno, $this->errstr);
435  $_retVal = false;
436  }
437  }
438 
439  return $_retVal;
440  }
441 
442  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
448  private function _server_authenticate()
449  {
450  // phpcs:enable
451  global $conf;
452 
453  // Send the RFC2554 specified EHLO.
454  // This improvment as provided by 'SirSir' to
455  // accomodate both SMTP AND ESMTP capable servers
456  $host = $this->getHost();
457  $usetls = preg_match('@tls://@i', $host);
458 
459  $host = preg_replace('@tcp://@i', '', $host); // Remove prefix
460  $host = preg_replace('@ssl://@i', '', $host); // Remove prefix
461  $host = preg_replace('@tls://@i', '', $host); // Remove prefix
462 
463  if ($usetls && !empty($conf->global->MAIN_SMTPS_ADD_TLS_TO_HOST_FOR_HELO)) {
464  $host = 'tls://'.$host;
465  }
466 
467  $hosth = $host; // so for example 'localhost' or 'smtp-relay.gmail.com'
468 
469  if (!empty($conf->global->MAIL_SMTP_USE_FROM_FOR_HELO)) {
470  if (!is_numeric($conf->global->MAIL_SMTP_USE_FROM_FOR_HELO)) {
471  // If value of MAIL_SMTP_USE_FROM_FOR_HELO is a string, we use it as domain name
472  $hosth = $conf->global->MAIL_SMTP_USE_FROM_FOR_HELO;
473  } else {
474  // If value of MAIL_SMTP_USE_FROM_FOR_HELO is 1, we use the domain in the from.
475  // So if the from to is 'aaa <bbb@ccc.com>', we will keep 'ccc.com'
476  $hosth = $this->getFrom('addr');
477  $hosth = preg_replace('/^.*</', '', $hosth);
478  $hosth = preg_replace('/>.*$/', '', $hosth);
479  $hosth = preg_replace('/.*@/', '', $hosth);
480  }
481  }
482 
483  if ($_retVal = $this->socket_send_str('EHLO '.$hosth, '250')) {
484  if ($usetls) {
485  /*
486  The following dialog illustrates how a client and server can start a TLS STARTTLS session:
487  S: <waits for connection on TCP port 25>
488  C: <opens connection>
489  S: 220 mail.imc.org SMTP service ready
490  C: EHLO mail.ietf.org
491  S: 250-mail.imc.org offers a warm hug of welcome
492  S: 250 STARTTLS
493  C: STARTTLS
494  S: 220 Go ahead
495  C: <starts TLS negotiation>
496  C & S: <negotiate a TLS session>
497  C & S: <check result of negotiation>
498  // Second pass EHLO
499  C: EHLO client-domain.com
500  S: 250-server-domain.com
501  S: 250 AUTH LOGIN
502  C: <continues by sending an SMTP command
503 
504  Another example here:
505  S: 220 smtp.server.com Simple Mail Transfer Service Ready
506  C: EHLO client.example.com
507  S: 250-smtp.server.com Hello client.example.com
508  S: 250-SIZE 1000000
509  S: 250-AUTH LOGIN PLAIN CRAM-MD5
510  S: 250-STARTTLS
511  S: 250 HELP
512  C: STARTTLS
513  S: 220 TLS go ahead
514  C: EHLO client.example.com *
515  S: 250-smtp.server.com Hello client.example.com
516  S: 250-SIZE 1000000
517  S: 250-AUTH LOGIN PLAIN CRAM-MD5
518  S: 250 HELP
519  C: AUTH LOGIN
520  S: 334 VXNlcm5hbWU6
521  C: adlxdkej
522  S: 334 UGFzc3dvcmQ6
523  C: lkujsefxlj
524  S: 235 2.7.0 Authentication successful
525  C: MAIL FROM:<mail@samlogic.com>
526  S: 250 OK
527  C: RCPT TO:<john@mail.com>
528  S: 250 OK
529  C: DATA
530  S: 354 Send message, end with a "." on a line by itself
531  C: <The message data (body text, subject, e-mail header, attachments etc) is sent>
532  S .
533  S: 250 OK, message accepted for delivery: queued as 12345
534  C: QUIT
535  S: 221 Bye
536  */
537  if (!$_retVal = $this->socket_send_str('STARTTLS', 220)) {
538  $this->_setErr(131, 'STARTTLS connection is not supported.');
539  return $_retVal;
540  }
541 
542  // Before 5.6.7:
543  // STREAM_CRYPTO_METHOD_SSLv23_CLIENT = STREAM_CRYPTO_METHOD_SSLv2_CLIENT|STREAM_CRYPTO_METHOD_SSLv3_CLIENT
544  // STREAM_CRYPTO_METHOD_TLS_CLIENT = STREAM_CRYPTO_METHOD_TLSv1_0_CLIENT|STREAM_CRYPTO_METHOD_TLSv1_1_CLIENT|STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT
545  // PHP >= 5.6.7:
546  // STREAM_CRYPTO_METHOD_SSLv23_CLIENT = STREAM_CRYPTO_METHOD_TLSv1_0_CLIENT|STREAM_CRYPTO_METHOD_TLSv1_1_CLIENT|STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT
547  // STREAM_CRYPTO_METHOD_TLS_CLIENT = STREAM_CRYPTO_METHOD_TLSv1_0_CLIENT
548 
549  $crypto_method = STREAM_CRYPTO_METHOD_TLS_CLIENT;
550  if (defined('STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT')) {
551  $crypto_method |= STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT;
552  $crypto_method |= STREAM_CRYPTO_METHOD_TLSv1_1_CLIENT;
553  }
554 
555  if (!stream_socket_enable_crypto($this->socket, true, $crypto_method)) {
556  $this->_setErr(132, 'STARTTLS connection failed.');
557  return $_retVal;
558  }
559  // Most servers expect a 2nd pass of EHLO after TLS is established to get another time
560  // the answer with list of supported AUTH methods. They may differs between non STARTTLS and with STARTTLS.
561  if (! $_retVal = $this->socket_send_str('EHLO '.$hosth, '250')) {
562  $this->_setErr(126, '"'.$hosth.'" does not support authenticated connections. Error after sending EHLO '.$hosth);
563  return $_retVal;
564  }
565  }
566 
567  // Default authentication method is LOGIN
568  if (empty($conf->global->MAIL_SMTP_AUTH_TYPE)) {
569  $conf->global->MAIL_SMTP_AUTH_TYPE = 'LOGIN';
570  }
571 
572  // Send Authentication to Server
573  // Check for errors along the way
574  switch ($conf->global->MAIL_SMTP_AUTH_TYPE) {
575  case 'NONE':
576  // Do not send the 'AUTH type' message. For test purpose, if you don't need authentication, it is better to not enter login/pass into setup.
577  $_retVal = true;
578  break;
579  case 'PLAIN':
580  $this->socket_send_str('AUTH PLAIN', '334');
581  // The error here just means the ID/password combo doesn't work.
582  $_retVal = $this->socket_send_str(base64_encode("\0".$this->_smtpsID."\0".$this->_smtpsPW), '235');
583  break;
584  case 'XOAUTH2':
585  // "user=$email\1auth=Bearer $token\1\1"
586  $token = 'xxx';
587  $xxxx = "user=".$this->_smtpsID."\1auth=Bearer ".$token."\1\1";
588  $_retVal = $this->socket_send_str('AUTH XOAUTH2 '.base64_encode($xxxx), '235');
589  if (!$_retVal) {
590  $this->_setErr(130, 'Error when asking for AUTH XOAUTH2');
591  }
592  break;
593  case 'LOGIN': // most common case
594  default:
595  $_retVal = $this->socket_send_str('AUTH LOGIN', '334');
596  if (!$_retVal) {
597  $this->_setErr(130, 'Error when asking for AUTH LOGIN');
598  } else {
599  // User name will not return any error, server will take anything we give it.
600  $this->socket_send_str(base64_encode($this->_smtpsID), '334');
601  // The error here just means the ID/password combo doesn't work.
602  // There is no method to determine which is the problem, ID or password
603  $_retVal = $this->socket_send_str(base64_encode($this->_smtpsPW), '235');
604  }
605  break;
606  }
607  if (!$_retVal) {
608  $this->_setErr(130, 'Invalid Authentication Credentials.');
609  }
610  } else {
611  $this->_setErr(126, '"'.$host.'" does not support authenticated connections. Error after sending EHLO '.$hosth);
612  }
613 
614  return $_retVal;
615  }
616 
622  public function sendMsg()
623  {
624  global $conf;
625 
629  $_retVal = false;
630 
631  // Connect to Server
632  if ($this->socket = $this->_server_connect()) {
633  // If a User ID *and* a password is given, assume Authentication is desired
634  if (!empty($this->_smtpsID) && !empty($this->_smtpsPW)) {
635  // Send the RFC2554 specified EHLO.
636  $_retVal = $this->_server_authenticate();
637  } else {
638  // This is a "normal" SMTP Server "handshack"
639  // Send the RFC821 specified HELO.
640  $host = $this->getHost();
641  $usetls = preg_match('@tls://@i', $host);
642 
643  $host = preg_replace('@tcp://@i', '', $host); // Remove prefix
644  $host = preg_replace('@ssl://@i', '', $host); // Remove prefix
645  $host = preg_replace('@tls://@i', '', $host); // Remove prefix
646 
647  if ($usetls && !empty($conf->global->MAIN_SMTPS_ADD_TLS_TO_HOST_FOR_HELO)) {
648  $host = 'tls://'.$host;
649  }
650 
651  $hosth = $host;
652 
653  if (!empty($conf->global->MAIL_SMTP_USE_FROM_FOR_HELO)) {
654  if (!is_numeric($conf->global->MAIL_SMTP_USE_FROM_FOR_HELO)) {
655  // If value of MAIL_SMTP_USE_FROM_FOR_HELO is a string, we use it as domain name
656  $hosth = $conf->global->MAIL_SMTP_USE_FROM_FOR_HELO;
657  } else {
658  // If value of MAIL_SMTP_USE_FROM_FOR_HELO is 1, we use the domain in the from.
659  // If the from to is 'aaa <bbb@ccc.com>', we will keep 'ccc.com'
660  $hosth = $this->getFrom('addr');
661  $hosth = preg_replace('/^.*</', '', $hosth);
662  $hosth = preg_replace('/>.*$/', '', $hosth);
663  $hosth = preg_replace('/.*@/', '', $hosth);
664  }
665  }
666 
667  $_retVal = $this->socket_send_str('HELO '.$hosth, '250');
668  }
669 
670  // Well, did we get to the server?
671  if ($_retVal) {
672  // From this point onward most server response codes should be 250
673  // Specify who the mail is from....
674  // This has to be the raw email address, strip the "name" off
675  $resultmailfrom = $this->socket_send_str('MAIL FROM: '.$this->getFrom('addr'), '250');
676  if (!$resultmailfrom) {
677  fclose($this->socket);
678  return false;
679  }
680 
681  // 'RCPT TO:' must be given a single address, so this has to loop
682  // through the list of addresses, regardless of TO, CC or BCC
683  // and send it out "single file"
684  foreach ($this->get_RCPT_list() as $_address) {
685  /* Note:
686  * BCC email addresses must be listed in the RCPT TO command list,
687  * but the BCC header should not be printed under the DATA command.
688  * http://stackoverflow.com/questions/2750211/sending-bcc-emails-using-a-smtp-server
689  */
690 
691  /*
692  * TODO
693  * After each 'RCPT TO:' is sent, we need to make sure it was kosher,
694  * if not, the whole message will fail
695  * If any email address fails, we will need to RESET the connection,
696  * mark the last address as "bad" and start the address loop over again.
697  * If any address fails, the entire message fails.
698  */
699  $this->socket_send_str('RCPT TO: <'.$_address.'>', '250');
700  }
701 
702  // Tell the server we are ready to start sending data
703  // with any custom headers...
704  // This is the last response code we look for until the end of the message.
705  $this->socket_send_str('DATA', '354');
706 
707  // Now we are ready for the message...
708  // Ok, all the ingredients are mixed in let's cook this puppy...
709  $this->socket_send_str($this->getHeader().$this->getBodyContent()."\r\n".'.', '250');
710 
711  // Now tell the server we are done and close the socket...
712  fputs($this->socket, 'QUIT');
713  fclose($this->socket);
714  }
715  }
716 
717  return $_retVal;
718  }
719 
720  // =============================================================
721  // ** Setter & Getter methods
722 
723  // ** Basic System configuration
724 
750  public function setConfig($_strConfigPath = null)
751  {
756  $_retVal = true;
757 
758  // if we have a path...
759  if (!empty($_strConfigPath)) {
760  // If the path is not valid, this will NOT generate an error,
761  // it will simply return false.
762  if (!@include $_strConfigPath) {
763  $this->_setErr(110, '"'.$_strConfigPath.'" is not a valid path.');
764  $_retVal = false;
765  }
766  } else {
767  // Read the Systems php.ini file
768  // Set these properties ONLY if they are set in the php.ini file.
769  // Otherwise the default values will be used.
770  if ($_host = ini_get('SMTPs')) {
771  $this->setHost($_host);
772  }
773 
774  if ($_port = ini_get('smtp_port')) {
775  $this->setPort($_port);
776  }
777 
778  if ($_from = ini_get('sendmail_from')) {
779  $this->setFrom($_from);
780  }
781  }
782 
783  // Send back what we have
784  return $_retVal;
785  }
786 
796  public function setTransportType($_type = 0)
797  {
798  if ((is_numeric($_type)) && (($_type >= 0) && ($_type <= 3))) {
799  $this->_transportType = $_type;
800  }
801  }
802 
811  public function getTransportType()
812  {
813  return $this->_transportType;
814  }
815 
823  public function setMailPath($_path)
824  {
825  // This feature is not yet implemented
826  return true;
827 
828  //if ( $_path ) $this->_mailPath = $_path;
829  }
830 
839  public function setHost($_strHost)
840  {
841  if ($_strHost) {
842  $this->_smtpsHost = $_strHost;
843  }
844  }
845 
852  public function getHost()
853  {
854  return $this->_smtpsHost;
855  }
856 
865  public function setPort($_intPort)
866  {
867  if ((is_numeric($_intPort)) &&
868  (($_intPort >= 1) && ($_intPort <= 65536))) {
869  $this->_smtpsPort = $_intPort;
870  }
871  }
872 
879  public function getPort()
880  {
881  return $this->_smtpsPort;
882  }
883 
890  public function setID($_strID)
891  {
892  $this->_smtpsID = $_strID;
893  }
894 
900  public function getID()
901  {
902  return $this->_smtpsID;
903  }
904 
911  public function setPW($_strPW)
912  {
913  $this->_smtpsPW = $_strPW;
914  }
915 
921  public function getPW()
922  {
923  return $this->_smtpsPW;
924  }
925 
933  public function setCharSet($_strCharSet)
934  {
935  if ($_strCharSet) {
936  $this->_smtpsCharSet = $_strCharSet;
937  }
938  }
939 
945  public function getCharSet()
946  {
947  return $this->_smtpsCharSet;
948  }
949 
965  public function setTransEncode($_strTransEncode)
966  {
967  if (array_search($_strTransEncode, $this->_smtpsTransEncodeTypes)) {
968  $this->_smtpsTransEncode = $_strTransEncode;
969  }
970  }
971 
977  public function getTransEncode()
978  {
980  }
981 
998  public function setTransEncodeType($_strTransEncodeType)
999  {
1000  if (array_search($_strTransEncodeType, $this->_smtpsTransEncodeTypes)) {
1001  $this->_smtpsTransEncodeType = $_strTransEncodeType;
1002  }
1003  }
1004 
1010  public function getTransEncodeType()
1011  {
1012  return $this->_smtpsTransEncodeTypes[$this->_smtpsTransEncodeType];
1013  }
1014 
1015 
1016  // ** Message Construction
1017 
1024  public function setFrom($_strFrom)
1025  {
1026  if ($_strFrom) {
1027  $this->_msgFrom = $this->_strip_email($_strFrom);
1028  }
1029  }
1030 
1037  public function getFrom($_part = true)
1038  {
1039  $_retValue = '';
1040 
1041  if ($_part === true) {
1042  $_retValue = $this->_msgFrom;
1043  } else {
1044  $_retValue = $this->_msgFrom[$_part];
1045  }
1046 
1047  return $_retValue;
1048  }
1049 
1056  public function setReplyTo($_strReplyTo)
1057  {
1058  if ($_strReplyTo) {
1059  $this->_msgReplyTo = $this->_strip_email($_strReplyTo);
1060  }
1061  }
1062 
1069  public function getReplyTo($_part = true)
1070  {
1071  $_retValue = '';
1072 
1073  if ($_part === true) {
1074  $_retValue = $this->_msgReplyTo;
1075  } else {
1076  $_retValue = $this->_msgReplyTo[$_part];
1077  }
1078 
1079  return $_retValue;
1080  }
1081 
1094  private function _buildAddrList($_type, $_addrList)
1095  {
1096  // Pull existing list
1097  $aryHost = $this->_msgRecipients;
1098 
1099  // Only run this if we have something
1100  if (!empty($_addrList)) {
1101  // $_addrList can be a STRING or an array
1102  if (is_string($_addrList)) {
1103  // This could be a COMMA delimited string
1104  if (strstr($_addrList, ',')) {
1105  // "explode "list" into an array
1106  $_addrList = explode(',', $_addrList);
1107  } else {
1108  // Stick it in an array
1109  $_addrList = array($_addrList);
1110  }
1111  }
1112 
1113  // take the array of addresses and split them further
1114  foreach ($_addrList as $_strAddr) {
1115  // Strip off the end '>'
1116  $_strAddr = str_replace('>', '', $_strAddr);
1117 
1118  // Seperate "Real Name" from eMail address
1119  $_tmpaddr = null;
1120  $_tmpaddr = explode('<', $_strAddr);
1121 
1122  // We have a "Real Name" and eMail address
1123  if (count($_tmpaddr) == 2) {
1124  $_tmpHost = explode('@', $_tmpaddr[1]);
1125  $_tmpaddr[0] = trim($_tmpaddr[0], ' ">');
1126  $aryHost[$_tmpHost[1]][$_type][$_tmpHost[0]] = $_tmpaddr[0];
1127  } else {
1128  // We only have an eMail address
1129  // Strip off the beggining '<'
1130  $_strAddr = str_replace('<', '', $_strAddr);
1131 
1132  $_tmpHost = explode('@', $_strAddr);
1133  $_tmpHost[0] = trim($_tmpHost[0]);
1134  $_tmpHost[1] = trim($_tmpHost[1]);
1135 
1136  $aryHost[$_tmpHost[1]][$_type][$_tmpHost[0]] = '';
1137  }
1138  }
1139  }
1140  // replace list
1141  $this->_msgRecipients = $aryHost;
1142  }
1143 
1144  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1161  private function _strip_email($_strAddr)
1162  {
1163  // phpcs:enable
1164  // Keep the orginal
1165  $_aryEmail['org'] = $_strAddr;
1166 
1167  // Set entire string to Lower Case
1168  $_strAddr = strtolower($_strAddr);
1169 
1170  // Drop "stuff' off the end
1171  $_strAddr = trim($_strAddr, ' ">');
1172 
1173  // Seperate "Real Name" from eMail address, if we have one
1174  $_tmpAry = explode('<', $_strAddr);
1175 
1176  // Do we have a "Real name"
1177  if (count($_tmpAry) == 2) {
1178  // We may not really have a "Real Name"
1179  if ($_tmpAry[0]) {
1180  $_aryEmail['real'] = trim($_tmpAry[0], ' ">');
1181  }
1182 
1183  $_aryEmail['addr'] = $_tmpAry[1];
1184  } else {
1185  $_aryEmail['addr'] = $_tmpAry[0];
1186  }
1187 
1188  // Pull User Name and Host.tld apart
1189  list($_aryEmail['user'], $_aryEmail['host']) = explode('@', $_aryEmail['addr']);
1190 
1191  // Put the brackets back around the address
1192  $_aryEmail['addr'] = '<'.$_aryEmail['addr'].'>';
1193 
1194  return $_aryEmail;
1195  }
1196 
1197  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1205  public function get_RCPT_list()
1206  {
1207  // phpcs:enable
1211  $_RCPT_list = array();
1212 
1213  // walk down Recipients array and pull just email addresses
1214  foreach ($this->_msgRecipients as $_host => $_list) {
1215  foreach ($_list as $_subList) {
1216  foreach ($_subList as $_name => $_addr) {
1217  // build RCPT list
1218  $_RCPT_list[] = $_name.'@'.$_host;
1219  }
1220  }
1221  }
1222 
1223  return $_RCPT_list;
1224  }
1225 
1226  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1233  public function get_email_list($_which = null)
1234  {
1235  // phpcs:enable
1236  // We need to know which address segment to pull
1237  if ($_which) {
1238  // Make sure we have addresses to process
1239  if ($this->_msgRecipients) {
1240  $_RCPT_list = array();
1241  // walk down Recipients array and pull just email addresses
1242  foreach ($this->_msgRecipients as $_host => $_list) {
1243  if ($this->_msgRecipients[$_host][$_which]) {
1244  foreach ($this->_msgRecipients[$_host][$_which] as $_addr => $_realName) {
1245  if ($_realName) { // @CHANGE LDR
1246  $_realName = '"'.$_realName.'"';
1247  $_RCPT_list[] = $_realName.' <'.$_addr.'@'.$_host.'>';
1248  } else {
1249  $_RCPT_list[] = $_addr.'@'.$_host;
1250  }
1251  }
1252  }
1253  }
1254 
1255  return implode(', ', $_RCPT_list);
1256  } else {
1257  $this->_setErr(101, 'No eMail Address for message to be sent to.');
1258  return false;
1259  }
1260  } else {
1261  $this->_setErr(102, 'eMail type not defined.');
1262  return false;
1263  }
1264  }
1265 
1272  public function setTO($_addrTo)
1273  {
1274  if ($_addrTo) {
1275  $this->_buildAddrList('to', $_addrTo);
1276  }
1277  }
1278 
1284  public function getTo()
1285  {
1286  return $this->get_email_list('to');
1287  }
1288 
1295  public function setCC($_strCC)
1296  {
1297  if ($_strCC) {
1298  $this->_buildAddrList('cc', $_strCC);
1299  }
1300  }
1301 
1307  public function getCC()
1308  {
1309  return $this->get_email_list('cc');
1310  }
1311 
1318  public function setBCC($_strBCC)
1319  {
1320  if ($_strBCC) {
1321  $this->_buildAddrList('bcc', $_strBCC);
1322  }
1323  }
1324 
1330  public function getBCC()
1331  {
1332  return $this->get_email_list('bcc');
1333  }
1334 
1341  public function setSubject($_strSubject = '')
1342  {
1343  if ($_strSubject) {
1344  $this->_msgSubject = $_strSubject;
1345  }
1346  }
1347 
1353  public function getSubject()
1354  {
1355  return $this->_msgSubject;
1356  }
1357 
1363  public function getHeader()
1364  {
1365  global $conf;
1366 
1367  $_header = 'From: '.$this->getFrom('org')."\r\n"
1368  . 'To: '.$this->getTO()."\r\n";
1369 
1370  if ($this->getCC()) {
1371  $_header .= 'Cc: '.$this->getCC()."\r\n";
1372  }
1373 
1374  /* Note:
1375  * BCC email addresses must be listed in the RCPT TO command list,
1376  * but the BCC header should not be printed under the DATA command.
1377  * So it is included into the function sendMsg() but not here.
1378  * http://stackoverflow.com/questions/2750211/sending-bcc-emails-using-a-smtp-server
1379  */
1380  /*
1381  if ( $this->getBCC() )
1382  $_header .= 'Bcc: ' . $this->getBCC() . "\r\n";
1383  */
1384 
1385  $host = dol_getprefix('email');
1386 
1387  //NOTE: Message-ID should probably contain the username of the user who sent the msg
1388  $_header .= 'Subject: '.$this->getSubject()."\r\n";
1389  $_header .= 'Date: '.date("r")."\r\n";
1390 
1391  $trackid = $this->getTrackId();
1392  if ($trackid) {
1393  // References is kept in response and Message-ID is returned into In-Reply-To:
1394  $_header .= 'Message-ID: <'.time().'.SMTPs-dolibarr-'.$trackid.'@'.$host.">\r\n";
1395  $_header .= 'References: <'.time().'.SMTPs-dolibarr-'.$trackid.'@'.$host.">\r\n";
1396  $_header .= 'X-Dolibarr-TRACKID: '.$trackid.'@'.$host."\r\n";
1397  } else {
1398  $_header .= 'Message-ID: <'.time().'.SMTPs@'.$host.">\r\n";
1399  }
1400  if (!empty($_SERVER['REMOTE_ADDR'])) {
1401  $_header .= "X-RemoteAddr: ".$_SERVER['REMOTE_ADDR']."\r\n";
1402  }
1403  if ($this->getMoreInHeader()) {
1404  $_header .= $this->getMoreInHeader(); // Value must include the "\r\n";
1405  }
1406 
1407  //$_header .=
1408  // 'Read-Receipt-To: ' . $this->getFrom( 'org' ) . "\r\n"
1409  // 'Return-Receipt-To: ' . $this->getFrom( 'org' ) . "\r\n";
1410 
1411  if ($this->getSensitivity()) {
1412  $_header .= 'Sensitivity: '.$this->getSensitivity()."\r\n";
1413  }
1414 
1415  if ($this->_msgPriority != 3) {
1416  $_header .= $this->getPriority();
1417  }
1418 
1419 
1420  // @CHANGE LDR
1421  if ($this->getDeliveryReceipt()) {
1422  $_header .= 'Disposition-Notification-To: '.$this->getFrom('addr')."\r\n";
1423  }
1424  if ($this->getErrorsTo()) {
1425  $_header .= 'Errors-To: '.$this->getErrorsTo('addr')."\r\n";
1426  }
1427  if ($this->getReplyTo()) {
1428  $_header .= "Reply-To: ".$this->getReplyTo('addr')."\r\n";
1429  }
1430 
1431  $_header .= 'X-Mailer: Dolibarr version '.DOL_VERSION.' (using SMTPs Mailer)'."\r\n";
1432  $_header .= 'X-Dolibarr-Option: '.($conf->global->MAIN_MAIL_USE_MULTI_PART ? 'MAIN_MAIL_USE_MULTI_PART' : 'No MAIN_MAIL_USE_MULTI_PART')."\r\n";
1433  $_header .= 'Mime-Version: 1.0'."\r\n";
1434 
1435 
1436  return $_header;
1437  }
1438 
1446  public function setBodyContent($strContent, $strType = 'plain')
1447  {
1448  //if ( $strContent )
1449  //{
1450  if ($strType == 'html') {
1451  $strMimeType = 'text/html';
1452  } else {
1453  $strMimeType = 'text/plain';
1454  }
1455 
1456  // Make RFC821 Compliant, replace bare linefeeds
1457  $strContent = preg_replace("/(?<!\r)\n/si", "\r\n", $strContent);
1458 
1459  $strContentAltText = '';
1460  if ($strType == 'html') {
1461  // Similar code to forge a text from html is also in CMailFile.class.php
1462  $strContentAltText = preg_replace('/<head><title>.*<\/style><\/head>/', '', $strContent);
1463  $strContentAltText = preg_replace("/<br\s*[^>]*>/", " ", $strContentAltText);
1464  $strContentAltText = html_entity_decode(strip_tags($strContentAltText));
1465  $strContentAltText = trim(wordwrap($strContentAltText, 75, "\r\n"));
1466  }
1467 
1468  // Make RFC2045 Compliant
1469  //$strContent = rtrim(chunk_split($strContent)); // Function chunck_split seems ko if not used on a base64 content
1470  $strContent = rtrim(wordwrap($strContent, 75, "\r\n")); // TODO Using this method creates unexpected line break on text/plain content.
1471 
1472  $this->_msgContent[$strType] = array();
1473 
1474  $this->_msgContent[$strType]['mimeType'] = $strMimeType;
1475  $this->_msgContent[$strType]['data'] = $strContent;
1476  $this->_msgContent[$strType]['dataText'] = $strContentAltText;
1477 
1478  if ($this->getMD5flag()) {
1479  $this->_msgContent[$strType]['md5'] = dol_hash($strContent, 3);
1480  }
1481  //}
1482  }
1483 
1489  public function getBodyContent()
1490  {
1491  global $conf;
1492 
1493  // Generate a new Boundary string
1494  $this->_setBoundary();
1495 
1496  // What type[s] of content do we have
1497  $_types = array_keys($this->_msgContent);
1498 
1499  // How many content types do we have
1500  $keyCount = count($_types);
1501 
1502  // If we have ZERO, we have a problem
1503  if ($keyCount === 0) {
1504  die("Sorry, no content");
1505  } elseif ($keyCount === 1 && empty($conf->global->MAIN_MAIL_USE_MULTI_PART)) {
1506  // If we have ONE, we can use the simple format
1507  $_msgData = $this->_msgContent;
1508  $_msgData = $_msgData[$_types[0]];
1509 
1510  $content = 'Content-Type: '.$_msgData['mimeType'].'; charset="'.$this->getCharSet().'"'."\r\n"
1511  . 'Content-Transfer-Encoding: '.$this->getTransEncodeType()."\r\n"
1512  . 'Content-Disposition: inline'."\r\n"
1513  . 'Content-Description: Message'."\r\n";
1514 
1515  if ($this->getMD5flag()) {
1516  $content .= 'Content-MD5: '.$_msgData['md5']."\r\n";
1517  }
1518 
1519  $content .= "\r\n"
1520  . $_msgData['data']."\r\n";
1521  } elseif ($keyCount >= 1 || !empty($conf->global->MAIN_MAIL_USE_MULTI_PART)) {
1522  // If we have more than ONE, we use the multi-part format
1523  // Since this is an actual multi-part message
1524  // We need to define a content message Boundary
1525  // NOTE: This was 'multipart/alternative', but Windows based mail servers have issues with this.
1526 
1527  //$content = 'Content-Type: multipart/related; boundary="' . $this->_getBoundary() . '"' . "\r\n";
1528  $content = 'Content-Type: multipart/mixed; boundary="'.$this->_getBoundary('mixed').'"'."\r\n";
1529 
1530  // . "\r\n"
1531  // . 'This is a multi-part message in MIME format.' . "\r\n";
1532  $content .= "Content-Transfer-Encoding: 8bit\r\n";
1533  $content .= "\r\n";
1534 
1535  $content .= "--".$this->_getBoundary('mixed')."\r\n";
1536 
1537  if (key_exists('image', $this->_msgContent)) { // If inline image found
1538  $content .= 'Content-Type: multipart/alternative; boundary="'.$this->_getBoundary('alternative').'"'."\r\n";
1539  $content .= "\r\n";
1540  $content .= "--".$this->_getBoundary('alternative')."\r\n";
1541  }
1542 
1543 
1544  // $this->_msgContent must be sorted with key 'text' or 'html' first then 'image' then 'attachment'
1545 
1546 
1547  // Loop through message content array
1548  foreach ($this->_msgContent as $type => $_content) {
1549  if ($type == 'attachment') {
1550  // loop through all attachments
1551  foreach ($_content as $_file => $_data) {
1552  $content .= "--".$this->_getBoundary('mixed')."\r\n"
1553  . 'Content-Disposition: attachment; filename="'.$_data['fileName'].'"'."\r\n"
1554  . 'Content-Type: '.$_data['mimeType'].'; name="'.$_data['fileName'].'"'."\r\n"
1555  . 'Content-Transfer-Encoding: base64'."\r\n"
1556  . 'Content-Description: '.$_data['fileName']."\r\n";
1557 
1558  if ($this->getMD5flag()) {
1559  $content .= 'Content-MD5: '.$_data['md5']."\r\n";
1560  }
1561 
1562  $content .= "\r\n".$_data['data']."\r\n\r\n";
1563  }
1564  } elseif ($type == 'image') {
1565  // @CHANGE LDR
1566  // loop through all images
1567  foreach ($_content as $_image => $_data) {
1568  $content .= "--".$this->_getBoundary('related')."\r\n"; // always related for an inline image
1569 
1570  $content .= 'Content-Type: '.$_data['mimeType'].'; name="'.$_data['imageName'].'"'."\r\n"
1571  . 'Content-Transfer-Encoding: base64'."\r\n"
1572  . 'Content-Disposition: inline; filename="'.$_data['imageName'].'"'."\r\n"
1573  . 'Content-ID: <'.$_data['cid'].'> '."\r\n";
1574 
1575  if ($this->getMD5flag()) {
1576  $content .= 'Content-MD5: '.$_data['md5']."\r\n";
1577  }
1578 
1579  $content .= "\r\n"
1580  . $_data['data']."\r\n";
1581  }
1582 
1583  // always end related and end alternative after inline images
1584  $content .= "--".$this->_getBoundary('related')."--\r\n";
1585  $content .= "\r\n--".$this->_getBoundary('alternative')."--\r\n";
1586  $content .= "\r\n";
1587  } else {
1588  if (key_exists('image', $this->_msgContent)) {
1589  $content .= "Content-Type: text/plain; charset=".$this->getCharSet()."\r\n";
1590  $content .= "\r\n".($_content['dataText'] ? $_content['dataText'] : strip_tags($_content['data']))."\r\n"; // Add plain text message
1591  $content .= "--".$this->_getBoundary('alternative')."\r\n";
1592  $content .= 'Content-Type: multipart/related; boundary="'.$this->_getBoundary('related').'"'."\r\n";
1593  $content .= "\r\n";
1594  $content .= "--".$this->_getBoundary('related')."\r\n";
1595  }
1596 
1597  if (!key_exists('image', $this->_msgContent) && $_content['dataText'] && !empty($conf->global->MAIN_MAIL_USE_MULTI_PART)) {
1598  // Add plain text message part before html part
1599  $content .= 'Content-Type: multipart/alternative; boundary="'.$this->_getBoundary('alternative').'"'."\r\n";
1600  $content .= "\r\n";
1601  $content .= "--".$this->_getBoundary('alternative')."\r\n";
1602 
1603  $content .= "Content-Type: text/plain; charset=".$this->getCharSet()."\r\n";
1604  $content .= "\r\n".$_content['dataText']."\r\n";
1605  $content .= "--".$this->_getBoundary('alternative')."\r\n";
1606  }
1607 
1608  $content .= 'Content-Type: '.$_content['mimeType'].'; charset='.$this->getCharSet();
1609 
1610  $content .= "\r\n";
1611 
1612  if ($this->getMD5flag()) {
1613  $content .= 'Content-MD5: '.$_content['md5']."\r\n";
1614  }
1615 
1616  $content .= "\r\n".$_content['data']."\r\n";
1617 
1618  if (!key_exists('image', $this->_msgContent) && $_content['dataText'] && !empty($conf->global->MAIN_MAIL_USE_MULTI_PART)) {
1619  // Add plain text message part after html part
1620  $content .= "--".$this->_getBoundary('alternative')."--\r\n";
1621  }
1622 
1623  $content .= "\r\n";
1624  }
1625  }
1626 
1627  $content .= "--".$this->_getBoundary('mixed').'--'."\r\n";
1628  }
1629 
1630  return $content;
1631  }
1632 
1642  public function setAttachment($strContent, $strFileName = 'unknown', $strMimeType = 'unknown')
1643  {
1644  if ($strContent) {
1645  $strContent = rtrim(chunk_split(base64_encode($strContent), 76, "\r\n")); // 76 max is defined into http://tools.ietf.org/html/rfc2047
1646 
1647  $this->_msgContent['attachment'][$strFileName]['mimeType'] = $strMimeType;
1648  $this->_msgContent['attachment'][$strFileName]['fileName'] = $strFileName;
1649  $this->_msgContent['attachment'][$strFileName]['data'] = $strContent;
1650 
1651  if ($this->getMD5flag()) {
1652  $this->_msgContent['attachment'][$strFileName]['md5'] = dol_hash($strContent, 3);
1653  }
1654  }
1655  }
1656 
1657 
1658  // @CHANGE LDR
1659 
1670  public function setImageInline($strContent, $strImageName = 'unknown', $strMimeType = 'unknown', $strImageCid = 'unknown')
1671  {
1672  if ($strContent) {
1673  $this->_msgContent['image'][$strImageName]['mimeType'] = $strMimeType;
1674  $this->_msgContent['image'][$strImageName]['imageName'] = $strImageName;
1675  $this->_msgContent['image'][$strImageName]['cid'] = $strImageCid;
1676  $this->_msgContent['image'][$strImageName]['data'] = $strContent;
1677 
1678  if ($this->getMD5flag()) {
1679  $this->_msgContent['image'][$strImageName]['md5'] = dol_hash($strContent, 3);
1680  }
1681  }
1682  }
1683  // END @CHANGE LDR
1684 
1685 
1697  public function setSensitivity($_value = 0)
1698  {
1699  if ((is_numeric($_value)) &&
1700  (($_value >= 0) && ($_value <= 3))) {
1701  $this->_msgSensitivity = $_value;
1702  }
1703  }
1704 
1715  public function getSensitivity()
1716  {
1717  return $this->_arySensitivity[$this->_msgSensitivity];
1718  }
1719 
1733  public function setPriority($_value = 3)
1734  {
1735  if ((is_numeric($_value)) &&
1736  (($_value >= 0) && ($_value <= 5))) {
1737  $this->_msgPriority = $_value;
1738  }
1739  }
1740 
1753  public function getPriority()
1754  {
1755  return 'Importance: '.$this->_aryPriority[$this->_msgPriority]."\r\n"
1756  . 'Priority: '.$this->_aryPriority[$this->_msgPriority]."\r\n"
1757  . 'X-Priority: '.$this->_msgPriority.' ('.$this->_aryPriority[$this->_msgPriority].')'."\r\n";
1758  }
1759 
1766  public function setMD5flag($_flag = false)
1767  {
1768  $this->_smtpMD5 = $_flag;
1769  }
1770 
1776  public function getMD5flag()
1777  {
1778  return $this->_smtpMD5;
1779  }
1780 
1789  public function setXheader($strXdata)
1790  {
1791  if ($strXdata) {
1792  $this->_msgXheader[] = $strXdata;
1793  }
1794  }
1795 
1801  public function getXheader()
1802  {
1803  return $this->_msgXheader;
1804  }
1805 
1811  private function _setBoundary()
1812  {
1813  $this->_smtpsBoundary = "multipart_x.".time().".x_boundary";
1814  $this->_smtpsRelatedBoundary = 'mul_'.dol_hash(uniqid("dolibarr2"), 3);
1815  $this->_smtpsAlternativeBoundary = 'mul_'.dol_hash(uniqid("dolibarr3"), 3);
1816  }
1817 
1824  private function _getBoundary($type = 'mixed')
1825  {
1826  if ($type == 'mixed') {
1827  return $this->_smtpsBoundary;
1828  } elseif ($type == 'related') {
1830  } elseif ($type == 'alternative') {
1832  }
1833  }
1834 
1835  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1844  public function server_parse($socket, $response)
1845  {
1846  // phpcs:enable
1851  $_retVal = true;
1852 
1853  $server_response = '';
1854 
1855  // avoid infinite loop
1856  $limit = 0;
1857 
1858  while (substr($server_response, 3, 1) != ' ' && $limit < 100) {
1859  if (!($server_response = fgets($socket, 256))) {
1860  $this->_setErr(121, "Couldn't get mail server response codes");
1861  $_retVal = false;
1862  break;
1863  }
1864  $this->log .= $server_response;
1865  $limit++;
1866  }
1867 
1868  if (!(substr($server_response, 0, 3) == $response)) {
1869  $this->_setErr(120, "Ran into problems sending Mail.\r\nResponse: $server_response");
1870  $_retVal = false;
1871  }
1872 
1873  return $_retVal;
1874  }
1875 
1876  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1885  public function socket_send_str($_strSend, $_returnCode = null, $CRLF = "\r\n")
1886  {
1887  // phpcs:enable
1888  if ($this->_debug) {
1889  $this->log .= $_strSend; // @CHANGE LDR for log
1890  }
1891  fputs($this->socket, $_strSend.$CRLF);
1892  if ($this->_debug) {
1893  $this->log .= ' ('.$_returnCode.')'.$CRLF;
1894  }
1895 
1896  if ($_returnCode) {
1897  return $this->server_parse($this->socket, $_returnCode);
1898  }
1899  }
1900 
1901  // =============================================================
1902  // ** Error handling methods
1903 
1911  private function _setErr($_errNum, $_errMsg)
1912  {
1913  $this->_smtpsErrors[] = array(
1914  'num' => $_errNum,
1915  'msg' => $_errMsg,
1916  );
1917  }
1918 
1924  public function getErrors()
1925  {
1926  $_errMsg = array();
1927 
1928  if (is_array($this->_smtpsErrors)) {
1929  foreach ($this->_smtpsErrors as $_err => $_info) {
1930  $_errMsg[] = 'Error ['.$_info['num'].']: '.$_info['msg'];
1931  }
1932  }
1933 
1934  return implode("\n", $_errMsg);
1935  }
1936 }
1937 
1938 
1939 // =============================================================
1940 // ** CSV Version Control Info
1941 
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.
setOptions($_options=array())
Set delivery receipt.
_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;.
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.
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.