2011-08-26 17:13:58 +02:00
< ? php
2011-11-26 12:36:36 +01:00
/*
* Copyright ( C ) Walter Torres < walter @ torres . ws > [ with a * lot * of help ! ]
2015-05-05 04:10:42 +02:00
* Copyright ( C ) 2005 - 2015 Laurent Destailleur < eldy @ users . sourceforge . net >
2011-11-26 12:36:36 +01:00
* Copyright ( C ) 2006 - 2011 Regis Houssin
2016-03-16 01:54:45 +01:00
* Copyright ( C ) 2016 Jonathan TISSEAU < jonathan . tisseau @ 86 dev . fr >
2011-11-26 12:36:36 +01:00
*
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
2013-01-16 15:36:08 +01:00
* the Free Software Foundation ; either version 3 of the License , or
2011-11-26 12:36:36 +01:00
* ( at your option ) any later version .
2011-08-27 01:40:47 +02:00
*
2011-11-26 12:36:36 +01:00
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
2011-08-27 01:40:47 +02:00
*
2011-11-26 12:36:36 +01:00
* You should have received a copy of the GNU General Public License
* along with this program . If not , see < http :// www . gnu . org / licenses />.
*/
/**
* \file htdocs / core / class / smtps . class . php
* \brief Class to construct and send SMTP compliant email , even to a secure
* SMTP server , regardless of platform .
2011-08-27 01:40:47 +02:00
* Goals :
* - mime compliant
* - multiple Reciptiants
* - TO
* - CC
* - BCC
* - multi - part message
* - plain text
* - HTML
* - inline attachments
* - attachments
* - GPG access
* This Class is based off of 'SMTP PHP MAIL' by Dirk Paehl , http :// www . paehl . de
*/
/**
2012-02-01 22:39:17 +01:00
* Class to construct and send SMTP compliant email , even
* to a secure SMTP server , regardless of platform .
2011-08-28 16:18:14 +02:00
*/
2011-08-26 17:13:58 +02:00
class SMTPs
{
2011-11-26 12:36:36 +01:00
/**
* Host Name or IP of SMTP Server to use
*/
var $_smtpsHost = 'localhost' ;
/**
* SMTP Server Port definition . 25 is default value
* This can be defined via a INI file or via a setter method
*/
var $_smtpsPort = '25' ;
/**
* Secure SMTP Server access ID
* This can be defined via a INI file or via a setter method
*/
var $_smtpsID = null ;
/**
* Secure SMTP Server access Password
* This can be defined via a INI file or via a setter method
*/
var $_smtpsPW = null ;
/**
* Who sent the Message
* This can be defined via a INI file or via a setter method
*/
var $_msgFrom = null ;
/**
* Where are replies and errors to be sent to
* This can be defined via a INI file or via a setter method
*/
var $_msgReplyTo = null ;
/**
* Who will the Message be sent to ; TO , CC , BCC
* Multi - diminsional array containg addresses the message will
* be sent TO , CC or BCC
*/
var $_msgRecipients = null ;
/**
* Message Subject
*/
var $_msgSubject = null ;
/**
* Message Content
*/
var $_msgContent = null ;
/**
* Custom X - Headers
*/
var $_msgXheader = null ;
/**
* Character set
* Defaulted to 'iso-8859-1'
*/
var $_smtpsCharSet = 'iso-8859-1' ;
/**
* Message Sensitivity
* Defaults to ZERO - None
*/
var $_msgSensitivity = 0 ;
/**
* Message Sensitivity
*/
var $_arySensitivity = array ( false ,
2011-08-26 17:13:58 +02:00
'Personal' ,
'Private' ,
'Company Confidential' );
2011-11-26 12:36:36 +01:00
/**
* Message Sensitivity
* Defaults to 3 - Normal
*/
var $_msgPriority = 3 ;
2011-08-26 17:13:58 +02:00
2011-11-26 12:36:36 +01:00
/**
* Message Priority
*/
var $_aryPriority = array ( 'Bulk' ,
2011-08-26 17:13:58 +02:00
'Highest' ,
'High' ,
'Normal' ,
'Low' ,
'Lowest' );
2011-11-26 12:36:36 +01:00
/**
* Content - Transfer - Encoding
* Defaulted to 0 - 7 bit
*/
var $_smtpsTransEncodeType = 0 ;
2011-08-26 17:13:58 +02:00
2011-11-26 12:36:36 +01:00
/**
* Content - Transfer - Encoding
*/
var $_smtpsTransEncodeTypes = array ( '7bit' , // Simple 7-bit ASCII
2011-08-26 17:13:58 +02:00
'8bit' , // 8-bit coding with line termination characters
'base64' , // 3 octets encoded into 4 sextets with offset
'binary' , // Arbitrary binary stream
'mac-binhex40' , // Macintosh binary to hex encoding
'quoted-printable' , // Mostly 7-bit, with 8-bit characters encoded as "=HH"
'uuencode' ); // UUENCODE encoding
2011-11-26 12:36:36 +01:00
/**
* Content - Transfer - Encoding
* Defaulted to '7bit'
*/
var $_smtpsTransEncode = '7bit' ;
/**
* Boundary String for MIME seperation
*/
var $_smtpsBoundary = null ;
2012-06-17 18:40:45 +02:00
/**
* Related Boundary
*/
var $_smtpsRelatedBoundary = null ;
2012-07-02 19:30:37 +02:00
/**
* Alternative Boundary
*/
2012-06-17 18:40:45 +02:00
var $_smtpsAlternativeBoundary = null ;
2011-11-26 12:36:36 +01:00
/**
* Determines the method inwhich the message are to be sent .
* - 'sockets' [ 0 ] - conect via network to SMTP server - default
* - ' pipe [ 1 ] - use UNIX path to EXE
* - ' phpmail [ 2 ] - use the PHP built - in mail function
* NOTE : Only 'sockets' is implemented
*/
var $_transportType = 0 ;
/**
* If '$_transportType' is set to '1' , then this variable is used
* to define the UNIX file system path to the sendmail execuable
*/
var $_mailPath = '/usr/lib/sendmail' ;
/**
* Sets the SMTP server timeout in seconds .
*/
var $_smtpTimeout = 10 ;
/**
* Determines whether to calculate message MD5 checksum .
*/
var $_smtpMD5 = false ;
/**
* Class error codes and messages
*/
var $_smtpsErrors = null ;
/**
* Defines log level
* 0 - no logging
* 1 - connectivity logging
* 2 - message generation logging
* 3 - detail logging
*/
var $_log_level = 0 ;
/**
* Place Class in " debug " mode
*/
var $_debug = false ;
2017-07-17 20:09:19 +02:00
// @CHANGE LDR
2011-11-26 12:36:36 +01:00
var $log = '' ;
var $_errorsTo = '' ;
var $_deliveryReceipt = 0 ;
2016-12-20 12:38:24 +01:00
var $_trackId = '' ;
var $_moreInHeader = '' ;
2011-11-26 12:36:36 +01:00
2012-01-04 14:05:49 +01:00
/**
* Set delivery receipt
*
* @ param int $_val Value
* @ return void
*/
2011-11-26 12:36:36 +01:00
function setDeliveryReceipt ( $_val = 0 )
{
$this -> _deliveryReceipt = $_val ;
}
2012-01-04 14:05:49 +01:00
/**
* get delivery receipt
*
* @ return int Delivery receipt
*/
2011-11-26 12:36:36 +01:00
function getDeliveryReceipt ()
{
return $this -> _deliveryReceipt ;
}
2015-05-05 04:10:42 +02:00
/**
* Set trackid
*
* @ param string $_val Value
* @ return void
*/
function setTrackId ( $_val = '' )
{
$this -> _trackId = $_val ;
}
/**
2016-12-20 12:38:24 +01:00
* Set moreInHeader
*
* @ param string $_val Value
* @ return void
*/
function setMoreInHeader ( $_val = '' )
{
$this -> _moreinheader = $_val ;
}
2017-07-18 12:49:19 +02:00
2016-12-20 12:38:24 +01:00
/**
2015-05-05 04:10:42 +02:00
* get trackid
*
2016-12-20 12:38:24 +01:00
* @ return string Track id
2015-05-05 04:10:42 +02:00
*/
function getTrackId ()
{
return $this -> _trackId ;
}
2016-12-20 12:38:24 +01:00
/**
* get moreInHeader
*
* @ return string moreInHeader
*/
function getMoreInHeader ()
{
return $this -> _moreinheader ;
}
2017-07-18 12:49:19 +02:00
2012-01-04 14:05:49 +01:00
/**
* Set errors to
*
* @ param string $_strErrorsTo Errors to
* @ return void
*/
2011-11-26 12:36:36 +01:00
function setErrorsTo ( $_strErrorsTo )
{
if ( $_strErrorsTo )
$this -> _errorsTo = $this -> _strip_email ( $_strErrorsTo );
}
2012-01-04 14:05:49 +01:00
/**
* Get errors to
*
* @ param boolean $_part Variant
* @ return string Errors to
*/
function getErrorsTo ( $_part = true )
2011-11-26 12:36:36 +01:00
{
$_retValue = '' ;
if ( $_part === true )
$_retValue = $this -> _errorsTo ;
else
$_retValue = $this -> _errorsTo [ $_part ];
return $_retValue ;
}
2012-01-04 14:05:49 +01:00
/**
* Set debug
*
* @ param boolean $_vDebug Value for debug
* @ return void
*/
function setDebug ( $_vDebug = false )
2011-11-26 12:36:36 +01:00
{
$this -> _debug = $_vDebug ;
}
/**
* build RECIPIENT List , all addresses who will recieve this message
*
* @ return void
*/
function buildRCPTlist ()
{
// Pull TO list
$_aryToList = $this -> getTO ();
}
2018-09-06 21:27:18 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
2011-11-26 12:36:36 +01:00
/**
* Attempt a connection to mail server
*
* @ return mixed $_retVal Boolean indicating success or failure on connection
*/
function _server_connect ()
{
2018-09-06 21:27:18 +02:00
// phpcs:enable
2011-11-26 12:36:36 +01:00
// Default return value
$_retVal = true ;
// We have to make sure the HOST given is valid
// This is done here because '@fsockopen' will not give me this
// information if it failes to connect because it can't find the HOST
$host = $this -> getHost ();
2017-08-24 02:02:00 +02:00
$usetls = preg_match ( '@tls://@i' , $host );
2011-11-26 12:36:36 +01:00
$host = preg_replace ( '@tcp://@i' , '' , $host ); // Remove prefix
$host = preg_replace ( '@ssl://@i' , '' , $host ); // Remove prefix
2017-08-24 02:02:00 +02:00
$host = preg_replace ( '@tls://@i' , '' , $host ); // Remove prefix
2011-11-26 12:36:36 +01:00
2017-07-17 20:09:19 +02:00
// @CHANGE LDR
2012-08-23 02:04:35 +02:00
include_once DOL_DOCUMENT_ROOT . '/core/lib/functions2.lib.php' ;
2011-11-26 12:36:36 +01:00
2012-01-04 14:05:49 +01:00
if ( ( ! is_ip ( $host )) && (( gethostbyname ( $host )) == $host ))
2011-11-26 12:36:36 +01:00
{
$this -> _setErr ( 99 , $host . ' is either offline or is an invalid host name.' );
$_retVal = false ;
}
else
{
//See if we can connect to the SMTP server
2012-01-04 14:05:49 +01:00
if ( $this -> socket = @ fsockopen (
2017-08-24 02:02:00 +02:00
preg_replace ( '@tls://@i' , '' , $this -> getHost ()), // Host to 'hit', IP or domain
2012-01-04 14:05:49 +01:00
$this -> getPort (), // which Port number to use
$this -> errno , // actual system level error
$this -> errstr , // and any text that goes with the error
$this -> _smtpTimeout
)) // timeout for reading/writing data over the socket
2011-11-26 12:36:36 +01:00
{
// Fix from PHP SMTP class by 'Chris Ryan'
// Sometimes the SMTP server takes a little longer to respond
// so we will give it a longer timeout for the first read
// Windows still does not have support for this timeout function
if ( function_exists ( 'stream_set_timeout' )) stream_set_timeout ( $this -> socket , $this -> _smtpTimeout , 0 );
// Check response from Server
if ( $_retVal = $this -> server_parse ( $this -> socket , " 220 " ) )
$_retVal = $this -> socket ;
}
// This connection attempt failed.
else
{
2017-07-17 20:09:19 +02:00
// @CHANGE LDR
2011-11-26 12:36:36 +01:00
if ( empty ( $this -> errstr )) $this -> errstr = 'Failed to connect with fsockopen host=' . $this -> getHost () . ' port=' . $this -> getPort ();
$this -> _setErr ( $this -> errno , $this -> errstr );
$_retVal = false ;
}
}
return $_retVal ;
}
2018-09-06 21:27:18 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
2011-11-26 12:36:36 +01:00
/**
* Attempt mail server authentication for a secure connection
*
2016-04-09 15:07:33 +02:00
* @ return boolean | null $_retVal Boolean indicating success or failure of authentication
2011-11-26 12:36:36 +01:00
*/
function _server_authenticate ()
{
2018-09-06 21:27:18 +02:00
// phpcs:enable
2016-03-16 01:54:45 +01:00
global $conf ;
2017-07-18 12:49:19 +02:00
2011-11-26 12:36:36 +01:00
// Send the RFC2554 specified EHLO.
// This improvment as provided by 'SirSir' to
// accomodate both SMTP AND ESMTP capable servers
$host = $this -> getHost ();
2017-08-24 02:02:00 +02:00
$usetls = preg_match ( '@tls://@i' , $host );
2011-11-26 12:36:36 +01:00
$host = preg_replace ( '@tcp://@i' , '' , $host ); // Remove prefix
$host = preg_replace ( '@ssl://@i' , '' , $host ); // Remove prefix
2017-08-24 02:02:00 +02:00
$host = preg_replace ( '@tls://@i' , '' , $host ); // Remove prefix
if ( $usetls ) $host = 'tls://' . $host ;
2017-12-03 20:18:00 +01:00
$hosth = $host ;
2017-12-03 20:15:04 +01:00
if ( ! empty ( $conf -> global -> MAIL_SMTP_USE_FROM_FOR_HELO ))
{
// If the from to is 'aaa <bbb@ccc.com>', we will keep 'ccc.com'
2017-12-03 20:18:00 +01:00
$hosth = $this -> getFrom ( 'addr' );
$hosth = preg_replace ( '/^.*</' , '' , $hosth );
$hosth = preg_replace ( '/>.*$/' , '' , $hosth );
$hosth = preg_replace ( '/.*@/' , '' , $hosth );
2017-12-03 20:15:04 +01:00
}
2017-12-03 20:18:00 +01:00
if ( $_retVal = $this -> socket_send_str ( 'EHLO ' . $hosth , '250' ) )
2011-11-26 12:36:36 +01:00
{
2017-08-24 02:02:00 +02:00
if ( $usetls )
2016-03-16 01:54:45 +01:00
{
2017-03-18 19:56:53 +01:00
/*
The following dialog illustrates how a client and server can start a TLS STARTTLS session
S : < waits for connection on TCP port 25 >
C : < opens connection >
S : 220 mail . imc . org SMTP service ready
C : EHLO mail . ietf . org
S : 250 - mail . imc . org offers a warm hug of welcome
S : 250 STARTTLS
C : STARTTLS
S : 220 Go ahead
C : < starts TLS negotiation >
C & S : < negotiate a TLS session >
C & S : < check result of negotiation >
// Second pass EHLO
C : EHLO client - domain . com
S : 250 - server - domain . com
2017-08-24 02:02:00 +02:00
S : 250 AUTH LOGIN
2017-03-18 19:56:53 +01:00
C : < continues by sending an SMTP command
*/
2016-03-16 01:54:45 +01:00
if ( ! $_retVal = $this -> socket_send_str ( 'STARTTLS' , 220 ))
{
$this -> _setErr ( 131 , 'STARTTLS connection is not supported.' );
return $_retVal ;
}
2017-08-28 00:06:19 +02:00
// Before 5.6.7:
// STREAM_CRYPTO_METHOD_SSLv23_CLIENT = STREAM_CRYPTO_METHOD_SSLv2_CLIENT|STREAM_CRYPTO_METHOD_SSLv3_CLIENT
// STREAM_CRYPTO_METHOD_TLS_CLIENT = STREAM_CRYPTO_METHOD_TLSv1_0_CLIENT|STREAM_CRYPTO_METHOD_TLSv1_1_CLIENT|STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT
// PHP >= 5.6.7:
// STREAM_CRYPTO_METHOD_SSLv23_CLIENT = STREAM_CRYPTO_METHOD_TLSv1_0_CLIENT|STREAM_CRYPTO_METHOD_TLSv1_1_CLIENT|STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT
// STREAM_CRYPTO_METHOD_TLS_CLIENT = STREAM_CRYPTO_METHOD_TLSv1_0_CLIENT
$crypto_method = STREAM_CRYPTO_METHOD_TLS_CLIENT ;
if ( defined ( 'STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT' )) {
$crypto_method |= STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT ;
$crypto_method |= STREAM_CRYPTO_METHOD_TLSv1_1_CLIENT ;
}
if ( ! stream_socket_enable_crypto ( $this -> socket , true , $crypto_method ))
2016-03-16 01:54:45 +01:00
{
$this -> _setErr ( 132 , 'STARTTLS connection failed.' );
return $_retVal ;
}
2017-08-24 02:02:00 +02:00
// Most server servers expect a 2nd pass of EHLO after TLS is established to get another time
2017-03-18 19:56:53 +01:00
// the answer with list of supported AUTH methods. They may differs between non STARTTLS and with STARTTLS.
2016-03-16 01:54:45 +01:00
if ( ! $_retVal = $this -> socket_send_str ( 'EHLO ' . $host , '250' ))
{
$this -> _setErr ( 126 , '"' . $host . '" does not support authenticated connections.' );
return $_retVal ;
2017-07-18 12:49:19 +02:00
}
2016-03-16 01:54:45 +01:00
}
2011-11-26 12:36:36 +01:00
// Send Authentication to Server
// Check for errors along the way
$this -> socket_send_str ( 'AUTH LOGIN' , '334' );
// User name will not return any error, server will take anything we give it.
$this -> socket_send_str ( base64_encode ( $this -> _smtpsID ), '334' );
// The error here just means the ID/password combo doesn't work.
// There is not a method to determine which is the problem, ID or password
if ( ! $_retVal = $this -> socket_send_str ( base64_encode ( $this -> _smtpsPW ), '235' ) )
$this -> _setErr ( 130 , 'Invalid Authentication Credentials.' );
}
else
{
$this -> _setErr ( 126 , '"' . $host . '" does not support authenticated connections.' );
}
return $_retVal ;
}
/**
* Now send the message
*
* @ param boolean $_bolTestMsg whether to run this method in 'Test' mode .
* @ param boolean $_bolDebug whether to log all communication between this Class and the Mail Server .
2016-04-09 15:07:33 +02:00
* @ return boolean | null void
2011-11-26 12:36:36 +01:00
* $_strMsg If this is run in 'Test' mode , the actual message structure will be returned
*/
2012-01-04 14:05:49 +01:00
function sendMsg ( $_bolTestMsg = false , $_bolDebug = false )
2011-11-26 12:36:36 +01:00
{
2017-12-03 20:08:53 +01:00
global $conf ;
2011-11-26 12:36:36 +01:00
/**
* Default return value
*/
$_retVal = false ;
// Connect to Server
if ( $this -> socket = $this -> _server_connect () )
{
// If a User ID *and* a password is given, assume Authentication is desired
if ( ! empty ( $this -> _smtpsID ) && ! empty ( $this -> _smtpsPW ) )
{
// Send the RFC2554 specified EHLO.
$_retVal = $this -> _server_authenticate ();
}
// This is a "normal" SMTP Server "handshack"
else
{
// Send the RFC821 specified HELO.
$host = $this -> getHost ();
2017-08-24 02:02:00 +02:00
$usetls = preg_match ( '@tls://@i' , $host );
2011-11-26 12:36:36 +01:00
$host = preg_replace ( '@tcp://@i' , '' , $host ); // Remove prefix
$host = preg_replace ( '@ssl://@i' , '' , $host ); // Remove prefix
2017-08-24 02:02:00 +02:00
$host = preg_replace ( '@tls://@i' , '' , $host ); // Remove prefix
2017-12-03 20:18:00 +01:00
$hosth = $host ;
2017-12-03 20:15:04 +01:00
2017-12-03 20:08:53 +01:00
if ( ! empty ( $conf -> global -> MAIL_SMTP_USE_FROM_FOR_HELO ))
{
// If the from to is 'aaa <bbb@ccc.com>', we will keep 'ccc.com'
2017-12-03 20:18:00 +01:00
$hosth = $this -> getFrom ( 'addr' );
$hosth = preg_replace ( '/^.*</' , '' , $hosth );
$hosth = preg_replace ( '/>.*$/' , '' , $hosth );
$hosth = preg_replace ( '/.*@/' , '' , $hosth );
2017-12-03 20:08:53 +01:00
}
2017-12-03 20:18:00 +01:00
$_retVal = $this -> socket_send_str ( 'HELO ' . $hosth , '250' );
2011-11-26 12:36:36 +01:00
}
// Well, did we get to the server?
if ( $_retVal )
{
// From this point onward most server response codes should be 250
// Specify who the mail is from....
// This has to be the raw email address, strip the "name" off
2012-01-04 14:05:49 +01:00
$this -> socket_send_str ( 'MAIL FROM: ' . $this -> getFrom ( 'addr' ), '250' );
2011-11-26 12:36:36 +01:00
// 'RCPT TO:' must be given a single address, so this has to loop
// through the list of addresses, regardless of TO, CC or BCC
// and send it out "single file"
foreach ( $this -> get_RCPT_list () as $_address )
{
2016-11-09 00:10:02 +01:00
/* Note :
* BCC email addresses must be listed in the RCPT TO command list ,
* but the BCC header should not be printed under the DATA command .
* http :// stackoverflow . com / questions / 2750211 / sending - bcc - emails - using - a - smtp - server
*/
/*
2011-11-26 12:36:36 +01:00
* TODO
2016-11-09 00:10:02 +01:00
* After each 'RCPT TO:' is sent , we need to make sure it was kosher ,
* if not , the whole message will fail
* If any email address fails , we will need to RESET the connection ,
* mark the last address as " bad " and start the address loop over again .
* If any address fails , the entire message fails .
*/
2011-11-26 12:36:36 +01:00
$this -> socket_send_str ( 'RCPT TO: <' . $_address . '>' , '250' );
}
// Tell the server we are ready to start sending data
// with any custom headers...
// This is the last response code we look for until the end of the message.
$this -> socket_send_str ( 'DATA' , '354' );
// Now we are ready for the message...
// Ok, all the ingredients are mixed in let's cook this puppy...
$this -> socket_send_str ( $this -> getHeader () . $this -> getBodyContent () . " \r \n " . '.' , '250' );
// Now tell the server we are done and close the socket...
fputs ( $this -> socket , 'QUIT' );
2012-01-04 14:05:49 +01:00
fclose ( $this -> socket );
2011-11-26 12:36:36 +01:00
}
}
return $_retVal ;
}
// =============================================================
// ** Setter & Getter methods
// ** Basic System configuration
/**
* setConfig () is used to populate select class properties from either
* a user defined INI file or the systems 'php.ini' file
*
* If a user defined INI is to be used , the files complete path is passed
* as the method single parameter . The INI can define any class and / or
* user properties . Only properties defined within this file will be setter
* and / or orverwritten
*
* If the systems 'php.ini' file is to be used , the method is called without
* parameters . In this case , only HOST , PORT and FROM properties will be set
* as they are the only properties that are defined within the 'php.ini' .
*
* If secure SMTP is to be used , the user ID and Password can be defined with
* the user INI file , but the properties are not defined with the systems
* 'php.ini' file , they must be defined via their setter methods
*
* This method can be called twice , if desired . Once without a parameter to
* load the properties as defined within the systems 'php.ini' file , and a
* second time , with a path to a user INI file for other properties to be
* defined .
*
* @ param mixed $_strConfigPath path to config file or VOID
2016-04-09 15:07:33 +02:00
* @ return boolean
2011-11-26 12:36:36 +01:00
*/
2015-08-20 15:07:16 +02:00
function setConfig ( $_strConfigPath = null )
2011-11-26 12:36:36 +01:00
{
/**
* Returns constructed SELECT Object string or boolean upon failure
2018-04-16 13:51:16 +02:00
* Default value is set at true
2011-11-26 12:36:36 +01:00
*/
$_retVal = true ;
// if we have a path...
if ( ! empty ( $_strConfigPath ) )
{
// If the path is not valid, this will NOT generate an error,
2018-04-16 13:51:16 +02:00
// it will simply return false.
2018-07-26 11:57:25 +02:00
if ( ! @ include $_strConfigPath )
2011-11-26 12:36:36 +01:00
{
$this -> _setErr ( 110 , '"' . $_strConfigPath . '" is not a valid path.' );
$_retVal = false ;
}
}
// Read the Systems php.ini file
else
{
// Set these properties ONLY if they are set in the php.ini file.
// Otherwise the default values will be used.
2012-01-04 14:05:49 +01:00
if ( $_host = ini_get ( 'SMTPs' ) )
2011-11-26 12:36:36 +01:00
$this -> setHost ( $_host );
2012-01-04 14:05:49 +01:00
if ( $_port = ini_get ( 'smtp_port' ) )
2011-11-26 12:36:36 +01:00
$this -> setPort ( $_port );
2012-01-04 14:05:49 +01:00
if ( $_from = ini_get ( 'sendmail_from' ) )
2011-11-26 12:36:36 +01:00
$this -> setFrom ( $_from );
}
// Send back what we have
return $_retVal ;
}
/**
* Determines the method inwhich the messages are to be sent .
* - 'sockets' [ 0 ] - conect via network to SMTP server
* - ' pipe [ 1 ] - use UNIX path to EXE
* - ' phpmail [ 2 ] - use the PHP built - in mail function
*
* @ param int $_type Interger value representing Mail Transport Type
* @ return void
*/
function setTransportType ( $_type = 0 )
{
2012-01-04 14:05:49 +01:00
if ( ( is_numeric ( $_type ) ) &&
2011-11-26 12:36:36 +01:00
( ( $_type >= 0 ) && ( $_type <= 3 ) ) )
$this -> _transportType = $_type ;
}
/**
* Return the method inwhich the message is to be sent .
* - 'sockets' [ 0 ] - conect via network to SMTP server
* - ' pipe [ 1 ] - use UNIX path to EXE
* - ' phpmail [ 2 ] - use the PHP built - in mail function
*
* @ return int $_strHost Host Name or IP of the Mail Server to use
*/
function getTransportType ()
{
return $this -> _transportType ;
}
/**
* Path to the sendmail execuable
*
* @ param string $_path Path to the sendmail execuable
2016-04-09 15:07:33 +02:00
* @ return boolean
2011-11-26 12:36:36 +01:00
*
*/
function setMailPath ( $_path )
{
// This feature is not yet implemented
return true ;
2011-12-01 17:09:01 +01:00
//if ( $_path ) $this->_mailPath = $_path;
2011-11-26 12:36:36 +01:00
}
/**
* Defines the Host Name or IP of the Mail Server to use .
* This is defaulted to 'localhost'
* This is used only with 'socket' based mail transmission
*
* @ param string $_strHost Host Name or IP of the Mail Server to use
* @ return void
*/
function setHost ( $_strHost )
{
if ( $_strHost )
$this -> _smtpsHost = $_strHost ;
}
/**
* Retrieves the Host Name or IP of the Mail Server to use
* This is used only with 'socket' based mail transmission
*
* @ return string $_strHost Host Name or IP of the Mail Server to use
*/
function getHost ()
{
return $this -> _smtpsHost ;
}
/**
* Defines the Port Number of the Mail Server to use
* This is defaulted to '25'
* This is used only with 'socket' based mail transmission
*
* @ param int $_intPort Port Number of the Mail Server to use
* @ return void
*/
function setPort ( $_intPort )
{
2012-01-04 14:05:49 +01:00
if ( ( is_numeric ( $_intPort ) ) &&
2011-11-26 12:36:36 +01:00
( ( $_intPort >= 1 ) && ( $_intPort <= 65536 ) ) )
$this -> _smtpsPort = $_intPort ;
}
/**
* Retrieves the Port Number of the Mail Server to use
* This is used only with 'socket' based mail transmission
*
* @ return string Port Number of the Mail Server to use
*/
function getPort ()
{
return $this -> _smtpsPort ;
}
/**
* User Name for authentication on Mail Server
*
* @ param string $_strID User Name for authentication on Mail Server
* @ return void
*/
function setID ( $_strID )
{
$this -> _smtpsID = $_strID ;
}
/**
* Retrieves the User Name for authentication on Mail Server
*
* @ return string User Name for authentication on Mail Server
*/
function getID ()
{
return $this -> _smtpsID ;
}
/**
* User Password for authentication on Mail Server
*
* @ param string $_strPW User Password for authentication on Mail Server
* @ return void
*/
function setPW ( $_strPW )
{
$this -> _smtpsPW = $_strPW ;
}
/**
* Retrieves the User Password for authentication on Mail Server
*
* @ return string User Password for authentication on Mail Server
*/
function getPW ()
{
return $this -> _smtpsPW ;
}
/**
* Character set used for current message
* Character set is defaulted to 'iso-8859-1' ;
*
* @ param string $_strCharSet Character set used for current message
* @ return void
*/
function setCharSet ( $_strCharSet )
{
if ( $_strCharSet )
$this -> _smtpsCharSet = $_strCharSet ;
}
/**
* Retrieves the Character set used for current message
*
* @ return string $_smtpsCharSet Character set used for current message
*/
function getCharSet ()
{
return $this -> _smtpsCharSet ;
}
/**
* Content - Transfer - Encoding , Defaulted to '7bit'
* This can be changed for 2 byte characers sets
* Known Encode Types
* - 7 bit Simple 7 - bit ASCII
* - 8 bit 8 - bit coding with line termination characters
* - base64 3 octets encoded into 4 sextets with offset
* - binary Arbitrary binary stream
* - mac - binhex40 Macintosh binary to hex encoding
* - quoted - printable Mostly 7 - bit , with 8 - bit characters encoded as " =HH "
* - uuencode UUENCODE encoding
*
* @ param string $_strTransEncode Content - Transfer - Encoding
* @ return void
*/
2015-08-20 15:07:16 +02:00
function setTransEncode ( $_strTransEncode )
2011-11-26 12:36:36 +01:00
{
2012-01-04 14:05:49 +01:00
if ( array_search ( $_strTransEncode , $this -> _smtpsTransEncodeTypes ))
2011-11-26 12:36:36 +01:00
$this -> _smtpsTransEncode = $_strTransEncode ;
}
/**
* Retrieves the Content - Transfer - Encoding
*
* @ return string $_smtpsTransEncode Content - Transfer - Encoding
*/
function getTransEncode ()
{
return $this -> _smtpsTransEncode ;
}
/**
* Content - Transfer - Encoding , Defaulted to '0' [ ZERO ]
* This can be changed for 2 byte characers sets
* Known Encode Types
* - [ 0 ] 7 bit Simple 7 - bit ASCII
* - [ 1 ] 8 bit 8 - bit coding with line termination characters
* - [ 2 ] base64 3 octets encoded into 4 sextets with offset
* - [ 3 ] binary Arbitrary binary stream
* - [ 4 ] mac - binhex40 Macintosh binary to hex encoding
* - [ 5 ] quoted - printable Mostly 7 - bit , with 8 - bit characters encoded as " =HH "
* - [ 6 ] uuencode UUENCODE encoding
*
* @ param string $_strTransEncodeType Content - Transfer - Encoding
* @ return void
*
*/
function setTransEncodeType ( $_strTransEncodeType )
{
if ( array_search ( $_strTransEncodeType , $this -> _smtpsTransEncodeTypes ))
$this -> _smtpsTransEncodeType = $_strTransEncodeType ;
}
/**
* Retrieves the Content - Transfer - Encoding
*
* @ return string Content - Transfer - Encoding
*/
function getTransEncodeType ()
{
return $this -> _smtpsTransEncodeTypes [ $this -> _smtpsTransEncodeType ];
}
// ** Message Construction
/**
* FROM Address from which mail will be sent
*
* @ param string $_strFrom Address from which mail will be sent
* @ return void
*/
function setFrom ( $_strFrom )
{
if ( $_strFrom )
$this -> _msgFrom = $this -> _strip_email ( $_strFrom );
}
/**
* Retrieves the Address from which mail will be sent
*
* @ param boolean $_part To " strip " 'Real name' from address
* @ return string Address from which mail will be sent
*/
function getFrom ( $_part = true )
{
$_retValue = '' ;
if ( $_part === true )
$_retValue = $this -> _msgFrom ;
else
$_retValue = $this -> _msgFrom [ $_part ];
return $_retValue ;
}
2016-02-09 11:56:12 +01:00
/**
* Reply - To Address from which mail will be the reply - to
*
* @ param string $_strReplyTo Address from which mail will be the reply - to
* @ return void
*/
function setReplyTo ( $_strReplyTo )
{
if ( $_strReplyTo )
$this -> _msgReplyTo = $this -> _strip_email ( $_strReplyTo );
}
2017-07-18 12:49:19 +02:00
2016-02-09 11:56:12 +01:00
/**
* Retrieves the Address from which mail will be the reply - to
*
* @ param boolean $_part To " strip " 'Real name' from address
* @ return string Address from which mail will be the reply - to
*/
function getReplyTo ( $_part = true )
{
$_retValue = '' ;
2017-07-18 12:49:19 +02:00
2016-02-09 11:56:12 +01:00
if ( $_part === true )
$_retValue = $this -> _msgReplyTo ;
else
$_retValue = $this -> _msgReplyTo [ $_part ];
2017-07-18 12:49:19 +02:00
2016-02-09 11:56:12 +01:00
return $_retValue ;
}
2017-07-18 12:49:19 +02:00
2011-11-26 12:36:36 +01:00
/**
* Inserts given addresses into structured format .
* This method takes a list of given addresses , via an array
* or a COMMA delimted string , and inserts them into a highly
* structured array . This array is designed to remove duplicate
* addresses and to sort them by Domain .
*
* @ param string $_type TO , CC , or BCC lists to add addrresses into
* @ param mixed $_addrList Array or COMMA delimited string of addresses
* @ return void
*
*/
2015-08-20 15:07:16 +02:00
function _buildAddrList ( $_type , $_addrList )
2011-11-26 12:36:36 +01:00
{
// Pull existing list
$aryHost = $this -> _msgRecipients ;
// Only run this if we have something
if ( ! empty ( $_addrList ))
{
// $_addrList can be a STRING or an array
2012-01-04 14:05:49 +01:00
if ( is_string ( $_addrList ) )
2011-11-26 12:36:36 +01:00
{
// This could be a COMMA delimited string
2012-01-04 14:05:49 +01:00
if ( strstr ( $_addrList , ',' ) )
2011-11-26 12:36:36 +01:00
// "explode "list" into an array
2012-01-04 14:05:49 +01:00
$_addrList = explode ( ',' , $_addrList );
2011-11-26 12:36:36 +01:00
// Stick it in an array
else
$_addrList = array ( $_addrList );
}
// take the array of addresses and split them further
foreach ( $_addrList as $_strAddr )
{
// Strip off the end '>'
2012-01-04 14:05:49 +01:00
$_strAddr = str_replace ( '>' , '' , $_strAddr );
2011-11-26 12:36:36 +01:00
// Seperate "Real Name" from eMail address
$_tmpaddr = null ;
2012-01-04 14:05:49 +01:00
$_tmpaddr = explode ( '<' , $_strAddr );
2011-11-26 12:36:36 +01:00
// We have a "Real Name" and eMail address
2012-01-04 14:05:49 +01:00
if ( count ( $_tmpaddr ) == 2 )
2011-11-26 12:36:36 +01:00
{
2012-01-04 14:05:49 +01:00
$_tmpHost = explode ( '@' , $_tmpaddr [ 1 ]);
$_tmpaddr [ 0 ] = trim ( $_tmpaddr [ 0 ], ' ">' );
2011-11-26 12:36:36 +01:00
$aryHost [ $_tmpHost [ 1 ]][ $_type ][ $_tmpHost [ 0 ]] = $_tmpaddr [ 0 ];
}
// We only have an eMail address
else
{
// Strip off the beggining '<'
2012-01-04 14:05:49 +01:00
$_strAddr = str_replace ( '<' , '' , $_strAddr );
2011-11-26 12:36:36 +01:00
2012-01-04 14:05:49 +01:00
$_tmpHost = explode ( '@' , $_strAddr );
$_tmpHost [ 0 ] = trim ( $_tmpHost [ 0 ]);
$_tmpHost [ 1 ] = trim ( $_tmpHost [ 1 ]);
2011-11-26 12:36:36 +01:00
$aryHost [ $_tmpHost [ 1 ]][ $_type ][ $_tmpHost [ 0 ]] = '' ;
}
}
}
// replace list
$this -> _msgRecipients = $aryHost ;
}
2018-09-06 21:27:18 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
2011-11-26 12:36:36 +01:00
/**
* Returns an array of the various parts of an email address
* This assumes a well formed address :
* - " Real name " < username @ domain . tld >
* - " Real Name " is optional
* - if " Real Name " does not exist , the angle brackets are optional
* This will split an email address into 4 or 5 parts .
* - $_aryEmail [ org ] = orignal string
* - $_aryEmail [ real ] = " real name " - if there is one
* - $_aryEmail [ addr ] = address part " username@domain.tld "
* - $_aryEmail [ host ] = " domain.tld "
* - $_aryEmail [ user ] = " userName "
*
* @ param string $_strAddr Email address
* @ return array An array of the various parts of an email address
*/
function _strip_email ( $_strAddr )
{
2018-09-06 21:27:18 +02:00
// phpcs:enable
2011-11-26 12:36:36 +01:00
// Keep the orginal
$_aryEmail [ 'org' ] = $_strAddr ;
// Set entire string to Lower Case
2012-01-04 14:05:49 +01:00
$_strAddr = strtolower ( $_strAddr );
2011-11-26 12:36:36 +01:00
// Drop "stuff' off the end
2012-01-04 14:05:49 +01:00
$_strAddr = trim ( $_strAddr , ' ">' );
2011-11-26 12:36:36 +01:00
// Seperate "Real Name" from eMail address, if we have one
2012-01-04 14:05:49 +01:00
$_tmpAry = explode ( '<' , $_strAddr );
2011-11-26 12:36:36 +01:00
// Do we have a "Real name"
2012-01-04 14:05:49 +01:00
if ( count ( $_tmpAry ) == 2 )
2011-11-26 12:36:36 +01:00
{
// We may not really have a "Real Name"
if ( $_tmpAry [ 0 ])
2012-01-04 14:05:49 +01:00
$_aryEmail [ 'real' ] = trim ( $_tmpAry [ 0 ], ' ">' );
2011-11-26 12:36:36 +01:00
$_aryEmail [ 'addr' ] = $_tmpAry [ 1 ];
}
else
$_aryEmail [ 'addr' ] = $_tmpAry [ 0 ];
// Pull User Name and Host.tld apart
2012-01-04 14:05:49 +01:00
list ( $_aryEmail [ 'user' ], $_aryEmail [ 'host' ] ) = explode ( '@' , $_aryEmail [ 'addr' ]);
2011-11-26 12:36:36 +01:00
// Put the brackets back around the address
$_aryEmail [ 'addr' ] = '<' . $_aryEmail [ 'addr' ] . '>' ;
return $_aryEmail ;
}
2018-09-06 21:27:18 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
2011-11-26 12:36:36 +01:00
/**
* Returns an array of bares addresses for use with 'RCPT TO:'
* This is a " build as you go " method . Each time this method is called
* the underlaying array is destroyed and reconstructed .
*
* @ return array Returns an array of bares addresses
*/
function get_RCPT_list ()
{
2018-09-06 21:27:18 +02:00
// phpcs:enable
2011-11-26 12:36:36 +01:00
/**
* An array of bares addresses for use with 'RCPT TO:'
*/
2011-12-01 17:09:01 +01:00
$_RCPT_list = array ();
2011-11-26 12:36:36 +01:00
// walk down Recipients array and pull just email addresses
foreach ( $this -> _msgRecipients as $_host => $_list )
{
foreach ( $_list as $_subList )
{
foreach ( $_subList as $_name => $_addr )
{
// build RCPT list
$_RCPT_list [] = $_name . '@' . $_host ;
}
}
}
return $_RCPT_list ;
}
2018-09-06 21:27:18 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
2011-11-26 12:36:36 +01:00
/**
* Returns an array of addresses for a specific type ; TO , CC or BCC
*
2016-11-09 00:10:02 +01:00
* @ param string $_which Which collection of addresses to return ( 'to' , 'cc' , 'bcc' )
2016-04-09 15:07:33 +02:00
* @ return string | false Array of emaill address
2011-11-26 12:36:36 +01:00
*/
function get_email_list ( $_which = null )
{
2018-09-06 21:27:18 +02:00
// phpcs:enable
2011-11-26 12:36:36 +01:00
// We need to know which address segment to pull
if ( $_which )
{
// Make sure we have addresses to process
if ( $this -> _msgRecipients )
{
$_RCPT_list = array ();
// walk down Recipients array and pull just email addresses
foreach ( $this -> _msgRecipients as $_host => $_list )
{
if ( $this -> _msgRecipients [ $_host ][ $_which ] )
{
foreach ( $this -> _msgRecipients [ $_host ][ $_which ] as $_addr => $_realName )
{
2017-07-17 20:09:19 +02:00
if ( $_realName ) // @CHANGE LDR
2011-11-26 12:36:36 +01:00
{
$_realName = '"' . $_realName . '"' ;
$_RCPT_list [] = $_realName . ' <' . $_addr . '@' . $_host . '>' ;
}
else
{
$_RCPT_list [] = $_addr . '@' . $_host ;
}
}
}
}
return implode ( ', ' , $_RCPT_list );
}
else
{
$this -> _setErr ( 101 , 'No eMail Address for message to be sent to.' );
return false ;
}
}
else
{
$this -> _setErr ( 102 , 'eMail type not defined.' );
return false ;
}
}
/**
* TO Address [ es ] inwhich to send mail to
*
2016-04-09 15:07:33 +02:00
* @ param string $_addrTo TO Address [ es ] inwhich to send mail to
2011-11-26 12:36:36 +01:00
* @ return void
*/
function setTO ( $_addrTo )
{
if ( $_addrTo )
$this -> _buildAddrList ( 'to' , $_addrTo );
}
/**
* Retrieves the TO Address [ es ] inwhich to send mail to
*
* @ return string TO Address [ es ] inwhich to send mail to
*/
function getTo ()
{
return $this -> get_email_list ( 'to' );
}
/**
* CC Address [ es ] inwhich to send mail to
*
* @ param string $_strCC CC Address [ es ] inwhich to send mail to
* @ return void
*/
function setCC ( $_strCC )
{
if ( $_strCC )
$this -> _buildAddrList ( 'cc' , $_strCC );
}
/**
* Retrieves the CC Address [ es ] inwhich to send mail to
*
* @ return string CC Address [ es ] inwhich to send mail to
*/
function getCC ()
{
return $this -> get_email_list ( 'cc' );
}
/**
* BCC Address [ es ] inwhich to send mail to
*
* @ param string $_strBCC Recipients BCC Address [ es ] inwhich to send mail to
* @ return void
*/
function setBCC ( $_strBCC )
{
if ( $_strBCC )
$this -> _buildAddrList ( 'bcc' , $_strBCC );
}
/**
* Retrieves the BCC Address [ es ] inwhich to send mail to
*
* @ return string BCC Address [ es ] inwhich to send mail to
*/
function getBCC ()
{
return $this -> get_email_list ( 'bcc' );
}
/**
* Message Subject
*
* @ param string $_strSubject Message Subject
* @ return void
*/
function setSubject ( $_strSubject = '' )
{
if ( $_strSubject )
$this -> _msgSubject = $_strSubject ;
}
/**
* Retrieves the Message Subject
*
* @ return string Message Subject
*/
function getSubject ()
{
return $this -> _msgSubject ;
}
/**
* Constructes and returns message header
*
* @ return string Complete message header
*/
function getHeader ()
{
2017-07-18 12:49:19 +02:00
global $conf ;
2012-01-04 14:05:49 +01:00
$_header = 'From: ' . $this -> getFrom ( 'org' ) . " \r \n "
2011-11-26 12:36:36 +01:00
. 'To: ' . $this -> getTO () . " \r \n " ;
if ( $this -> getCC () )
$_header .= 'Cc: ' . $this -> getCC () . " \r \n " ;
2016-11-09 00:10:02 +01:00
/* Note :
* BCC email addresses must be listed in the RCPT TO command list ,
* but the BCC header should not be printed under the DATA command .
* So it is included into the function sendMsg () but not here .
* http :// stackoverflow . com / questions / 2750211 / sending - bcc - emails - using - a - smtp - server
*/
/*
2011-11-26 12:36:36 +01:00
if ( $this -> getBCC () )
$_header .= 'Bcc: ' . $this -> getBCC () . " \r \n " ;
2016-11-09 00:10:02 +01:00
*/
2017-07-18 12:49:19 +02:00
2011-11-26 12:36:36 +01:00
$host = $this -> getHost ();
2017-08-24 02:02:00 +02:00
$usetls = preg_match ( '@tls://@i' , $host );
2011-11-26 12:36:36 +01:00
$host = preg_replace ( '@tcp://@i' , '' , $host ); // Remove prefix
$host = preg_replace ( '@ssl://@i' , '' , $host ); // Remove prefix
2017-08-24 02:02:00 +02:00
$host = preg_replace ( '@tls://@i' , '' , $host ); // Remove prefix
2011-11-26 12:36:36 +01:00
2017-01-14 13:27:44 +01:00
$host = dol_getprefix ( 'email' );
2017-07-18 12:49:19 +02:00
2011-11-26 12:36:36 +01:00
//NOTE: Message-ID should probably contain the username of the user who sent the msg
2015-05-05 04:10:42 +02:00
$_header .= 'Subject: ' . $this -> getSubject () . " \r \n " ;
$_header .= 'Date: ' . date ( " r " ) . " \r \n " ;
$trackid = $this -> getTrackId ();
if ( $trackid )
{
2015-11-13 00:19:11 +01:00
// References is kept in response and Message-ID is returned into In-Reply-To:
$_header .= 'Message-ID: <' . time () . '.SMTPs-dolibarr-' . $trackid . '@' . $host . " > \r \n " ;
$_header .= 'References: <' . time () . '.SMTPs-dolibarr-' . $trackid . '@' . $host . " > \r \n " ;
2018-11-16 16:43:13 +01:00
$_header .= 'X-Dolibarr-TRACKID: ' . $trackid . '@' . $host . " \r \n " ;
2015-05-05 04:10:42 +02:00
}
else
{
$_header .= 'Message-ID: <' . time () . '.SMTPs@' . $host . " > \r \n " ;
}
2017-11-21 14:05:29 +01:00
if ( ! empty ( $_SERVER [ 'REMOTE_ADDR' ])) $_header .= " X-RemoteAddr: " . $_SERVER [ 'REMOTE_ADDR' ] . " \r \n " ;
2016-12-20 12:38:24 +01:00
if ( $this -> getMoreInHeader () )
$_header .= $this -> getMoreInHeader (); // Value must include the "\r\n";
2017-07-18 12:49:19 +02:00
2015-05-05 04:10:42 +02:00
//$_header .=
// 'Read-Receipt-To: ' . $this->getFrom( 'org' ) . "\r\n"
// 'Return-Receipt-To: ' . $this->getFrom( 'org' ) . "\r\n";
2011-11-26 12:36:36 +01:00
if ( $this -> getSensitivity () )
$_header .= 'Sensitivity: ' . $this -> getSensitivity () . " \r \n " ;
if ( $this -> _msgPriority != 3 )
$_header .= $this -> getPriority ();
2017-07-17 20:09:19 +02:00
// @CHANGE LDR
2011-11-26 12:36:36 +01:00
if ( $this -> getDeliveryReceipt () )
2016-12-20 12:38:24 +01:00
$_header .= 'Disposition-Notification-To: ' . $this -> getFrom ( 'addr' ) . " \r \n " ;
2011-11-26 12:36:36 +01:00
if ( $this -> getErrorsTo () )
2016-12-20 12:38:24 +01:00
$_header .= 'Errors-To: ' . $this -> getErrorsTo ( 'addr' ) . " \r \n " ;
2016-02-09 11:56:12 +01:00
if ( $this -> getReplyTo () )
2016-12-20 12:38:24 +01:00
$_header .= " Reply-To: " . $this -> getReplyTo ( 'addr' ) . " \r \n " ;
2011-11-26 12:36:36 +01:00
2016-12-20 12:38:24 +01:00
$_header .= 'X-Mailer: Dolibarr version ' . DOL_VERSION . ' (using SMTPs Mailer)' . " \r \n " ;
2017-07-18 12:49:19 +02:00
$_header .= 'X-Dolibarr-Option: ' . ( $conf -> global -> MAIN_MAIL_USE_MULTI_PART ? 'MAIN_MAIL_USE_MULTI_PART' : 'No MAIN_MAIL_USE_MULTI_PART' ) . " \r \n " ;
2016-12-20 12:38:24 +01:00
$_header .= 'Mime-Version: 1.0' . " \r \n " ;
2011-11-26 12:36:36 +01:00
2017-07-18 12:49:19 +02:00
2011-11-26 12:36:36 +01:00
return $_header ;
}
/**
* Message Content
*
2012-01-04 14:05:49 +01:00
* @ param string $strContent Message Content
* @ param string $strType Type
* @ return void
2011-11-26 12:36:36 +01:00
*/
2012-01-04 14:05:49 +01:00
function setBodyContent ( $strContent , $strType = 'plain' )
2011-11-26 12:36:36 +01:00
{
//if ( $strContent )
//{
if ( $strType == 'html' )
$strMimeType = 'text/html' ;
else
$strMimeType = 'text/plain' ;
// Make RFC821 Compliant, replace bare linefeeds
2012-01-04 14:05:49 +01:00
$strContent = preg_replace ( " /(?<! \r ) \n /si " , " \r \n " , $strContent );
2011-11-26 12:36:36 +01:00
2017-04-05 01:01:43 +02:00
$strContentAltText = '' ;
if ( $strType == 'html' )
{
2018-06-18 23:18:22 +02:00
// Similar code to forge a text from html is also in CMailFile.class.php
2018-06-18 23:26:21 +02:00
$strContentAltText = preg_replace ( " /<br \ s*[^>]*>/ " , " " , $strContent );
$strContentAltText = html_entity_decode ( strip_tags ( $strContentAltText ));
2017-04-05 01:01:43 +02:00
$strContentAltText = rtrim ( wordwrap ( $strContentAltText , 75 , " \r \n " ));
}
2017-07-18 12:49:19 +02:00
2016-12-19 01:04:17 +01:00
// Make RFC2045 Compliant
//$strContent = rtrim(chunk_split($strContent)); // Function chunck_split seems ko if not used on a base64 content
$strContent = rtrim ( wordwrap ( $strContent , 75 , " \r \n " )); // TODO Using this method creates unexpected line break on text/plain content.
2017-07-18 12:49:19 +02:00
2011-11-26 12:36:36 +01:00
$this -> _msgContent [ $strType ] = array ();
$this -> _msgContent [ $strType ][ 'mimeType' ] = $strMimeType ;
$this -> _msgContent [ $strType ][ 'data' ] = $strContent ;
2017-04-05 01:01:43 +02:00
$this -> _msgContent [ $strType ][ 'dataText' ] = $strContentAltText ;
2017-07-18 12:49:19 +02:00
2011-11-26 12:36:36 +01:00
if ( $this -> getMD5flag () )
2014-10-18 16:08:15 +02:00
$this -> _msgContent [ $strType ][ 'md5' ] = dol_hash ( $strContent , 3 );
2011-11-26 12:36:36 +01:00
//}
}
/**
* Retrieves the Message Content
*
* @ return string Message Content
*/
function getBodyContent ()
{
2017-04-05 01:01:43 +02:00
global $conf ;
2017-07-18 12:49:19 +02:00
2011-11-26 12:36:36 +01:00
// Generate a new Boundary string
$this -> _setBoundary ();
// What type[s] of content do we have
2012-01-04 14:05:49 +01:00
$_types = array_keys ( $this -> _msgContent );
2011-11-26 12:36:36 +01:00
// How many content types do we have
2012-01-04 14:05:49 +01:00
$keyCount = count ( $_types );
2011-11-26 12:36:36 +01:00
// If we have ZERO, we have a problem
if ( $keyCount === 0 )
die ( " Sorry, no content " );
// If we have ONE, we can use the simple format
2017-04-05 01:01:43 +02:00
else if ( $keyCount === 1 && empty ( $conf -> global -> MAIN_MAIL_USE_MULTI_PART ))
2011-11-26 12:36:36 +01:00
{
$_msgData = $this -> _msgContent ;
$_msgData = $_msgData [ $_types [ 0 ]];
$content = 'Content-Type: ' . $_msgData [ 'mimeType' ] . '; charset="' . $this -> getCharSet () . '"' . " \r \n "
. 'Content-Transfer-Encoding: ' . $this -> getTransEncodeType () . " \r \n "
. 'Content-Disposition: inline' . " \r \n "
2018-04-20 11:20:56 +02:00
. 'Content-Description: Message' . " \r \n " ;
2011-11-26 12:36:36 +01:00
if ( $this -> getMD5flag () )
$content .= 'Content-MD5: ' . $_msgData [ 'md5' ] . " \r \n " ;
$content .= " \r \n "
. $_msgData [ 'data' ] . " \r \n " ;
}
// If we have more than ONE, we use the multi-part format
2017-04-05 01:01:43 +02:00
else if ( $keyCount >= 1 || ! empty ( $conf -> global -> MAIN_MAIL_USE_MULTI_PART ))
2011-11-26 12:36:36 +01:00
{
// Since this is an actual multi-part message
// We need to define a content message Boundary
2014-02-06 20:45:50 +01:00
// NOTE: This was 'multipart/alternative', but Windows based mail servers have issues with this.
2011-11-26 12:36:36 +01:00
//$content = 'Content-Type: multipart/related; boundary="' . $this->_getBoundary() . '"' . "\r\n";
2012-06-17 18:40:45 +02:00
$content = 'Content-Type: multipart/mixed; boundary="' . $this -> _getBoundary ( 'mixed' ) . '"' . " \r \n " ;
2011-11-26 12:36:36 +01:00
// . "\r\n"
// . 'This is a multi-part message in MIME format.' . "\r\n";
2012-01-04 14:05:49 +01:00
$content .= " Content-Transfer-Encoding: 8bit \r \n " ;
2011-11-26 12:36:36 +01:00
$content .= " \r \n " ;
2012-06-17 18:40:45 +02:00
$content .= " -- " . $this -> _getBoundary ( 'mixed' ) . " \r \n " ;
2017-07-18 12:49:19 +02:00
2017-04-05 01:01:43 +02:00
if ( key_exists ( 'image' , $this -> _msgContent )) // If inline image found
2012-06-17 18:40:45 +02:00
{
2012-07-02 19:30:37 +02:00
$content .= 'Content-Type: multipart/alternative; boundary="' . $this -> _getBoundary ( 'alternative' ) . '"' . " \r \n " ;
$content .= " \r \n " ;
2012-06-17 18:40:45 +02:00
$content .= " -- " . $this -> _getBoundary ( 'alternative' ) . " \r \n " ;
}
2017-07-18 12:49:19 +02:00
2017-04-05 01:01:43 +02:00
// $this->_msgContent must be sorted with key 'text' or 'html' first then 'image' then 'attachment'
2011-11-26 12:36:36 +01:00
// Loop through message content array
foreach ( $this -> _msgContent as $type => $_content )
{
if ( $type == 'attachment' )
{
// loop through all attachments
foreach ( $_content as $_file => $_data )
{
2012-06-17 18:40:45 +02:00
$content .= " -- " . $this -> _getBoundary ( 'mixed' ) . " \r \n "
2011-11-26 12:36:36 +01:00
. 'Content-Disposition: attachment; filename="' . $_data [ 'fileName' ] . '"' . " \r \n "
. 'Content-Type: ' . $_data [ 'mimeType' ] . '; name="' . $_data [ 'fileName' ] . '"' . " \r \n "
. 'Content-Transfer-Encoding: base64' . " \r \n "
2018-04-20 11:20:56 +02:00
. 'Content-Description: ' . $_data [ 'fileName' ] . " \r \n " ;
2011-11-26 12:36:36 +01:00
if ( $this -> getMD5flag () )
$content .= 'Content-MD5: ' . $_data [ 'md5' ] . " \r \n " ;
2012-01-04 14:05:49 +01:00
$content .= " \r \n " . $_data [ 'data' ] . " \r \n \r \n " ;
2011-11-26 12:36:36 +01:00
}
}
2017-07-17 20:09:19 +02:00
// @CHANGE LDR
2011-11-26 12:36:36 +01:00
else if ( $type == 'image' )
{
// loop through all images
foreach ( $_content as $_image => $_data )
{
2012-06-17 18:40:45 +02:00
$content .= " -- " . $this -> _getBoundary ( 'related' ) . " \r \n " ; // always related for an inline image
2011-11-26 12:36:36 +01:00
$content .= 'Content-Type: ' . $_data [ 'mimeType' ] . '; name="' . $_data [ 'imageName' ] . '"' . " \r \n "
. 'Content-Transfer-Encoding: base64' . " \r \n "
. 'Content-Disposition: inline; filename="' . $_data [ 'imageName' ] . '"' . " \r \n "
. 'Content-ID: <' . $_data [ 'cid' ] . '> ' . " \r \n " ;
if ( $this -> getMD5flag () )
$content .= 'Content-MD5: ' . $_data [ 'md5' ] . " \r \n " ;
$content .= " \r \n "
. $_data [ 'data' ] . " \r \n " ;
}
2012-06-17 18:40:45 +02:00
2012-07-02 19:30:37 +02:00
// always end related and end alternative after inline images
$content .= " -- " . $this -> _getBoundary ( 'related' ) . " -- " . " \r \n " ;
$content .= " \r \n " . " -- " . $this -> _getBoundary ( 'alternative' ) . " -- " . " \r \n " ;
2012-06-17 18:40:45 +02:00
$content .= " \r \n " ;
2011-11-26 12:36:36 +01:00
}
else
{
2012-07-02 19:30:37 +02:00
if ( key_exists ( 'image' , $this -> _msgContent ))
{
$content .= " Content-Type: text/plain; charset= " . $this -> getCharSet () . " \r \n " ;
2017-04-05 01:01:43 +02:00
$content .= " \r \n " . ( $_content [ 'dataText' ] ? $_content [ 'dataText' ] : strip_tags ( $_content [ 'data' ])) . " \r \n " ; // Add plain text message
2012-07-02 19:30:37 +02:00
$content .= " -- " . $this -> _getBoundary ( 'alternative' ) . " \r \n " ;
$content .= 'Content-Type: multipart/related; boundary="' . $this -> _getBoundary ( 'related' ) . '"' . " \r \n " ;
$content .= " \r \n " ;
$content .= " -- " . $this -> _getBoundary ( 'related' ) . " \r \n " ;
2012-06-17 18:40:45 +02:00
}
2017-07-18 12:49:19 +02:00
2017-04-05 01:01:43 +02:00
if ( ! key_exists ( 'image' , $this -> _msgContent ) && $_content [ 'dataText' ] && ! empty ( $conf -> global -> MAIN_MAIL_USE_MULTI_PART )) // Add plain text message part before html part
{
$content .= 'Content-Type: multipart/alternative; boundary="' . $this -> _getBoundary ( 'alternative' ) . '"' . " \r \n " ;
$content .= " \r \n " ;
$content .= " -- " . $this -> _getBoundary ( 'alternative' ) . " \r \n " ;
2017-07-18 12:49:19 +02:00
2017-04-05 01:01:43 +02:00
$content .= " Content-Type: text/plain; charset= " . $this -> getCharSet () . " \r \n " ;
$content .= " \r \n " . $_content [ 'dataText' ] . " \r \n " ;
$content .= " -- " . $this -> _getBoundary ( 'alternative' ) . " \r \n " ;
2017-07-18 12:49:19 +02:00
}
2012-06-17 18:40:45 +02:00
$content .= 'Content-Type: ' . $_content [ 'mimeType' ] . '; '
2011-11-26 12:36:36 +01:00
// . 'charset="' . $this->getCharSet() . '"';
. 'charset=' . $this -> getCharSet () . '' ;
// $content .= ( $type == 'html') ? '; name="HTML Part"' : '';
$content .= " \r \n " ;
// $content .= 'Content-Transfer-Encoding: ';
// $content .= ($type == 'html') ? 'quoted-printable' : $this->getTransEncodeType();
// $content .= "\r\n"
// . 'Content-Disposition: inline' . "\r\n"
// . 'Content-Description: ' . $type . ' message' . "\r\n";
if ( $this -> getMD5flag () )
$content .= 'Content-MD5: ' . $_content [ 'md5' ] . " \r \n " ;
2017-04-05 01:01:43 +02:00
$content .= " \r \n " . $_content [ 'data' ] . " \r \n " ;
if ( ! key_exists ( 'image' , $this -> _msgContent ) && $_content [ 'dataText' ] && ! empty ( $conf -> global -> MAIN_MAIL_USE_MULTI_PART )) // Add plain text message part after html part
{
$content .= " -- " . $this -> _getBoundary ( 'alternative' ) . " -- " . " \r \n " ;
}
2017-07-18 12:49:19 +02:00
2017-04-05 01:01:43 +02:00
$content .= " \r \n " ;
2011-11-26 12:36:36 +01:00
}
}
// Close message boundries
// $content .= "\r\n--" . $this->_getBoundary() . '--' . "\r\n" ;
2012-06-17 18:40:45 +02:00
$content .= " -- " . $this -> _getBoundary ( 'mixed' ) . '--' . " \r \n " ;
2011-11-26 12:36:36 +01:00
}
return $content ;
}
/**
* File attachments are added to the content array as sub - arrays ,
* allowing for multiple attachments for each outbound email
*
* @ param string $strContent File data to attach to message
* @ param string $strFileName File Name to give to attachment
* @ param string $strMimeType File Mime Type of attachment
* @ return void
*/
function setAttachment ( $strContent , $strFileName = 'unknown' , $strMimeType = 'unknown' )
{
if ( $strContent )
{
2012-02-01 16:00:22 +01:00
$strContent = rtrim ( chunk_split ( base64_encode ( $strContent ), 76 , " \r \n " )); // 76 max is defined into http://tools.ietf.org/html/rfc2047
2011-11-26 12:36:36 +01:00
$this -> _msgContent [ 'attachment' ][ $strFileName ][ 'mimeType' ] = $strMimeType ;
$this -> _msgContent [ 'attachment' ][ $strFileName ][ 'fileName' ] = $strFileName ;
$this -> _msgContent [ 'attachment' ][ $strFileName ][ 'data' ] = $strContent ;
if ( $this -> getMD5flag () )
2014-10-18 16:08:15 +02:00
$this -> _msgContent [ 'attachment' ][ $strFileName ][ 'md5' ] = dol_hash ( $strContent , 3 );
2011-11-26 12:36:36 +01:00
}
}
2017-07-17 20:09:19 +02:00
// @CHANGE LDR
2011-11-26 12:36:36 +01:00
/**
* Image attachments are added to the content array as sub - arrays ,
* allowing for multiple images for each outbound email
*
* @ param string $strContent Image data to attach to message
* @ param string $strImageName Image Name to give to attachment
* @ param string $strMimeType Image Mime Type of attachment
* @ param string $strImageCid CID
* @ return void
*/
function setImageInline ( $strContent , $strImageName = 'unknown' , $strMimeType = 'unknown' , $strImageCid = 'unknown' )
{
if ( $strContent )
{
$this -> _msgContent [ 'image' ][ $strImageName ][ 'mimeType' ] = $strMimeType ;
$this -> _msgContent [ 'image' ][ $strImageName ][ 'imageName' ] = $strImageName ;
$this -> _msgContent [ 'image' ][ $strImageName ][ 'cid' ] = $strImageCid ;
$this -> _msgContent [ 'image' ][ $strImageName ][ 'data' ] = $strContent ;
if ( $this -> getMD5flag () )
2014-10-18 16:08:15 +02:00
$this -> _msgContent [ 'image' ][ $strImageName ][ 'md5' ] = dol_hash ( $strContent , 3 );
2011-11-26 12:36:36 +01:00
}
}
2017-07-17 20:09:19 +02:00
// END @CHANGE LDR
2011-11-26 12:36:36 +01:00
/**
* Message Content Sensitivity
* Message Sensitivity values :
* - [ 0 ] None - default
* - [ 1 ] Personal
* - [ 2 ] Private
* - [ 3 ] Company Confidential
*
2016-04-09 15:07:33 +02:00
* @ param integer $_value Message Sensitivity
2011-11-26 12:36:36 +01:00
* @ return void
*/
function setSensitivity ( $_value = 0 )
{
2012-01-04 14:05:49 +01:00
if ( ( is_numeric ( $_value ) ) &&
2011-11-26 12:36:36 +01:00
( ( $_value >= 0 ) && ( $_value <= 3 ) ) )
$this -> _msgSensitivity = $_value ;
}
/**
* Returns Message Content Sensitivity string
* Message Sensitivity values :
* - [ 0 ] None - default
* - [ 1 ] Personal
* - [ 2 ] Private
* - [ 3 ] Company Confidential
*
* @ return void
*/
function getSensitivity ()
{
return $this -> _arySensitivity [ $this -> _msgSensitivity ];
}
/**
* Message Content Priority
* Message Priority values :
* - [ 0 ] 'Bulk'
* - [ 1 ] 'Highest'
* - [ 2 ] 'High'
* - [ 3 ] 'Normal' - default
* - [ 4 ] 'Low'
* - [ 5 ] 'Lowest'
*
2016-04-09 15:07:33 +02:00
* @ param integer $_value Message Priority
2011-11-26 12:36:36 +01:00
* @ return void
*/
2018-08-15 18:14:02 +02:00
function setPriority ( $_value = 3 )
2011-11-26 12:36:36 +01:00
{
2012-01-04 14:05:49 +01:00
if ( ( is_numeric ( $_value ) ) &&
2011-11-26 12:36:36 +01:00
( ( $_value >= 0 ) && ( $_value <= 5 ) ) )
$this -> _msgPriority = $_value ;
}
/**
* Message Content Priority
* Message Priority values :
* - [ 0 ] 'Bulk'
* - [ 1 ] 'Highest'
* - [ 2 ] 'High'
* - [ 3 ] 'Normal' - default
* - [ 4 ] 'Low'
* - [ 5 ] 'Lowest'
2011-09-12 19:08:02 +02:00
*
2016-04-09 15:07:33 +02:00
* @ return string
2011-11-26 12:36:36 +01:00
*/
function getPriority ()
{
return 'Importance: ' . $this -> _aryPriority [ $this -> _msgPriority ] . " \r \n "
. 'Priority: ' . $this -> _aryPriority [ $this -> _msgPriority ] . " \r \n "
. 'X-Priority: ' . $this -> _msgPriority . ' (' . $this -> _aryPriority [ $this -> _msgPriority ] . ')' . " \r \n " ;
}
/**
* Set flag which determines whether to calculate message MD5 checksum .
*
* @ param string $_flag Message Priority
* @ return void
*/
function setMD5flag ( $_flag = false )
{
$this -> _smtpMD5 = $_flag ;
}
/**
* Gets flag which determines whether to calculate message MD5 checksum .
*
2016-04-09 15:07:33 +02:00
* @ return boolean Message Priority
2011-11-26 12:36:36 +01:00
*/
function getMD5flag ()
{
return $this -> _smtpMD5 ;
}
/**
* Message X - Header Content
* This is a simple " insert " . Whatever is given will be placed
* " as is " into the Xheader array .
*
* @ param string $strXdata Message X - Header Content
* @ return void
*/
function setXheader ( $strXdata )
{
if ( $strXdata )
$this -> _msgXheader [] = $strXdata ;
}
/**
* Retrieves the Message X - Header Content
*
2016-04-09 15:07:33 +02:00
* @ return string [] $_msgContent Message X - Header Content
2011-11-26 12:36:36 +01:00
*/
function getXheader ()
{
return $this -> _msgXheader ;
}
/**
* Generates Random string for MIME message Boundary
*
* @ return void
*/
function _setBoundary ()
{
$this -> _smtpsBoundary = " multipart_x. " . time () . " .x_boundary " ;
2014-10-18 16:08:15 +02:00
$this -> _smtpsRelatedBoundary = 'mul_' . dol_hash ( uniqid ( " dolibarr2 " ), 3 );
$this -> _smtpsAlternativeBoundary = 'mul_' . dol_hash ( uniqid ( " dolibarr3 " ), 3 );
2011-11-26 12:36:36 +01:00
}
/**
* Retrieves the MIME message Boundary
*
2012-07-25 11:29:45 +02:00
* @ param string $type Type of boundary
* @ return string $_smtpsBoundary MIME message Boundary
2011-11-26 12:36:36 +01:00
*/
2012-06-17 18:40:45 +02:00
function _getBoundary ( $type = 'mixed' )
2011-11-26 12:36:36 +01:00
{
2012-06-17 18:40:45 +02:00
if ( $type == 'mixed' ) return $this -> _smtpsBoundary ;
else if ( $type == 'related' ) return $this -> _smtpsRelatedBoundary ;
else if ( $type == 'alternative' ) return $this -> _smtpsAlternativeBoundary ;
2011-11-26 12:36:36 +01:00
}
2018-09-06 21:27:18 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
2011-11-26 12:36:36 +01:00
/**
* This function has been modified as provided by SirSir to allow multiline responses when
* using SMTP Extensions
*
2012-01-04 14:05:49 +01:00
* @ param Handler $socket Socket handler
2017-12-03 19:36:59 +01:00
* @ param string $response Response . Example : " 550 5.7.1 https://support.google.com/a/answer/6140680#invalidcred j21sm814390wre.3 "
2012-01-04 14:05:49 +01:00
* @ return boolean True or false
2011-11-26 12:36:36 +01:00
*/
function server_parse ( $socket , $response )
{
2018-09-06 21:27:18 +02:00
// phpcs:enable
2011-11-26 12:36:36 +01:00
/**
* Returns constructed SELECT Object string or boolean upon failure
2018-04-16 13:51:16 +02:00
* Default value is set at true
2011-11-26 12:36:36 +01:00
*/
$_retVal = true ;
$server_response = '' ;
2017-12-03 19:36:59 +01:00
2016-04-16 18:15:03 +02:00
// avoid infinite loop
$limit = 0 ;
2011-11-26 12:36:36 +01:00
2017-12-03 19:36:59 +01:00
while ( substr ( $server_response , 3 , 1 ) != ' ' && $limit < 100 )
2011-11-26 12:36:36 +01:00
{
2017-12-03 19:36:59 +01:00
if ( ! ( $server_response = fgets ( $socket , 256 )))
2011-11-26 12:36:36 +01:00
{
$this -> _setErr ( 121 , " Couldn't get mail server response codes " );
$_retVal = false ;
2017-12-03 19:36:59 +01:00
break ;
2011-11-26 12:36:36 +01:00
}
2016-04-16 18:15:03 +02:00
$limit ++ ;
2011-11-26 12:36:36 +01:00
}
2017-12-03 19:36:59 +01:00
if ( ! ( substr ( $server_response , 0 , 3 ) == $response ))
2011-11-26 12:36:36 +01:00
{
$this -> _setErr ( 120 , " Ran into problems sending Mail. \r \n Response: $server_response " );
$_retVal = false ;
}
return $_retVal ;
}
2018-09-06 21:27:18 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
2012-01-04 14:05:49 +01:00
/**
* Send str
*
* @ param string $_strSend String to send
* @ param string $_returnCode Return code
* @ param string $CRLF CRLF
2016-04-09 15:07:33 +02:00
* @ return boolean | null True or false
2012-01-04 14:05:49 +01:00
*/
function socket_send_str ( $_strSend , $_returnCode = null , $CRLF = " \r \n " )
2011-11-26 12:36:36 +01:00
{
2018-09-06 21:27:18 +02:00
// phpcs:enable
2017-07-17 20:09:19 +02:00
if ( $this -> _debug ) $this -> log .= $_strSend ; // @CHANGE LDR for log
2011-11-26 12:36:36 +01:00
fputs ( $this -> socket , $_strSend . $CRLF );
if ( $this -> _debug ) $this -> log .= ' (' . $_returnCode . ')' . $CRLF ;
if ( $_returnCode )
return $this -> server_parse ( $this -> socket , $_returnCode );
}
// =============================================================
// ** Error handling methods
/**
* Defines errors codes and messages for Class
*
* @ param int $_errNum Error Code Number
* @ param string $_errMsg Error Message
* @ return void
2018-08-15 18:14:02 +02:00
*/
function _setErr ( $_errNum , $_errMsg )
{
$this -> _smtpsErrors [] = array (
'num' => $_errNum ,
'msg' => $_errMsg ,
);
}
2011-11-26 12:36:36 +01:00
/**
* Returns errors codes and messages for Class
*
* @ return string $_errMsg Error Message
*/
function getErrors ()
{
$_errMsg = array ();
2018-06-17 01:50:10 +02:00
if ( is_array ( $this -> _smtpsErrors ))
2011-11-26 12:36:36 +01:00
{
2018-06-17 01:50:10 +02:00
foreach ( $this -> _smtpsErrors as $_err => $_info )
{
$_errMsg [] = 'Error [' . $_info [ 'num' ] . ']: ' . $_info [ 'msg' ];
}
2011-11-26 12:36:36 +01:00
}
return implode ( " \n " , $_errMsg );
}
2011-09-12 19:43:31 +02:00
}
2011-08-26 17:13:58 +02:00
// =============================================================
// ** CSV Version Control Info
2011-08-27 01:40:47 +02:00
/**
2011-09-12 19:08:02 +02:00
* Revision 2011 / 09 / 12 07 : 49 : 59 eldy
2011-09-12 09:46:27 +02:00
* Doxygen
*
2011-09-12 19:08:02 +02:00
* Revision 2011 / 09 / 06 06 : 53 : 53 hregis
2011-09-06 08:53:52 +02:00
* Fix : use dol_hash instead md5 php function
*
2011-09-12 19:08:02 +02:00
* Revision 2011 / 09 / 03 00 : 14 : 27 eldy
2011-09-03 02:14:27 +02:00
* Doxygen
*
2011-09-12 19:08:02 +02:00
* Revision 2011 / 08 / 28 14 : 24 : 23 eldy
2011-08-28 16:18:14 +02:00
* Doxygen
*
2011-09-12 19:08:02 +02:00
* Revision 2011 / 07 / 12 22 : 19 : 02 eldy
2011-08-27 01:40:47 +02:00
* Fix : Attachment fails if content was empty
*
2011-09-12 19:08:02 +02:00
* Revision 2011 / 06 / 20 23 : 17 : 50 hregis
2011-08-27 01:40:47 +02:00
* Fix : use best structure of mail
*
2011-09-12 19:08:02 +02:00
* Revision 2010 / 04 / 13 20 : 58 : 37 eldy
2011-08-27 01:40:47 +02:00
* Fix : Can provide ip address on smtps . Better error reporting .
*
2011-09-12 19:08:02 +02:00
* Revision 2010 / 04 / 13 20 : 30 : 25 eldy
2011-08-27 01:40:47 +02:00
* Fix : Can provide ip address on smtps . Better error reporting .
*
2011-09-12 19:08:02 +02:00
* Revision 2010 / 01 / 12 13 : 02 : 07 hregis
2011-08-27 01:40:47 +02:00
* Fix : missing attach - files
*
2011-09-12 19:08:02 +02:00
* Revision 2009 / 11 / 01 14 : 16 : 30 eldy
2011-08-27 01:40:47 +02:00
* Fix : Sending mail with SMTPS was not working .
*
2011-09-12 19:08:02 +02:00
* Revision 2009 / 10 / 20 13 : 14 : 47 hregis
2011-08-27 01:40:47 +02:00
* Fix : function " split " is deprecated since php 5.3 . 0
*
2011-09-12 19:08:02 +02:00
* Revision 2009 / 05 / 13 19 : 10 : 07 eldy
2011-08-27 01:40:47 +02:00
* New : Can use inline images . Everything seems to work with thunderbird and webmail gmail . New to be tested on other mail browsers .
*
2011-09-12 19:08:02 +02:00
* Revision 2009 / 05 / 13 14 : 49 : 30 eldy
2011-08-27 01:40:47 +02:00
* Fix : Make code so much simpler and solve a lot of problem with new version .
*
2011-09-12 19:08:02 +02:00
* Revision 2009 / 02 / 09 00 : 04 : 35 eldy
2011-08-27 01:40:47 +02:00
* Added support for SMTPS protocol
*
2011-09-12 19:08:02 +02:00
* Revision 2008 / 04 / 16 23 : 11 : 45 eldy
2011-08-27 01:40:47 +02:00
* New : Add action " Test server connectivity "
*
* Revision 1.18 2007 / 01 / 12 22 : 17 : 08 ongardie
* - Added full_http_site_root () to utils - misc . php
* - Made SMTPs ' getError () easier to use
* - Improved activity modified emails
*
* Revision 1.17 2006 / 04 / 05 03 : 15 : 40 ongardie
* - Fixed method name typo that resulted in a fatal error .
*
* Revision 1.16 2006 / 03 / 08 04 : 05 : 25 jswalter
* - '$_smtpsTransEncode' was removed and '$_smtpsTransEncodeType' is now used
* - '$_smtpsTransEncodeType' is defaulted to ZERO
* - corrected 'setCharSet()' internal vars
* - defined '$_mailPath'
* - added '$_smtpMD5' as a class property
* - added 'setMD5flag()' to set above property
* - added 'getMD5flag()' to retrieve above property
* - 'setAttachment()' will add an MD5 checksum to attachements if above property is set
* - 'setBodyContent()' will add an MD5 checksum to message parts if above property is set
* - 'getBodyContent()' will insert the MD5 checksum for messages and attachments if above property is set
* - removed leading dashes from message boundry
* - added propery " Close message boundry " tomessage block
* - corrected some comments in various places
* - removed some incorrect comments in others
*
* Revision 1.15 2006 / 02 / 21 02 : 00 : 07 vanmer
* - patch to add support for sending to exim mail server
* - thanks to Diego Ongaro at ETSZONE ( diego @ etszone . com )
*
* Revision 1.14 2005 / 08 / 29 16 : 22 : 10 jswalter
* - change 'multipart/alternative' to 'multipart/mixed' , but Windows based mail servers have issues with this .
* Bug 594
*
* Revision 1.13 2005 / 08 / 21 01 : 57 : 30 vanmer
* - added initialization for array if no recipients exist
*
* Revision 1.12 2005 / 08 / 20 12 : 04 : 30 braverock
* - remove potentially binary characters from Message - ID
* - add getHost to get the hostname of the mailserver
2011-09-12 19:08:02 +02:00
* - add username to Message - ID header
2011-08-27 01:40:47 +02:00
*
* Revision 1.11 2005 / 08 / 20 11 : 49 : 48 braverock
* - fix typos in boundary
* - remove potentially illegal characters from boundary
*
* Revision 1.10 2005 / 08 / 19 20 : 39 : 32 jswalter
* - added _server_connect () ' as a seperate method to handle server connectivity .
* - added '_server_authenticate()' as a seperate method to handle server authentication .
* - 'sendMsg()' now uses the new methods to handle server communication .
* - modified 'server_parse()' and 'socket_send_str()' to give error codes and messages .
*
* Revision 1.9 2005 / 08 / 19 15 : 40 : 18 jswalter
* - IMPORTANT : 'setAttachement()' is now spelled correctly : 'setAttachment()'
* - added additional comment to several methods
* - added '$_smtpsTransEncodeTypes' array to limit encode types
* - added parameters to 'sendMsg()' for future development around debugging and logging
* - added error code within 'setConfig()' if the given path is not found
* - 'setTransportType()' now has parameter validation
* [ this still is not implemented ]
* - 'setPort()' now does parameter validation
* - 'setTransEncode()' now has parameter validation against '$_smtpsTransEncodeTypes'
* - modified 'get_email_list()' to handle error handling
* - 'setSensitivity()' now has parameter validation
* - 'setPriority()' now has parameter validation
*
* Revision 1.8 2005 / 06 / 24 21 : 00 : 20 jswalter
* - corrected comments
* - corrected the defualt value for 'setPriority()'
* - modified 'setAttachement()' to process multiple attachments correctly
* - modified 'getBodyContent()' to handle multiple attachments
* Bug 310
*
* Revision 1.7 2005 / 05 / 19 21 : 12 : 34 braverock
* - replace chunk_split () with wordwrap () to fix funky wrapping of templates
*
* Revision 1.6 2005 / 04 / 25 04 : 55 : 06 jswalter
* - cloned from Master Version
*
* Revision 1.10 2005 / 04 / 25 04 : 54 : 10 walter
* - " fixed " 'getBodyContent()' to handle a " simple " text only message
*
* Revision 1.9 2005 / 04 / 25 03 : 52 : 01 walter
* - replace closing curly bracket . Removed it in last revision !
*
* Revision 1.8 2005 / 04 / 25 02 : 29 : 49 walter
* - added '$_transportType' and its getter / setter methods .
* for future use . NOT yet implemented .
* - in 'sendMsg()' , added HOST validation check
* - added error check for initial Socket Connection
* - created new method 'socket_send_str()' to process socket
* communication in a unified means . Socket calls within
* 'sendMsg()' have been modified to use this new method .
* - expanded comments in 'setConfig()'
* - added " error " check on PHP ini file properties . If these
* properties not set within the INI file , the default values
* will be used .
* - modified 'get_RCPT_list()' to reset itself each time it is called
* - modified 'setBodyContent()' to store data in a sub - array for better
* parsing within the 'getBodyContent()' method
* - modified 'getBodyContent()' to process contents array better .
* Also modified to handle attachements .
* - added 'setAttachement()' so files and other data can be attached
* to messages
* - added '_setErr()' and 'getErrors()' as an attempt to begin an error
* handling process within this class
*
* Revision 1.7 2005 / 04 / 13 15 : 23 : 50 walter
* - made 'CC' a conditional insert
* - made 'BCC' a conditional insert
* - fixed 'Message-ID'
* - corrected 'getSensitivity()'
* - modified '$_aryPriority[]' to proper values
* - updated 'setConfig()' to handle external Ini or 'php.ini'
*
* Revision 1.6 2005 / 03 / 15 17 : 34 : 06 walter
* - corrected Message Sensitivity property and method comments
* - added array to Message Sensitivity
* - added getSensitivity () method to use new Sensitivity array
* - created seters and getter for Priority with new Prioity value array property
* - changed config file include from 'include_once'
* - modified getHeader () to ustilize new Message Sensitivity and Priorty properties
*
* Revision 1.5 2005 / 03 / 14 22 : 25 : 27 walter
* - added references
* - added Message sensitivity as a property with Getter / Setter methods
* - boundary is now a property with Getter / Setter methods
* - added 'builtRCPTlist()'
* - 'sendMsg()' now uses Object properties and methods to build message
* - 'setConfig()' to load external file
* - 'setForm()' will " strip " the email address out of " address " string
* - modifed 'getFrom()' to handle " striping " the email address
* - '_buildArrayList()' creates a multi - dimensional array of addresses
* by domain , TO , CC & BCC and then by User Name .
* - '_strip_email()' pulls email address out of " full Address " string '
* - 'get_RCPT_list()' pulls out " bare " emaill address form address array
* - 'getHeader()' builds message Header from Object properties
* - 'getBodyContent()' builds full messsage body , even multi - part
*
* Revision 1.4 2005 / 03 / 02 20 : 53 : 35 walter
* - core Setters & Getters defined
* - added additional Class Properties
*
* Revision 1.3 2005 / 03 / 02 18 : 51 : 51 walter
* - added base 'Class Properties'
*
* Revision 1.2 2005 / 03 / 01 19 : 37 : 52 walter
* - CVS logging tags
* - more comments
* - more " shell "
* - some constants
*
* Revision 1.1 2005 / 03 / 01 19 : 22 : 49 walter
* - initial commit
* - basic shell with some commets
*
*/