PageRenderTime 79ms CodeModel.GetById 26ms RepoModel.GetById 2ms app.codeStats 0ms

/htdocs/core/class/smtps.class.php

https://github.com/asterix14/dolibarr
PHP | 1755 lines | 879 code | 192 blank | 684 comment | 90 complexity | b9bd8a273da5d988840dbe916960bd73 MD5 | raw file
Possible License(s): LGPL-2.0

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /**
  3. * \file htdocs/core/class/smtps.class.php
  4. * \brief File of class to manage SMTPS email sending
  5. *
  6. * Class to construct and send SMTP compliant email, even to a secure
  7. * SMTP server, regardless of platform.
  8. *
  9. * Goals:
  10. * - mime compliant
  11. * - multiple Reciptiants
  12. * - TO
  13. * - CC
  14. * - BCC
  15. * - multi-part message
  16. * - plain text
  17. * - HTML
  18. * - inline attachments
  19. * - attachments
  20. * - GPG access
  21. *
  22. * This Class is based off of 'SMTP PHP MAIL' by Dirk Paehl, http://www.paehl.de
  23. *
  24. * @author Walter Torres <walter@torres.ws> [with a *lot* of help!]
  25. * @author Laurent Destailleur <eldy@users.sourceforge.net>
  26. * @author Regis Houssin
  27. *
  28. * @license GNU General Public Licence
  29. */
  30. /**
  31. * Version number of Class
  32. */
  33. define('SMTPs_VER', '1.16', false);
  34. /**
  35. * SMTPs Success value
  36. */
  37. define('SMTPs_SUCCEED', true, false);
  38. /**
  39. * SMTPs Fail value
  40. */
  41. define('SMTPs_FAIL', false, false);
  42. /**
  43. * Improper parameters
  44. */
  45. define('SMTPs_INVALID_PARAMETERS', 50, false);
  46. /**
  47. * \class SMTPs
  48. * \brief Class to construct and send SMTP compliant email, even
  49. * to a secure SMTP server, regardless of platform.
  50. */
  51. class SMTPs
  52. {
  53. /**
  54. * Host Name or IP of SMTP Server to use
  55. */
  56. var $_smtpsHost = 'localhost';
  57. /**
  58. * SMTP Server Port definition. 25 is default value
  59. * This can be defined via a INI file or via a setter method
  60. */
  61. var $_smtpsPort = '25';
  62. /**
  63. * Secure SMTP Server access ID
  64. * This can be defined via a INI file or via a setter method
  65. */
  66. var $_smtpsID = null;
  67. /**
  68. * Secure SMTP Server access Password
  69. * This can be defined via a INI file or via a setter method
  70. */
  71. var $_smtpsPW = null;
  72. /**
  73. * Who sent the Message
  74. * This can be defined via a INI file or via a setter method
  75. */
  76. var $_msgFrom = null;
  77. /**
  78. * Where are replies and errors to be sent to
  79. * This can be defined via a INI file or via a setter method
  80. */
  81. var $_msgReplyTo = null;
  82. /**
  83. * Who will the Message be sent to; TO, CC, BCC
  84. * Multi-diminsional array containg addresses the message will
  85. * be sent TO, CC or BCC
  86. */
  87. var $_msgRecipients = null;
  88. /**
  89. * Message Subject
  90. */
  91. var $_msgSubject = null;
  92. /**
  93. * Message Content
  94. */
  95. var $_msgContent = null;
  96. /**
  97. * Custom X-Headers
  98. */
  99. var $_msgXheader = null;
  100. /**
  101. * Character set
  102. * Defaulted to 'iso-8859-1'
  103. */
  104. var $_smtpsCharSet = 'iso-8859-1';
  105. /**
  106. * Message Sensitivity
  107. * Defaults to ZERO - None
  108. */
  109. var $_msgSensitivity = 0;
  110. /**
  111. * Message Sensitivity
  112. */
  113. var $_arySensitivity = array ( false,
  114. 'Personal',
  115. 'Private',
  116. 'Company Confidential' );
  117. /**
  118. * Message Sensitivity
  119. * Defaults to 3 - Normal
  120. */
  121. var $_msgPriority = 3;
  122. /**
  123. * Message Priority
  124. */
  125. var $_aryPriority = array ( 'Bulk',
  126. 'Highest',
  127. 'High',
  128. 'Normal',
  129. 'Low',
  130. 'Lowest' );
  131. /**
  132. * Content-Transfer-Encoding
  133. * Defaulted to 0 - 7bit
  134. */
  135. var $_smtpsTransEncodeType = 0;
  136. /**
  137. * Content-Transfer-Encoding
  138. */
  139. var $_smtpsTransEncodeTypes = array( '7bit', // Simple 7-bit ASCII
  140. '8bit', // 8-bit coding with line termination characters
  141. 'base64', // 3 octets encoded into 4 sextets with offset
  142. 'binary', // Arbitrary binary stream
  143. 'mac-binhex40', // Macintosh binary to hex encoding
  144. 'quoted-printable', // Mostly 7-bit, with 8-bit characters encoded as "=HH"
  145. 'uuencode' ); // UUENCODE encoding
  146. /**
  147. * Content-Transfer-Encoding
  148. * Defaulted to '7bit'
  149. */
  150. var $_smtpsTransEncode = '7bit';
  151. /**
  152. * Boundary String for MIME seperation
  153. */
  154. var $_smtpsBoundary = null;
  155. /**
  156. * Determines the method inwhich the message are to be sent.
  157. * - 'sockets' [0] - conect via network to SMTP server - default
  158. * - 'pipe [1] - use UNIX path to EXE
  159. * - 'phpmail [2] - use the PHP built-in mail function
  160. * NOTE: Only 'sockets' is implemented
  161. */
  162. var $_transportType = 0;
  163. /**
  164. * If '$_transportType' is set to '1', then this variable is used
  165. * to define the UNIX file system path to the sendmail execuable
  166. */
  167. var $_mailPath = '/usr/lib/sendmail';
  168. /**
  169. * Sets the SMTP server timeout in seconds.
  170. */
  171. var $_smtpTimeout = 10;
  172. /**
  173. * Determines whether to calculate message MD5 checksum.
  174. */
  175. var $_smtpMD5 = false;
  176. /**
  177. * Class error codes and messages
  178. */
  179. var $_smtpsErrors = null;
  180. /**
  181. * Defines log level
  182. * 0 - no logging
  183. * 1 - connectivity logging
  184. * 2 - message generation logging
  185. * 3 - detail logging
  186. */
  187. var $_log_level = 0;
  188. /**
  189. * Place Class in" debug" mode
  190. */
  191. var $_debug = false;
  192. // DOL_CHANGE LDR
  193. var $log = '';
  194. var $_errorsTo = '';
  195. var $_deliveryReceipt = 0;
  196. function setDeliveryReceipt($_val = 0)
  197. {
  198. $this->_deliveryReceipt = $_val;
  199. }
  200. function getDeliveryReceipt()
  201. {
  202. return $this->_deliveryReceipt;
  203. }
  204. function setErrorsTo($_strErrorsTo)
  205. {
  206. if ( $_strErrorsTo )
  207. $this->_errorsTo = $this->_strip_email($_strErrorsTo);
  208. }
  209. function getErrorsTo ( $_part = true )
  210. {
  211. $_retValue = '';
  212. if ( $_part === true )
  213. $_retValue = $this->_errorsTo;
  214. else
  215. $_retValue = $this->_errorsTo[$_part];
  216. return $_retValue;
  217. }
  218. function setDebug( $_vDebug = false )
  219. {
  220. $this->_debug = $_vDebug;
  221. }
  222. /**
  223. * build RECIPIENT List, all addresses who will recieve this message
  224. *
  225. * @return void
  226. */
  227. function buildRCPTlist()
  228. {
  229. // Pull TO list
  230. $_aryToList = $this->getTO();
  231. }
  232. /**
  233. * Attempt a connection to mail server
  234. *
  235. * @return mixed $_retVal Boolean indicating success or failure on connection
  236. */
  237. function _server_connect()
  238. {
  239. // Default return value
  240. $_retVal = true;
  241. // We have to make sure the HOST given is valid
  242. // This is done here because '@fsockopen' will not give me this
  243. // information if it failes to connect because it can't find the HOST
  244. $host=$this->getHost();
  245. $host=preg_replace('@tcp://@i','',$host); // Remove prefix
  246. $host=preg_replace('@ssl://@i','',$host); // Remove prefix
  247. // DOL_CHANGE LDR
  248. include_once(DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php');
  249. if ( (! is_ip($host)) && ((gethostbyname ( $host )) == $host) )
  250. {
  251. $this->_setErr(99, $host . ' is either offline or is an invalid host name.');
  252. $_retVal = false;
  253. }
  254. else
  255. {
  256. //See if we can connect to the SMTP server
  257. if ( $this->socket = @fsockopen($this->getHost(), // Host to 'hit', IP or domain
  258. $this->getPort(), // which Port number to use
  259. $this->errno, // actual system level error
  260. $this->errstr, // and any text that goes with the error
  261. $this->_smtpTimeout) ) // timeout for reading/writing data over the socket
  262. {
  263. // Fix from PHP SMTP class by 'Chris Ryan'
  264. // Sometimes the SMTP server takes a little longer to respond
  265. // so we will give it a longer timeout for the first read
  266. // Windows still does not have support for this timeout function
  267. if (function_exists('stream_set_timeout')) stream_set_timeout($this->socket, $this->_smtpTimeout, 0);
  268. // Check response from Server
  269. if ( $_retVal = $this->server_parse($this->socket, "220") )
  270. $_retVal = $this->socket;
  271. }
  272. // This connection attempt failed.
  273. else
  274. {
  275. // DOL_CHANGE LDR
  276. if (empty($this->errstr)) $this->errstr='Failed to connect with fsockopen host='.$this->getHost().' port='.$this->getPort();
  277. $this->_setErr($this->errno, $this->errstr);
  278. $_retVal = false;
  279. }
  280. }
  281. return $_retVal;
  282. }
  283. /**
  284. * Attempt mail server authentication for a secure connection
  285. *
  286. * @return mixed $_retVal Boolean indicating success or failure of authentication
  287. */
  288. function _server_authenticate()
  289. {
  290. // Send the RFC2554 specified EHLO.
  291. // This improvment as provided by 'SirSir' to
  292. // accomodate both SMTP AND ESMTP capable servers
  293. $host=$this->getHost();
  294. $host=preg_replace('@tcp://@i','',$host); // Remove prefix
  295. $host=preg_replace('@ssl://@i','',$host); // Remove prefix
  296. if ( $_retVal = $this->socket_send_str('EHLO ' . $host, '250') )
  297. {
  298. // Send Authentication to Server
  299. // Check for errors along the way
  300. $this->socket_send_str('AUTH LOGIN', '334');
  301. // User name will not return any error, server will take anything we give it.
  302. $this->socket_send_str(base64_encode($this->_smtpsID), '334');
  303. // The error here just means the ID/password combo doesn't work.
  304. // There is not a method to determine which is the problem, ID or password
  305. if ( ! $_retVal = $this->socket_send_str(base64_encode($this->_smtpsPW), '235') )
  306. $this->_setErr(130, 'Invalid Authentication Credentials.');
  307. }
  308. else
  309. {
  310. $this->_setErr(126, '"' . $host . '" does not support authenticated connections.');
  311. }
  312. return $_retVal;
  313. }
  314. /**
  315. * Now send the message
  316. *
  317. * @param boolean $_bolTestMsg whether to run this method in 'Test' mode.
  318. * @param boolean $_bolDebug whether to log all communication between this Class and the Mail Server.
  319. * @return mixed void
  320. * $_strMsg If this is run in 'Test' mode, the actual message structure will be returned
  321. */
  322. function sendMsg ( $_bolTestMsg = false, $_bolDebug = false )
  323. {
  324. /**
  325. * Default return value
  326. */
  327. $_retVal = false;
  328. // Connect to Server
  329. if ( $this->socket = $this->_server_connect() )
  330. {
  331. // If a User ID *and* a password is given, assume Authentication is desired
  332. if( !empty($this->_smtpsID) && !empty($this->_smtpsPW) )
  333. {
  334. // Send the RFC2554 specified EHLO.
  335. $_retVal = $this->_server_authenticate();
  336. }
  337. // This is a "normal" SMTP Server "handshack"
  338. else
  339. {
  340. // Send the RFC821 specified HELO.
  341. $host=$this->getHost();
  342. $host=preg_replace('@tcp://@i','',$host); // Remove prefix
  343. $host=preg_replace('@ssl://@i','',$host); // Remove prefix
  344. $_retVal = $this->socket_send_str('HELO ' . $host, '250');
  345. }
  346. // Well, did we get to the server?
  347. if ( $_retVal )
  348. {
  349. // From this point onward most server response codes should be 250
  350. // Specify who the mail is from....
  351. // This has to be the raw email address, strip the "name" off
  352. $this->socket_send_str('MAIL FROM: ' . $this->getFrom('addr' ), '250');
  353. // 'RCPT TO:' must be given a single address, so this has to loop
  354. // through the list of addresses, regardless of TO, CC or BCC
  355. // and send it out "single file"
  356. foreach ( $this->get_RCPT_list() as $_address )
  357. {
  358. /*
  359. * TODO
  360. * After each 'RCPT TO:' is sent, we need to make sure it was kosher,
  361. * if not, the whole message will fail
  362. * If any email address fails, we will need to RESET the connection,
  363. * mark the last address as "bad" and start the address loop over again.
  364. * If any address fails, the entire message fails.
  365. */
  366. $this->socket_send_str('RCPT TO: <' . $_address . '>', '250');
  367. }
  368. // Tell the server we are ready to start sending data
  369. // with any custom headers...
  370. // This is the last response code we look for until the end of the message.
  371. $this->socket_send_str('DATA', '354');
  372. // Now we are ready for the message...
  373. // Ok, all the ingredients are mixed in let's cook this puppy...
  374. $this->socket_send_str($this->getHeader().$this->getBodyContent() . "\r\n" . '.', '250');
  375. // Now tell the server we are done and close the socket...
  376. fputs($this->socket, 'QUIT');
  377. fclose($this->socket );
  378. }
  379. }
  380. return $_retVal;
  381. }
  382. // =============================================================
  383. // ** Setter & Getter methods
  384. // ** Basic System configuration
  385. /**
  386. * setConfig() is used to populate select class properties from either
  387. * a user defined INI file or the systems 'php.ini' file
  388. *
  389. * If a user defined INI is to be used, the files complete path is passed
  390. * as the method single parameter. The INI can define any class and/or
  391. * user properties. Only properties defined within this file will be setter
  392. * and/or orverwritten
  393. *
  394. * If the systems 'php.ini' file is to be used, the method is called without
  395. * parameters. In this case, only HOST, PORT and FROM properties will be set
  396. * as they are the only properties that are defined within the 'php.ini'.
  397. *
  398. * If secure SMTP is to be used, the user ID and Password can be defined with
  399. * the user INI file, but the properties are not defined with the systems
  400. * 'php.ini'file, they must be defined via their setter methods
  401. *
  402. * This method can be called twice, if desired. Once without a parameter to
  403. * load the properties as defined within the systems 'php.ini' file, and a
  404. * second time, with a path to a user INI file for other properties to be
  405. * defined.
  406. *
  407. * @param mixed $_strConfigPath path to config file or VOID
  408. * @return void
  409. */
  410. function setConfig ( $_strConfigPath = null )
  411. {
  412. /**
  413. * Returns constructed SELECT Object string or boolean upon failure
  414. * Default value is set at TRUE
  415. */
  416. $_retVal = true;
  417. // if we have a path...
  418. if ( ! empty ($_strConfigPath) )
  419. {
  420. // If the path is not valid, this will NOT generate an error,
  421. // it will simply return FALSE.
  422. if ( ! @include ( $_strConfigPath ) )
  423. {
  424. $this->_setErr(110, '"' . $_strConfigPath . '" is not a valid path.');
  425. $_retVal = false;
  426. }
  427. }
  428. // Read the Systems php.ini file
  429. else
  430. {
  431. // Set these properties ONLY if they are set in the php.ini file.
  432. // Otherwise the default values will be used.
  433. if ( $_host = ini_get ('SMTPs') )
  434. $this->setHost($_host);
  435. if ( $_port = ini_get ('smtp_port') )
  436. $this->setPort($_port);
  437. if ( $_from = ini_get ('sendmail_from') )
  438. $this->setFrom($_from);
  439. }
  440. // Send back what we have
  441. return $_retVal;
  442. }
  443. /**
  444. * Determines the method inwhich the messages are to be sent.
  445. * - 'sockets' [0] - conect via network to SMTP server
  446. * - 'pipe [1] - use UNIX path to EXE
  447. * - 'phpmail [2] - use the PHP built-in mail function
  448. *
  449. * @param int $_type Interger value representing Mail Transport Type
  450. * @return void
  451. */
  452. function setTransportType($_type = 0)
  453. {
  454. if ( ( is_numeric ($_type) ) &&
  455. ( ( $_type >= 0 ) && ( $_type <= 3 ) ) )
  456. $this->_transportType = $_type;
  457. }
  458. /**
  459. * Return the method inwhich the message is to be sent.
  460. * - 'sockets' [0] - conect via network to SMTP server
  461. * - 'pipe [1] - use UNIX path to EXE
  462. * - 'phpmail [2] - use the PHP built-in mail function
  463. *
  464. * @return int $_strHost Host Name or IP of the Mail Server to use
  465. */
  466. function getTransportType()
  467. {
  468. return $this->_transportType;
  469. }
  470. /**
  471. * Path to the sendmail execuable
  472. *
  473. * @param string $_path Path to the sendmail execuable
  474. * @return void
  475. *
  476. */
  477. function setMailPath($_path)
  478. {
  479. // This feature is not yet implemented
  480. return true;
  481. if ( $_path )
  482. $this->_mailPath = $_path;
  483. }
  484. /**
  485. * Defines the Host Name or IP of the Mail Server to use.
  486. * This is defaulted to 'localhost'
  487. * This is used only with 'socket' based mail transmission
  488. *
  489. * @param string $_strHost Host Name or IP of the Mail Server to use
  490. * @return void
  491. */
  492. function setHost($_strHost)
  493. {
  494. if ( $_strHost )
  495. $this->_smtpsHost = $_strHost;
  496. }
  497. /**
  498. * Retrieves the Host Name or IP of the Mail Server to use
  499. * This is used only with 'socket' based mail transmission
  500. *
  501. * @return string $_strHost Host Name or IP of the Mail Server to use
  502. */
  503. function getHost()
  504. {
  505. return $this->_smtpsHost;
  506. }
  507. /**
  508. * Defines the Port Number of the Mail Server to use
  509. * This is defaulted to '25'
  510. * This is used only with 'socket' based mail transmission
  511. *
  512. * @param int $_intPort Port Number of the Mail Server to use
  513. * @return void
  514. */
  515. function setPort($_intPort)
  516. {
  517. if ( ( is_numeric ($_intPort) ) &&
  518. ( ( $_intPort >= 1 ) && ( $_intPort <= 65536 ) ) )
  519. $this->_smtpsPort = $_intPort;
  520. }
  521. /**
  522. * Retrieves the Port Number of the Mail Server to use
  523. * This is used only with 'socket' based mail transmission
  524. *
  525. * @return string Port Number of the Mail Server to use
  526. */
  527. function getPort()
  528. {
  529. return $this->_smtpsPort;
  530. }
  531. /**
  532. * User Name for authentication on Mail Server
  533. *
  534. * @param string $_strID User Name for authentication on Mail Server
  535. * @return void
  536. */
  537. function setID($_strID)
  538. {
  539. $this->_smtpsID = $_strID;
  540. }
  541. /**
  542. * Retrieves the User Name for authentication on Mail Server
  543. *
  544. * @return string User Name for authentication on Mail Server
  545. */
  546. function getID()
  547. {
  548. return $this->_smtpsID;
  549. }
  550. /**
  551. * User Password for authentication on Mail Server
  552. *
  553. * @param string $_strPW User Password for authentication on Mail Server
  554. * @return void
  555. */
  556. function setPW($_strPW)
  557. {
  558. $this->_smtpsPW = $_strPW;
  559. }
  560. /**
  561. * Retrieves the User Password for authentication on Mail Server
  562. *
  563. * @return string User Password for authentication on Mail Server
  564. */
  565. function getPW()
  566. {
  567. return $this->_smtpsPW;
  568. }
  569. /**
  570. * Character set used for current message
  571. * Character set is defaulted to 'iso-8859-1';
  572. *
  573. * @param string $_strCharSet Character set used for current message
  574. * @return void
  575. */
  576. function setCharSet($_strCharSet)
  577. {
  578. if ( $_strCharSet )
  579. $this->_smtpsCharSet = $_strCharSet;
  580. }
  581. /**
  582. * Retrieves the Character set used for current message
  583. *
  584. * @return string $_smtpsCharSet Character set used for current message
  585. */
  586. function getCharSet()
  587. {
  588. return $this->_smtpsCharSet;
  589. }
  590. /**
  591. * Content-Transfer-Encoding, Defaulted to '7bit'
  592. * This can be changed for 2byte characers sets
  593. * Known Encode Types
  594. * - 7bit Simple 7-bit ASCII
  595. * - 8bit 8-bit coding with line termination characters
  596. * - base64 3 octets encoded into 4 sextets with offset
  597. * - binary Arbitrary binary stream
  598. * - mac-binhex40 Macintosh binary to hex encoding
  599. * - quoted-printable Mostly 7-bit, with 8-bit characters encoded as "=HH"
  600. * - uuencode UUENCODE encoding
  601. *
  602. * @param string $_strTransEncode Content-Transfer-Encoding
  603. * @return void
  604. */
  605. function setTransEncode ( $_strTransEncode )
  606. {
  607. if ( array_search ( $_strTransEncode, $this->_smtpsTransEncodeTypes ) )
  608. $this->_smtpsTransEncode = $_strTransEncode;
  609. }
  610. /**
  611. * Retrieves the Content-Transfer-Encoding
  612. *
  613. * @return string $_smtpsTransEncode Content-Transfer-Encoding
  614. */
  615. function getTransEncode()
  616. {
  617. return $this->_smtpsTransEncode;
  618. }
  619. /**
  620. * Content-Transfer-Encoding, Defaulted to '0' [ZERO]
  621. * This can be changed for 2byte characers sets
  622. * Known Encode Types
  623. * - [0] 7bit Simple 7-bit ASCII
  624. * - [1] 8bit 8-bit coding with line termination characters
  625. * - [2] base64 3 octets encoded into 4 sextets with offset
  626. * - [3] binary Arbitrary binary stream
  627. * - [4] mac-binhex40 Macintosh binary to hex encoding
  628. * - [5] quoted-printable Mostly 7-bit, with 8-bit characters encoded as "=HH"
  629. * - [6] uuencode UUENCODE encoding
  630. *
  631. * @param string $_strTransEncodeType Content-Transfer-Encoding
  632. * @return void
  633. *
  634. */
  635. function setTransEncodeType($_strTransEncodeType)
  636. {
  637. if (array_search($_strTransEncodeType, $this->_smtpsTransEncodeTypes))
  638. $this->_smtpsTransEncodeType = $_strTransEncodeType;
  639. }
  640. /**
  641. * Retrieves the Content-Transfer-Encoding
  642. *
  643. * @return string Content-Transfer-Encoding
  644. */
  645. function getTransEncodeType()
  646. {
  647. return $this->_smtpsTransEncodeTypes[$this->_smtpsTransEncodeType];
  648. }
  649. // ** Message Construction
  650. /**
  651. * FROM Address from which mail will be sent
  652. *
  653. * @param string $_strFrom Address from which mail will be sent
  654. * @return void
  655. */
  656. function setFrom($_strFrom)
  657. {
  658. if ( $_strFrom )
  659. $this->_msgFrom = $this->_strip_email($_strFrom);
  660. }
  661. /**
  662. * Retrieves the Address from which mail will be sent
  663. *
  664. * @param boolean $_part To "strip" 'Real name' from address
  665. * @return string Address from which mail will be sent
  666. */
  667. function getFrom($_part = true)
  668. {
  669. $_retValue = '';
  670. if ( $_part === true )
  671. $_retValue = $this->_msgFrom;
  672. else
  673. $_retValue = $this->_msgFrom[$_part];
  674. return $_retValue;
  675. }
  676. /**
  677. * Inserts given addresses into structured format.
  678. * This method takes a list of given addresses, via an array
  679. * or a COMMA delimted string, and inserts them into a highly
  680. * structured array. This array is designed to remove duplicate
  681. * addresses and to sort them by Domain.
  682. *
  683. * @param string $_type TO, CC, or BCC lists to add addrresses into
  684. * @param mixed $_addrList Array or COMMA delimited string of addresses
  685. * @return void
  686. *
  687. */
  688. function _buildAddrList( $_type, $_addrList )
  689. {
  690. // Pull existing list
  691. $aryHost = $this->_msgRecipients;
  692. // Only run this if we have something
  693. if ( !empty ($_addrList ))
  694. {
  695. // $_addrList can be a STRING or an array
  696. if ( is_string ($_addrList) )
  697. {
  698. // This could be a COMMA delimited string
  699. if ( strstr ($_addrList, ',') )
  700. // "explode "list" into an array
  701. $_addrList = explode (',', $_addrList);
  702. // Stick it in an array
  703. else
  704. $_addrList = array($_addrList);
  705. }
  706. // take the array of addresses and split them further
  707. foreach ( $_addrList as $_strAddr )
  708. {
  709. // Strip off the end '>'
  710. $_strAddr = str_replace ('>', '', $_strAddr);
  711. // Seperate "Real Name" from eMail address
  712. $_tmpaddr = null;
  713. $_tmpaddr = explode ('<', $_strAddr);
  714. // We have a "Real Name" and eMail address
  715. if ( count ($_tmpaddr) == 2 )
  716. {
  717. $_tmpHost = explode ('@', $_tmpaddr[1]);
  718. $_tmpaddr[0] = trim ($_tmpaddr[0], ' ">');
  719. $aryHost[$_tmpHost[1]][$_type][$_tmpHost[0]] = $_tmpaddr[0];
  720. }
  721. // We only have an eMail address
  722. else
  723. {
  724. // Strip off the beggining '<'
  725. $_strAddr = str_replace ('<', '', $_strAddr);
  726. $_tmpHost = explode ('@', $_strAddr);
  727. $_tmpHost[0] = trim ($_tmpHost[0]);
  728. $_tmpHost[1] = trim ($_tmpHost[1]);
  729. $aryHost[$_tmpHost[1]][$_type][$_tmpHost[0]] = '';
  730. }
  731. }
  732. }
  733. // replace list
  734. $this->_msgRecipients = $aryHost;
  735. }
  736. /**
  737. * Returns an array of the various parts of an email address
  738. * This assumes a well formed address:
  739. * - "Real name" <username@domain.tld>
  740. * - "Real Name" is optional
  741. * - if "Real Name" does not exist, the angle brackets are optional
  742. * This will split an email address into 4 or 5 parts.
  743. * - $_aryEmail[org] = orignal string
  744. * - $_aryEmail[real] = "real name" - if there is one
  745. * - $_aryEmail[addr] = address part "username@domain.tld"
  746. * - $_aryEmail[host] = "domain.tld"
  747. * - $_aryEmail[user] = "userName"
  748. *
  749. * @param string $_strAddr Email address
  750. * @return array An array of the various parts of an email address
  751. */
  752. function _strip_email($_strAddr)
  753. {
  754. // Keep the orginal
  755. $_aryEmail['org'] = $_strAddr;
  756. // Set entire string to Lower Case
  757. $_strAddr = strtolower ($_strAddr);
  758. // Drop "stuff' off the end
  759. $_strAddr = trim ($_strAddr, ' ">');
  760. // Seperate "Real Name" from eMail address, if we have one
  761. $_tmpAry = explode ('<', $_strAddr);
  762. // Do we have a "Real name"
  763. if ( count ($_tmpAry) == 2 )
  764. {
  765. // We may not really have a "Real Name"
  766. if ( $_tmpAry[0])
  767. $_aryEmail['real'] = trim ($_tmpAry[0], ' ">');
  768. $_aryEmail['addr'] = $_tmpAry[1];
  769. }
  770. else
  771. $_aryEmail['addr'] = $_tmpAry[0];
  772. // Pull User Name and Host.tld apart
  773. list($_aryEmail['user'], $_aryEmail['host'] ) = explode ('@', $_aryEmail['addr']);
  774. // Put the brackets back around the address
  775. $_aryEmail['addr'] = '<' . $_aryEmail['addr'] . '>';
  776. return $_aryEmail;
  777. }
  778. /**
  779. * Returns an array of bares addresses for use with 'RCPT TO:'
  780. * This is a "build as you go" method. Each time this method is called
  781. * the underlaying array is destroyed and reconstructed.
  782. *
  783. * @return array Returns an array of bares addresses
  784. */
  785. function get_RCPT_list()
  786. {
  787. /**
  788. * An array of bares addresses for use with 'RCPT TO:'
  789. */
  790. unset ($_RCPT_list);
  791. // walk down Recipients array and pull just email addresses
  792. foreach ( $this->_msgRecipients as $_host => $_list )
  793. {
  794. foreach ( $_list as $_subList )
  795. {
  796. foreach ( $_subList as $_name => $_addr )
  797. {
  798. // build RCPT list
  799. $_RCPT_list[] = $_name . '@' . $_host;
  800. }
  801. }
  802. }
  803. return $_RCPT_list;
  804. }
  805. /**
  806. * Returns an array of addresses for a specific type; TO, CC or BCC
  807. *
  808. * @param mixed $_which Which collection of adresses to return
  809. * @return array Array of emaill address
  810. */
  811. function get_email_list($_which = null)
  812. {
  813. // We need to know which address segment to pull
  814. if ( $_which )
  815. {
  816. // Make sure we have addresses to process
  817. if ( $this->_msgRecipients )
  818. {
  819. $_RCPT_list=array();
  820. // walk down Recipients array and pull just email addresses
  821. foreach ( $this->_msgRecipients as $_host => $_list )
  822. {
  823. if ( $this->_msgRecipients[$_host][$_which] )
  824. {
  825. foreach ( $this->_msgRecipients[$_host][$_which] as $_addr => $_realName )
  826. {
  827. if ( $_realName ) // DOL_CHANGE FIX
  828. {
  829. $_realName = '"' . $_realName . '"';
  830. $_RCPT_list[] = $_realName . ' <' . $_addr . '@' . $_host . '>';
  831. }
  832. else
  833. {
  834. $_RCPT_list[] = $_addr . '@' . $_host;
  835. }
  836. }
  837. }
  838. }
  839. return implode(', ', $_RCPT_list);
  840. }
  841. else
  842. {
  843. $this->_setErr(101, 'No eMail Address for message to be sent to.');
  844. return false;
  845. }
  846. }
  847. else
  848. {
  849. $this->_setErr(102, 'eMail type not defined.');
  850. return false;
  851. }
  852. }
  853. /**
  854. * TO Address[es] inwhich to send mail to
  855. *
  856. * @param mixed $_addrTo TO Address[es] inwhich to send mail to
  857. * @return void
  858. */
  859. function setTO($_addrTo)
  860. {
  861. if ( $_addrTo )
  862. $this->_buildAddrList('to', $_addrTo);
  863. }
  864. /**
  865. * Retrieves the TO Address[es] inwhich to send mail to
  866. *
  867. * @return string TO Address[es] inwhich to send mail to
  868. */
  869. function getTo()
  870. {
  871. return $this->get_email_list('to');
  872. }
  873. /**
  874. * CC Address[es] inwhich to send mail to
  875. *
  876. * @param string $_strCC CC Address[es] inwhich to send mail to
  877. * @return void
  878. */
  879. function setCC($_strCC)
  880. {
  881. if ( $_strCC )
  882. $this->_buildAddrList('cc', $_strCC);
  883. }
  884. /**
  885. * Retrieves the CC Address[es] inwhich to send mail to
  886. *
  887. * @return string CC Address[es] inwhich to send mail to
  888. */
  889. function getCC()
  890. {
  891. return $this->get_email_list('cc');
  892. }
  893. /**
  894. * BCC Address[es] inwhich to send mail to
  895. *
  896. * @param string $_strBCC Recipients BCC Address[es] inwhich to send mail to
  897. * @return void
  898. */
  899. function setBCC($_strBCC)
  900. {
  901. if ( $_strBCC )
  902. $this->_buildAddrList('bcc', $_strBCC);
  903. }
  904. /**
  905. * Retrieves the BCC Address[es] inwhich to send mail to
  906. *
  907. * @return string BCC Address[es] inwhich to send mail to
  908. */
  909. function getBCC()
  910. {
  911. return $this->get_email_list('bcc');
  912. }
  913. /**
  914. * Message Subject
  915. *
  916. * @param string $_strSubject Message Subject
  917. * @return void
  918. */
  919. function setSubject($_strSubject = '')
  920. {
  921. if ( $_strSubject )
  922. $this->_msgSubject = $_strSubject;
  923. }
  924. /**
  925. * Retrieves the Message Subject
  926. *
  927. * @return string Message Subject
  928. */
  929. function getSubject()
  930. {
  931. return $this->_msgSubject;
  932. }
  933. /**
  934. * Constructes and returns message header
  935. *
  936. * @return string Complete message header
  937. */
  938. function getHeader()
  939. {
  940. $_header = 'From: ' . $this->getFrom( 'org' ) . "\r\n"
  941. . 'To: ' . $this->getTO() . "\r\n";
  942. if ( $this->getCC() )
  943. $_header .= 'Cc: ' . $this->getCC() . "\r\n";
  944. if ( $this->getBCC() )
  945. $_header .= 'Bcc: ' . $this->getBCC() . "\r\n";
  946. $host=$this->getHost();
  947. $host=preg_replace('@tcp://@i','',$host); // Remove prefix
  948. $host=preg_replace('@ssl://@i','',$host); // Remove prefix
  949. //NOTE: Message-ID should probably contain the username of the user who sent the msg
  950. $_header .= 'Subject: ' . $this->getSubject() . "\r\n"
  951. . 'Date: ' . date("r") . "\r\n"
  952. . 'Message-ID: <' . time() . '.SMTPs@' . $host . ">\r\n";
  953. // . 'Read-Receipt-To: ' . $this->getFrom( 'org' ) . "\r\n"
  954. // . 'Return-Receipt-To: ' . $this->getFrom( 'org' ) . "\r\n";
  955. if ( $this->getSensitivity() )
  956. $_header .= 'Sensitivity: ' . $this->getSensitivity() . "\r\n";
  957. if ( $this->_msgPriority != 3 )
  958. $_header .= $this->getPriority();
  959. // DOL_CHANGE LDR
  960. if ( $this->getDeliveryReceipt() )
  961. $_header .= 'Disposition-Notification-To: '.$this->getFrom('addr') . "\r\n";
  962. if ( $this->getErrorsTo() )
  963. $_header .= 'Errors-To: '.$this->getErrorsTo('addr') . "\r\n";
  964. $_header .= 'X-Mailer: Dolibarr version ' . DOL_VERSION .' (using SMTPs Mailer)' . "\r\n"
  965. . 'Mime-Version: 1.0' . "\r\n";
  966. return $_header;
  967. }
  968. /**
  969. * Message Content
  970. *
  971. * @param string $_msgContent Message Content
  972. * @return void
  973. */
  974. function setBodyContent ( $strContent, $strType = 'plain' )
  975. {
  976. //if ( $strContent )
  977. //{
  978. if ( $strType == 'html' )
  979. $strMimeType = 'text/html';
  980. else
  981. $strMimeType = 'text/plain';
  982. // Make RFC821 Compliant, replace bare linefeeds
  983. $strContent = preg_replace("/(?<!\r)\n/si", "\r\n", $strContent );
  984. $strContent = rtrim(wordwrap($strContent));
  985. $this->_msgContent[$strType] = array();
  986. $this->_msgContent[$strType]['mimeType'] = $strMimeType;
  987. $this->_msgContent[$strType]['data'] = $strContent;
  988. if ( $this->getMD5flag() )
  989. $this->_msgContent[$strType]['md5'] = dol_hash($strContent);
  990. //}
  991. }
  992. /**
  993. * Retrieves the Message Content
  994. *
  995. * @return string Message Content
  996. */
  997. function getBodyContent()
  998. {
  999. // Generate a new Boundary string
  1000. $this->_setBoundary();
  1001. // What type[s] of content do we have
  1002. $_types = array_keys ($this->_msgContent);
  1003. // How many content types do we have
  1004. $keyCount = count ($_types);
  1005. // If we have ZERO, we have a problem
  1006. if( $keyCount === 0 )
  1007. die ("Sorry, no content");
  1008. // If we have ONE, we can use the simple format
  1009. else if( $keyCount === 1 )
  1010. {
  1011. $_msgData = $this->_msgContent;
  1012. $_msgData = $_msgData[$_types[0]];
  1013. $content = 'Content-Type: ' . $_msgData['mimeType'] . '; charset="' . $this->getCharSet() . '"' . "\r\n"
  1014. . 'Content-Transfer-Encoding: ' . $this->getTransEncodeType() . "\r\n"
  1015. . 'Content-Disposition: inline' . "\r\n"
  1016. . 'Content-Description: message' . "\r\n";
  1017. if ( $this->getMD5flag() )
  1018. $content .= 'Content-MD5: ' . $_msgData['md5'] . "\r\n";
  1019. $content .= "\r\n"
  1020. . $_msgData['data'] . "\r\n";
  1021. }
  1022. // If we have more than ONE, we use the multi-part format
  1023. else if( $keyCount > 1 )
  1024. {
  1025. // Since this is an actual multi-part message
  1026. // We need to define a content message Boundary
  1027. // NOTE: This was 'multipart/alternative', but Windows based
  1028. // mail servers have issues with this.
  1029. /*
  1030. * TODO Investigate "nested" boundary message parts
  1031. */
  1032. //$content = 'Content-Type: multipart/related; boundary="' . $this->_getBoundary() . '"' . "\r\n";
  1033. $content = 'Content-Type: multipart/mixed; boundary="' . $this->_getBoundary() . '"' . "\r\n";
  1034. // TODO Restore
  1035. // . "\r\n"
  1036. // . 'This is a multi-part message in MIME format.' . "\r\n";
  1037. $content .= "Content-Transfer-Encoding: 8bit" . "\r\n";
  1038. $content .= "\r\n";
  1039. // Loop through message content array
  1040. foreach ($this->_msgContent as $type => $_content )
  1041. {
  1042. if ( $type == 'attachment' )
  1043. {
  1044. // loop through all attachments
  1045. foreach ( $_content as $_file => $_data )
  1046. {
  1047. // TODO Restore "\r\n"
  1048. $content .= "--" . $this->_getBoundary() . "\r\n"
  1049. . 'Content-Disposition: attachment; filename="' . $_data['fileName'] . '"' . "\r\n"
  1050. . 'Content-Type: ' . $_data['mimeType'] . '; name="' . $_data['fileName'] . '"' . "\r\n"
  1051. . 'Content-Transfer-Encoding: base64' . "\r\n"
  1052. . 'Content-Description: File Attachment' . "\r\n";
  1053. if ( $this->getMD5flag() )
  1054. $content .= 'Content-MD5: ' . $_data['md5'] . "\r\n";
  1055. $content .= "\r\n"
  1056. . $_data['data'] . "\r\n"
  1057. . "\r\n";
  1058. }
  1059. }
  1060. // DOL_CHANGE LDR
  1061. else if ( $type == 'image' )
  1062. {
  1063. // loop through all images
  1064. foreach ( $_content as $_image => $_data )
  1065. {
  1066. // TODO Restore "\r\n"
  1067. $content .= "--" . $this->_getBoundary() . "\r\n";
  1068. $content .= 'Content-Type: ' . $_data['mimeType'] . '; name="' . $_data['imageName'] . '"' . "\r\n"
  1069. . 'Content-Transfer-Encoding: base64' . "\r\n"
  1070. . 'Content-Disposition: inline; filename="' . $_data['imageName'] . '"' . "\r\n"
  1071. . 'Content-ID: <' . $_data['cid'] . '> ' . "\r\n";
  1072. if ( $this->getMD5flag() )
  1073. $content .= 'Content-MD5: ' . $_data['md5'] . "\r\n";
  1074. $content .= "\r\n"
  1075. . $_data['data'] . "\r\n";
  1076. }
  1077. }
  1078. else
  1079. {
  1080. // TODO Restore "\r\n"
  1081. $content .= "--" . $this->_getBoundary() . "\r\n"
  1082. . 'Content-Type: ' . $_content['mimeType'] . '; '
  1083. // . 'charset="' . $this->getCharSet() . '"';
  1084. . 'charset=' . $this->getCharSet() . '';
  1085. // TODO Restore
  1086. // $content .= ( $type == 'html') ? '; name="HTML Part"' : '';
  1087. $content .= "\r\n";
  1088. // $content .= 'Content-Transfer-Encoding: ';
  1089. // $content .= ($type == 'html') ? 'quoted-printable' : $this->getTransEncodeType();
  1090. // $content .= "\r\n"
  1091. // . 'Content-Disposition: inline' . "\r\n"
  1092. // . 'Content-Description: ' . $type . ' message' . "\r\n";
  1093. if ( $this->getMD5flag() )
  1094. $content .= 'Content-MD5: ' . $_content['md5'] . "\r\n";
  1095. $content .= "\r\n"
  1096. . $_content['data'] . "\r\n"
  1097. . "\r\n";
  1098. }
  1099. }
  1100. // Close message boundries
  1101. // $content .= "\r\n--" . $this->_getBoundary() . '--' . "\r\n" ;
  1102. $content .= "--" . $this->_getBoundary() . '--' . "\r\n" ;
  1103. }
  1104. return $content;
  1105. }
  1106. /**
  1107. * File attachments are added to the content array as sub-arrays,
  1108. * allowing for multiple attachments for each outbound email
  1109. *
  1110. * @param string $strContent File data to attach to message
  1111. * @param string $strFileName File Name to give to attachment
  1112. * @param string $strMimeType File Mime Type of attachment
  1113. * @return void
  1114. */
  1115. function setAttachment($strContent, $strFileName = 'unknown', $strMimeType = 'unknown')
  1116. {
  1117. if ( $strContent )
  1118. {
  1119. $strContent = rtrim(chunk_split(base64_encode($strContent), 76, "\r\n"));
  1120. $this->_msgContent['attachment'][$strFileName]['mimeType'] = $strMimeType;
  1121. $this->_msgContent['attachment'][$strFileName]['fileName'] = $strFileName;
  1122. $this->_msgContent['attachment'][$strFileName]['data'] = $strContent;
  1123. if ( $this->getMD5flag() )
  1124. $this->_msgContent['attachment'][$strFileName]['md5'] = dol_hash($strContent);
  1125. }
  1126. }
  1127. // DOL_CHANGE LDR
  1128. /**
  1129. * Image attachments are added to the content array as sub-arrays,
  1130. * allowing for multiple images for each outbound email
  1131. *
  1132. * @param string $strContent Image data to attach to message
  1133. * @param string $strImageName Image Name to give to attachment
  1134. * @param string $strMimeType Image Mime Type of attachment
  1135. * @param string $strImageCid CID
  1136. * @return void
  1137. */
  1138. function setImageInline($strContent, $strImageName = 'unknown', $strMimeType = 'unknown', $strImageCid = 'unknown')
  1139. {
  1140. if ($strContent)
  1141. {
  1142. $this->_msgContent['image'][$strImageName]['mimeType'] = $strMimeType;
  1143. $this->_msgContent['image'][$strImageName]['imageName'] = $strImageName;
  1144. $this->_msgContent['image'][$strImageName]['cid'] = $strImageCid;
  1145. $this->_msgContent['image'][$strImageName]['data'] = $strContent;
  1146. if ( $this->getMD5flag() )
  1147. $this->_msgContent['image'][$strFileName]['md5'] = dol_hash($strContent);
  1148. }
  1149. }
  1150. // END DOL_CHANGE LDR
  1151. /**
  1152. * Message Content Sensitivity
  1153. * Message Sensitivity values:
  1154. * - [0] None - default
  1155. * - [1] Personal
  1156. * - [2] Private
  1157. * - [3] Company Confidential
  1158. *
  1159. * @param string $_value Message Sensitivity
  1160. * @return void
  1161. */
  1162. function setSensitivity($_value = 0)
  1163. {
  1164. if ( ( is_numeric ($_value) ) &&
  1165. ( ( $_value >= 0 ) && ( $_value <= 3 ) ) )
  1166. $this->_msgSensitivity = $_value;
  1167. }
  1168. /**
  1169. * Returns Message Content Sensitivity string
  1170. * Message Sensitivity values:
  1171. * - [0] None - default
  1172. * - [1] Personal
  1173. * - [2] Private
  1174. * - [3] Company Confidential
  1175. *
  1176. * @param string Message Sensitivity
  1177. * @return void
  1178. */
  1179. function getSensitivity()
  1180. {
  1181. return $this->_arySensitivity[$this->_msgSensitivity];
  1182. }
  1183. /**
  1184. * Message Content Priority
  1185. * Message Priority values:
  1186. * - [0] 'Bulk'
  1187. * - [1] 'Highest'
  1188. * - [2] 'High'
  1189. * - [3] 'Normal' - default
  1190. * - [4] 'Low'
  1191. * - [5] 'Lowest'
  1192. *
  1193. * @param string $_value Message Priority
  1194. * @return void
  1195. */
  1196. function setPriority ( $_value = 3 )
  1197. {
  1198. if ( ( is_numeric ($_value) ) &&
  1199. ( ( $_value >= 0 ) && ( $_value <= 5 ) ) )
  1200. $this->_msgPriority = $_value;
  1201. }
  1202. /**
  1203. * Message Content Priority
  1204. * Message Priority values:
  1205. * - [0] 'Bulk'
  1206. * - [1] 'Highest'
  1207. * - [2] 'High'
  1208. * - [3] 'Normal' - default
  1209. * - [4] 'Low'
  1210. * - [5] 'Lowest'
  1211. *
  1212. * @return void
  1213. */
  1214. function getPriority()
  1215. {
  1216. return 'Importance: ' . $this->_aryPriority[$this->_msgPriority] . "\r\n"
  1217. . 'Priority: ' . $this->_aryPriority[$this->_msgPriority] . "\r\n"
  1218. . 'X-Priority: ' . $this->_msgPriority . ' (' . $this->_aryPriority[$this->_msgPriority] . ')' . "\r\n";
  1219. }
  1220. /**
  1221. * Set flag which determines whether to calculate message MD5 checksum.
  1222. *
  1223. * @param string $_flag Message Priority
  1224. * @return void
  1225. */
  1226. function setMD5flag($_flag = false)
  1227. {
  1228. $this->_smtpMD5 = $_flag;
  1229. }
  1230. /**
  1231. * Gets flag which determines whether to calculate message MD5 checksum.
  1232. *
  1233. * @return string Message Priority
  1234. */
  1235. function getMD5flag()
  1236. {
  1237. return $this->_smtpMD5;
  1238. }
  1239. /**
  1240. * Message X-Header Content
  1241. * This is a simple "insert". Whatever is given will be placed
  1242. * "as is" into the Xheader array.
  1243. *
  1244. * @param string $strXdata Message X-Header Content
  1245. * @return void
  1246. */
  1247. function setXheader($strXdata)
  1248. {
  1249. if ( $strXdata )
  1250. $this->_msgXheader[] = $strXdata;
  1251. }
  1252. /**
  1253. * Retrieves the Message X-Header Content
  1254. *
  1255. * @return string $_msgContent Message X-Header Content
  1256. */
  1257. function getXheader()
  1258. {
  1259. return $this->_msgXheader;
  1260. }
  1261. /**
  1262. * Generates Random string for MIME message Boundary
  1263. *
  1264. * @return void
  1265. */
  1266. function _setBoundary()
  1267. {
  1268. $this->_smtpsBoundary = "multipart_x." . time() . ".x_boundary";
  1269. }
  1270. /**
  1271. * Retrieves the MIME message Boundary
  1272. *
  1273. * @return string $_smtpsBoundary MIME message Boundary
  1274. */
  1275. function _getBoundary()
  1276. {
  1277. return $this->_smtpsBoundary;
  1278. }
  1279. /**
  1280. * This function has been modified as provided by SirSir to allow multiline responses when
  1281. * using SMTP Extensions
  1282. *
  1283. * @param $socket
  1284. * @param $response
  1285. */
  1286. function server_parse($socket, $response)
  1287. {
  1288. /**
  1289. * Returns constructed SELECT Object string or boolean upon failure
  1290. * Default value is set at TRUE
  1291. */
  1292. $_retVal = true;
  1293. $server_response = '';
  1294. while ( substr($server_response,3,1) != ' ' )
  1295. {
  1296. if( !( $server_response = fgets($socket, 256) ) )
  1297. {
  1298. $this->_setErr(121, "Couldn't get mail server response codes");
  1299. $_retVal = false;
  1300. }
  1301. }
  1302. if( !( substr($server_response, 0, 3) == $response ) )
  1303. {
  1304. $this->_setErr(120, "Ran into problems sending Mail.\r\nResponse: $server_response");
  1305. $_retVal = false;
  1306. }
  1307. return $_retVal;
  1308. }
  1309. function socket_send_str ( $_strSend, $_returnCode = null, $CRLF = "\r\n" )
  1310. {
  1311. if ($this->_debug) $this->log.=$_strSend; // DOL_CHANGE LDR for log
  1312. fputs($this->socket, $_strSend . $CRLF);
  1313. if ($this->_debug) $this->log.=' ('.$_returnCode.')' . $CRLF;
  1314. if ( $_returnCode )
  1315. return $this->server_parse($this->socket, $_returnCode);
  1316. }
  1317. // =============================================================
  1318. // ** Error handling methods
  1319. /**
  1320. * Defines errors codes and messages for Class
  1321. *
  1322. * @param int $_errNum Error Code Number
  1323. * @param string $_errMsg Error Message
  1324. * @return void
  1325. */
  1326. function _setErr ( $_errNum, $_errMsg )
  1327. {
  1328. $this->_smtpsErrors[] = array( 'num' => $_errNum,
  1329. 'msg' => $_errMsg );
  1330. }
  1331. /**
  1332. * Returns errors codes and messages for Class
  1333. *
  1334. * @return string $_errMsg Error Message
  1335. */
  1336. function getErrors()
  1337. {
  1338. $_errMsg = array();
  1339. foreach ( $this->_smtpsErrors as $_err => $_info )
  1340. {
  1341. $_errMsg[] = 'Error [' . $_info['num'] .']: '. $_info['msg'];
  1342. }
  1343. return implode("\n", $_errMsg);
  1344. }
  1345. }
  1346. // =============================================================
  1347. // ** CSV Version Control Info
  1348. /**
  1349. * Revision 2011/09/12 07:49:59 eldy
  1350. * Doxygen
  1351. *
  1352. * Revision 2011/09/06 06:53:53 hregis
  1353. * Fix: use dol_hash instead md5 php function
  1354. *
  1355. * Revision 2011/09/03 00:14:27 eldy
  1356. * Doxygen
  1357. *
  1358. * Revision 2011/08/28 14:24:23 eldy
  1359. * Doxygen
  1360. *
  1361. * Revision 2011/07/12 22:19:02 eldy
  1362. * Fix: Attachment fails if content was empty
  1363. *
  1364. * Revision 2011/06/20 23:17:50 hregis
  1365. * Fix: use best structure of mail
  1366. *
  1367. * Revision 2010/04/13 20:58:37 eldy
  1368. * Fix: Can provide ip address on smtps. Better error reporting.
  1369. *
  1370. * Revision 2010/04/13 20:30:25 eldy
  1371. * Fix: Can provide ip address on smtps. Better error reporting.
  1372. *
  1373. * Revision 2010/01/12 13:02:07 hregis
  1374. * Fix: missing attach-files
  1375. *
  1376. * Revision 2009/11/01 14:16:30 eldy
  1377. * Fix: Sending mail with SMTPS was not working.
  1378. *
  1379. * Revision 2009/10/20 13:14:47 hregis
  1380. * Fix: function "split" is deprecated since php 5.3.0
  1381. *
  1382. * Revision 2009/05/13 19:10:07 eldy
  1383. * New: Can use inline images.Everything seems to work with thunderbird and webmail gmail. New to be tested on other mail browsers.
  1384. *
  1385. * Revision 2009/05/13 14:49:30 eldy
  1386. * Fix: Make code so much simpler and solve a lot of problem with new version.
  1387. *
  1388. * Revision 2009/02/09 00:04:35 eldy
  1389. * Added support for SMTPS protocol
  1390. *
  1391. * Revision 2008/04/16 23:11:45 eldy
  1392. * New: Add action "Test server connectivity"
  1393. *
  1394. * Revision 1.18 2007/01/12 22:17:08 ongardie
  1395. * - Added full_http_site_root() to utils-misc.php
  1396. * - Made SMTPs' getError() easier to use
  1397. * - Improved activity modified emails
  1398. *
  1399. * Revision 1.17 2006/04/05 03:15:40 ongardie
  1400. * -Fixed …

Large files files are truncated, but you can click here to view the full file