class SMTPs (View source)

Class to construct and send SMTP compliant email, even to a secure SMTP server, regardless of platform.

Properties

string $log
string $lastretval
resource $socket
int $errno
string $errstr

Methods

void
setMessageID(string $_msgId = '')

Set Message-ID

void
setOptions(array<string, array<string, mixed>> $_options = array())

Set options

void
setDeliveryReceipt(int $_val = 0)

Set delivery receipt

int
getDeliveryReceipt()

get delivery receipt

void
setSMTPTimeout(int $timeout)

Set socket timeout. May be increase when email sent after a long time and with a large file for the wake up of SMTP server.

int
getSMTPTimeout()

Get socket timeout

void
setTrackId(string $_val = '')

Set trackid

void
setMoreInHeader(string $_val = '')

Set moreInHeader

string
getTrackId()

get trackid

string
getMoreInHeader()

get moreInHeader

void
setErrorsTo(string $_strErrorsTo)

Set errors to

string|array<string, string>
getErrorsTo(true|string $_part = true)

Get errors to

void
setDebug(bool $_vDebug = false)

Set debug

void
buildRCPTlist()

build RECIPIENT List, all addresses who will receive this message

bool|null
sendMsg()

Now send the message

bool
setConfig(mixed $_strConfigPath = null)

setConfig() is used to populate select class properties from either a user defined INI file or the systems 'php.ini' file

void
setTransportType(int $_type = 0)

Determines the method inwhich the messages are to be sent.

int
getTransportType()

Return the method inwhich the message is to be sent.

bool
setMailPath(string $_path)

Path to the sendmail executable

void
setHost(string $_strHost)

Defines the Host Name or IP of the Mail Server to use.

string
getHost()

Retrieves the Host Name or IP of the Mail Server to use This is used only with 'socket' based mail transmission

void
setPort(int|string $_intPort)

Defines the Port Number of the Mail Server to use The default is 25 This is used only with 'socket' based mail transmission

int
getPort()

Retrieves the Port Number of the Mail Server to use This is used only with 'socket' based mail transmission

void
setID(string $_strID)

User Name for authentication on Mail Server

string
getID()

Retrieves the User Name for authentication on Mail Server

void
setPW(string $_strPW)

User Password for authentication on Mail Server

string
getPW()

Retrieves the User Password for authentication on Mail Server

void
setToken(string $_strToken)

User token for OAUTH2

string
getToken()

Retrieves the User token for OAUTH2

void
setCharSet(string $_strCharSet)

Character set used for current message Character set is defaulted to 'iso-8859-1';

string
getCharSet()

Retrieves the Character set used for current message

void
setTransEncode(string $_strTransEncode)

Content-Transfer-Encoding, Defaulted to '7bit' This can be changed for 2byte characters sets Known Encode Types

  • 7bit Simple 7-bit ASCII
  • 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

string
getTransEncode()

Retrieves the Content-Transfer-Encoding

void
setTransEncodeType(string $_strTransEncodeType)

Content-Transfer-Encoding, Defaulted to '0' [ZERO] This can be changed for 2byte characters sets Known Encode Types

  • [0] 7bit Simple 7-bit ASCII
  • [1] 8bit 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

string
getTransEncodeType()

Retrieves the Content-Transfer-Encoding

void
setFrom(string $_strFrom)

FROM Address from which mail will be sent

null|string|array{org: string, real?: string, addr: string, user: string, host: string}
getFrom(true|string $_part = true)

Retrieves the Address from which mail will be sent

void
setReplyTo(string $_strReplyTo)

Reply-To Address from which mail will be the reply-to

null|array<string, string>|string
getReplyTo(true|string $_part = true)

Retrieves the Address from which mail will be the reply-to

void
setInReplyTo(string $_strInReplyTo)

Set References in the list of Msg-Id

string
getInReplyTo()

Retrieves the InReplyTo from which mail we reply to

void
setReferences(string[] $_strReferences)

Set References in the list of Msg-Id

?string[]
getReferences()

Retrieves the References from which mail will be the reply-to

string[]
get_RCPT_list()

Returns an array of bare addresses for use with 'RCPT TO:' This is a "build as you go" method. Each time this method is called the underlying array is destroyed and reconstructed.

string|false
get_email_list(string $_which = null)

Returns an array of addresses for a specific type; TO, CC or BCC

void
setTO(string $_addrTo)

TO Address[es] inwhich to send mail to

string
getTo()

Retrieves the TO Address[es] inwhich to send mail to

void
setCC(string $_strCC)

CC Address[es] inwhich to send mail to

string
getCC()

Retrieves the CC Address[es] inwhich to send mail to

void
setBCC(string $_strBCC)

BCC Address[es] inwhich to send mail to

string
getBCC()

Retrieves the BCC Address[es] inwhich to send mail to

void
setSubject(string $_strSubject = '')

Message Subject

string
getSubject()

Retrieves the Message Subject

string
getHeader()

Constructs and returns message header

void
setBodyContent(string $strContent, string $strType = 'plain')

Message Content

string
getBodyContent()

Retrieves the Message Content

void
setAttachment(string $strContent, string $strFileName = 'unknown', string $strMimeType = 'unknown', string $strCid = '')

File attachments are added to the content array as sub-arrays, allowing for multiple attachments for each outbound email

void
setImageInline(string $strContent, string $strImageName = 'unknown', string $strMimeType = 'unknown', string $strImageCid = 'unknown')

Image attachments are added to the content array as sub-arrays, allowing for multiple images for each outbound email

void
setSensitivity(int $_value = 0)

Message Content Sensitivity Message Sensitivity values:

  • [0] None - default
  • [1] Personal
  • [2] Private
  • [3] Company Confidential

string|bool
getSensitivity()

Returns Message Content Sensitivity string Message Sensitivity values:

  • [0] None - default
  • [1] Personal
  • [2] Private
  • [3] Company Confidential

void
setPriority(int $_value = 3)

Message Content Priority Message Priority values:

  • [0] 'Bulk'
  • [1] 'Highest'
  • [2] 'High'
  • [3] 'Normal' - default
  • [4] 'Low'
  • [5] 'Lowest'

string
getPriority()

Message Content Priority Message Priority values:

  • [0] 'Bulk'
  • [1] 'Highest'
  • [2] 'High'
  • [3] 'Normal' - default
  • [4] 'Low'
  • [5] 'Lowest'

void
setMD5flag(bool $_flag = false)

Set flag which determines whether to calculate message MD5 checksum.

bool
getMD5flag()

Gets flag which determines whether to calculate message MD5 checksum.

void
setXheader(string $strXdata)

Message X-Header Content This is a simple "insert". Whatever is given will be placed "as is" into the Xheader array.

string[]
getXheader()

Retrieves the Message X-Header Content

bool
server_parse(resource $socket, string $response)

This function has been modified as provided by SirSir to allow multiline responses when using SMTP Extensions

bool|null
socket_send_str(string $_strSend, string $_returnCode = null, string $CRLF = "\r\n")

Send str

string
getErrors()

Returns applicative errors codes and messages for Class (not the SMTP error code)

Details

void setMessageID(string $_msgId = '')

Set Message-ID

Parameters

string $_msgId

Message-ID to use

Return Value

void

void setOptions(array<string, array<string, mixed>> $_options = array())

Set options

Parameters

array<string, array<string, mixed>> $_options

An array of options for stream_context_create()

Return Value

void

void setDeliveryReceipt(int $_val = 0)

Set delivery receipt

Parameters

int $_val Value

Return Value

void

int getDeliveryReceipt()

get delivery receipt

Return Value

int

Delivery receipt

void setSMTPTimeout(int $timeout)

Set socket timeout. May be increase when email sent after a long time and with a large file for the wake up of SMTP server.

Parameters

int $timeout

Delay in second for socket timeout (default is 10s)

Return Value

void

int getSMTPTimeout()

Get socket timeout

Return Value

int

Delay in second for socket timeout

void setTrackId(string $_val = '')

Set trackid

Parameters

string $_val Value

Return Value

void

void setMoreInHeader(string $_val = '')

Set moreInHeader

Parameters

string $_val Value

Return Value

void

string getTrackId()

get trackid

Return Value

string

Track id

string getMoreInHeader()

get moreInHeader

Return Value

string moreInHeader

void setErrorsTo(string $_strErrorsTo)

Set errors to

Parameters

string $_strErrorsTo

Errors to

Return Value

void

string|array<string, string> getErrorsTo(true|string $_part = true)

Get errors to

Parameters

true|string $_part Variant

Return Value

string|array<string, string>

Errors to

void setDebug(bool $_vDebug = false)

Set debug

Parameters

bool $_vDebug

Value for debug

Return Value

void

void buildRCPTlist()

build RECIPIENT List, all addresses who will receive this message

Return Value

void

bool|null sendMsg()

Now send the message

Return Value

bool|null Result

bool setConfig(mixed $_strConfigPath = null)

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.

Parameters

mixed $_strConfigPath

path to config file or VOID

Return Value

bool

void setTransportType(int $_type = 0)

Determines the method inwhich the messages are to be sent.

  • 'sockets' [0] - connect via network to SMTP server
  • 'pipe [1] - use UNIX path to EXE
  • 'phpmail [2] - use the PHP built-in mail function

Parameters

int $_type

Integer value representing Mail Transport Type

Return Value

void

int getTransportType()

Return the method inwhich the message is to be sent.

  • 'sockets' [0] - connect via network to SMTP server
  • 'pipe [1] - use UNIX path to EXE
  • 'phpmail [2] - use the PHP built-in mail function

Return Value

int

$_strHost Host Name or IP of the Mail Server to use

bool setMailPath(string $_path)

Path to the sendmail executable

Parameters

string $_path

Path to the sendmail executable

Return Value

bool

void setHost(string $_strHost)

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

Parameters

string $_strHost

Host Name or IP of the Mail Server to use

Return Value

void

string getHost()

Retrieves the Host Name or IP of the Mail Server to use This is used only with 'socket' based mail transmission

Return Value

string

$_strHost Host Name or IP of the Mail Server to use

void setPort(int|string $_intPort)

Defines the Port Number of the Mail Server to use The default is 25 This is used only with 'socket' based mail transmission

Parameters

int|string $_intPort

Port Number of the Mail Server to use

Return Value

void

int getPort()

Retrieves the Port Number of the Mail Server to use This is used only with 'socket' based mail transmission

Return Value

int

Port Number of the Mail Server to use

void setID(string $_strID)

User Name for authentication on Mail Server

Parameters

string $_strID

User Name for authentication on Mail Server

Return Value

void

string getID()

Retrieves the User Name for authentication on Mail Server

Return Value

string

User Name for authentication on Mail Server

void setPW(string $_strPW)

User Password for authentication on Mail Server

Parameters

string $_strPW

User Password for authentication on Mail Server

Return Value

void

string getPW()

Retrieves the User Password for authentication on Mail Server

Return Value

string

User Password for authentication on Mail Server

void setToken(string $_strToken)

User token for OAUTH2

Parameters

string $_strToken

User token

Return Value

void

string getToken()

Retrieves the User token for OAUTH2

Return Value

string

User token for OAUTH2

void setCharSet(string $_strCharSet)

Character set used for current message Character set is defaulted to 'iso-8859-1';

Parameters

string $_strCharSet

Character set used for current message

Return Value

void

string getCharSet()

Retrieves the Character set used for current message

Return Value

string

$_smtpsCharSet Character set used for current message

void setTransEncode(string $_strTransEncode)

Content-Transfer-Encoding, Defaulted to '7bit' This can be changed for 2byte characters sets Known Encode Types

  • 7bit Simple 7-bit ASCII
  • 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

Parameters

string $_strTransEncode Content-Transfer-Encoding

Return Value

void

string getTransEncode()

Retrieves the Content-Transfer-Encoding

Return Value

string

$_smtpsTransEncode Content-Transfer-Encoding

void setTransEncodeType(string $_strTransEncodeType)

Content-Transfer-Encoding, Defaulted to '0' [ZERO] This can be changed for 2byte characters sets Known Encode Types

  • [0] 7bit Simple 7-bit ASCII
  • [1] 8bit 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

Parameters

string $_strTransEncodeType Content-Transfer-Encoding

Return Value

void

string getTransEncodeType()

Retrieves the Content-Transfer-Encoding

Return Value

string Content-Transfer-Encoding

void setFrom(string $_strFrom)

FROM Address from which mail will be sent

Parameters

string $_strFrom

Address from which mail will be sent

Return Value

void

null|string|array{org: string, real?: string, addr: string, user: string, host: string} getFrom(true|string $_part = true)

Retrieves the Address from which mail will be sent

Parameters

true|string $_part

To "strip" 'Real name' from address

Return Value

null|string|array{org: string, real?: string, addr: string, user: string, host: string}

Address from which mail will be sent

void setReplyTo(string $_strReplyTo)

Reply-To Address from which mail will be the reply-to

Parameters

string $_strReplyTo

Address from which mail will be the reply-to

Return Value

void

null|array<string, string>|string getReplyTo(true|string $_part = true)

Retrieves the Address from which mail will be the reply-to

Parameters

true|string $_part

To "strip" 'Real name' from address

Return Value

null|array<string, string>|string

Reply-To Address to use

void setInReplyTo(string $_strInReplyTo)

Set References in the list of Msg-Id

Parameters

string $_strInReplyTo

List of Msg-Id

Return Value

void

string getInReplyTo()

Retrieves the InReplyTo from which mail we reply to

Return Value

string

Msg-Id of email we reply to

void setReferences(string[] $_strReferences)

Set References in the list of Msg-Id

Parameters

string[] $_strReferences

List of Msg-Id

Return Value

void

?string[] getReferences()

Retrieves the References from which mail will be the reply-to

Return Value

?string[]

List of Msg-Id

string[] get_RCPT_list()

Returns an array of bare addresses for use with 'RCPT TO:' This is a "build as you go" method. Each time this method is called the underlying array is destroyed and reconstructed.

Return Value

string[]

Returns an array of bare addresses

string|false get_email_list(string $_which = null)

Returns an array of addresses for a specific type; TO, CC or BCC

Parameters

string $_which

Which collection of addresses to return ('to', 'cc', 'bcc')

Return Value

string|false

Array of emaill address

void setTO(string $_addrTo)

TO Address[es] inwhich to send mail to

Parameters

string $_addrTo

TO Address[es] inwhich to send mail to

Return Value

void

string getTo()

Retrieves the TO Address[es] inwhich to send mail to

Return Value

string

TO Address[es] inwhich to send mail to

void setCC(string $_strCC)

CC Address[es] inwhich to send mail to

Parameters

string $_strCC

CC Address[es] inwhich to send mail to

Return Value

void

string getCC()

Retrieves the CC Address[es] inwhich to send mail to

Return Value

string

CC Address[es] inwhich to send mail to

void setBCC(string $_strBCC)

BCC Address[es] inwhich to send mail to

Parameters

string $_strBCC

Recipients BCC Address[es] inwhich to send mail to

Return Value

void

string getBCC()

Retrieves the BCC Address[es] inwhich to send mail to

Return Value

string

BCC Address[es] inwhich to send mail to

void setSubject(string $_strSubject = '')

Message Subject

Parameters

string $_strSubject

Message Subject

Return Value

void

string getSubject()

Retrieves the Message Subject

Return Value

string

Message Subject

string getHeader()

Constructs and returns message header

Return Value

string

Complete message header

void setBodyContent(string $strContent, string $strType = 'plain')

Message Content

Parameters

string $strContent

Message Content

string $strType Type

Return Value

void

string getBodyContent()

Retrieves the Message Content

Return Value

string

Message Content

void setAttachment(string $strContent, string $strFileName = 'unknown', string $strMimeType = 'unknown', string $strCid = '')

File attachments are added to the content array as sub-arrays, allowing for multiple attachments for each outbound email

Parameters

string $strContent

File data to attach to message

string $strFileName

File Name to give to attachment

string $strMimeType

File Mime Type of attachment

string $strCid

File Cid of attachment (if defined, to be shown inline)

Return Value

void

void setImageInline(string $strContent, string $strImageName = 'unknown', string $strMimeType = 'unknown', string $strImageCid = 'unknown')

Image attachments are added to the content array as sub-arrays, allowing for multiple images for each outbound email

Parameters

string $strContent

Image data to attach to message

string $strImageName

Image Name to give to attachment

string $strMimeType

Image Mime Type of attachment

string $strImageCid CID

Return Value

void

void setSensitivity(int $_value = 0)

Message Content Sensitivity Message Sensitivity values:

  • [0] None - default
  • [1] Personal
  • [2] Private
  • [3] Company Confidential

Parameters

int $_value

Message Sensitivity

Return Value

void

string|bool getSensitivity()

Returns Message Content Sensitivity string Message Sensitivity values:

  • [0] None - default
  • [1] Personal
  • [2] Private
  • [3] Company Confidential

Return Value

string|bool

void setPriority(int $_value = 3)

Message Content Priority Message Priority values:

  • [0] 'Bulk'
  • [1] 'Highest'
  • [2] 'High'
  • [3] 'Normal' - default
  • [4] 'Low'
  • [5] 'Lowest'

Parameters

int $_value

Message Priority

Return Value

void

string getPriority()

Message Content Priority Message Priority values:

  • [0] 'Bulk'
  • [1] 'Highest'
  • [2] 'High'
  • [3] 'Normal' - default
  • [4] 'Low'
  • [5] 'Lowest'

Return Value

string

void setMD5flag(bool $_flag = false)

Set flag which determines whether to calculate message MD5 checksum.

Parameters

bool $_flag MD5flag

Return Value

void

bool getMD5flag()

Gets flag which determines whether to calculate message MD5 checksum.

Return Value

bool MD5flag

void setXheader(string $strXdata)

Message X-Header Content This is a simple "insert". Whatever is given will be placed "as is" into the Xheader array.

Parameters

string $strXdata

Message X-Header Content

Return Value

void

string[] getXheader()

Retrieves the Message X-Header Content

Return Value

string[]

$_msgContent Message X-Header Content

bool server_parse(resource $socket, string $response)

This function has been modified as provided by SirSir to allow multiline responses when using SMTP Extensions

Parameters

resource $socket

Socket handler

string $response

Expected response ('250', ...). Example of response we can get: "421 4.7.0 Try again later, closing connection. (EHLO) nb21-20020a1709071c9500b0093d0d964affsm869534ejc.73 - gsmtp" "550 5.7.1 https://support.google.com/a/answer/6140680#invalidcred j21sm814390wre.3"

Return Value

bool

True or false

bool|null socket_send_str(string $_strSend, string $_returnCode = null, string $CRLF = "\r\n")

Send str

Parameters

string $_strSend

String to send

string $_returnCode

Expected return code

string $CRLF CRLF

Return Value

bool|null

True or false

string getErrors()

Returns applicative errors codes and messages for Class (not the SMTP error code)

Return Value

string

$_errMsg Error Message