\Horde_Smtp

An interface to an SMTP server (RFC 5321).

Implements the following SMTP-related RFCs:

  - RFC 1870/STD 10: Message Size Declaration
  - RFC 1985: SMTP Service Extension for Remote Message Queue Starting
  - RFC 2034: Enhanced-Status-Codes
  - RFC 2195: CRAM-MD5 (SASL Authentication)
  - RFC 2595/4616: TLS & PLAIN (SASL Authentication)
  - RFC 2831: DIGEST-MD5 authentication mechanism (obsoleted by RFC 6331)
  - RFC 2920/STD 60: Pipelining
  - RFC 3030: SMTP Service Extensions for Transmission of Large and Binary
              MIME Messages
  - RFC 3207: Secure SMTP over TLS
  - RFC 3463: Enhanced Mail System Status Codes
  - RFC 4422: SASL Authentication (for DIGEST-MD5)
  - RFC 4954: Authentication
  - RFC 5321: Simple Mail Transfer Protocol
  - RFC 6152/STD 71: 8bit-MIMEtransport
  - RFC 6409/STD 72: Message Submission for Mail
  - RFC 6531: Internationalized Email

  - XOAUTH2: https://developers.google.com/gmail/xoauth2_protocol

TODO:

  - RFC 1845: CHECKPOINT
  - RFC 2852: DELIVERYBY
  - RFC 3461: DSN
  - RFC 3865: NO-SOLICITING
  - RFC 3885: MTRK
  - RFC 4141: CONPERM/CONNEG
  - RFC 4405: SUBMITTER
  - RFC 4468: BURL
  - RFC 4865: FUTURERELEASE
  - RFC 6710: MT-PRIORITY
  - RFC 7293: RRVS

Summary

Methods
Properties
Constants
__construct()
shutdown()
__clone()
serialize()
unserialize()
__get()
getParam()
setParam()
queryExtension()
isSecureConnection()
login()
logout()
send()
resetCmd()
noop()
processQueue()
$data_8bit
$data_binary
$data_intl
$size
CHUNK_DEFAULT
_getEncryptKey()
_initOb()
_hello()
_startTls()
_auth()
_getResponse()
_processData()
_getHostname()
$_connection
$_debug
$_ehlo
$_extensions
$_params
$_requiredExts
N/A
No private methods found
No private properties found
N/A

Constants

CHUNK_DEFAULT

CHUNK_DEFAULT

Properties

$data_8bit

$data_8bit : boolean

Does server support sending 8-bit MIME data?

Type

boolean

$data_binary

$data_binary : boolean

Does server support sending binary MIME data? (@since 1.7.0)

Type

boolean

$data_intl

$data_intl : boolean

Does server support sending internationalized (UTF-8) header data? (@since 1.6.0)

Type

boolean

$size

$size : integer

The maximum message size supported (in bytes) or null if this cannot be determined.

Type

integer

$_connection

$_connection : \Horde_Smtp_Connection

Connection to the SMTP server.

Type

\Horde_Smtp_Connection

$_ehlo

$_ehlo : string

The hello command to use for extended SMTP support.

Type

string

$_extensions

$_extensions : array

The list of ESMTP extensions.

If this value is null, we have not connected to server yet.

Type

array

$_params

$_params : array

Hash containing connection parameters.

Type

array

$_requiredExts

$_requiredExts : array

List of required ESMTP extensions.

Type

array

Methods

__construct()

__construct(array  $params = array()) 

Constructor.

Parameters

array $params

Configuration parameters:

  • chunk_size: (integer) If CHUNKING is supported on the server, the chunk size (in octets) to send. 0 will disable chunking. @since 1.7.0
  • context: (array) Any context parameters passed to stream_create_context(). @since 1.9.0
  • debug: (string) If set, will output debug information to the stream provided. The value can be any PHP supported wrapper that can be opened via fopen(). DEFAULT: No debug output
  • host: (string) The SMTP server. DEFAULT: localhost
  • localhost: (string) The hostname of the localhost. (since 1.9.0) DEFAULT: Auto-determined.
  • password: (mixed) The SMTP password or a Horde_Smtp_Password object (since 1.1.0). DEFAULT: NONE
  • port: (string) The SMTP port. DEFAULT: 587 (See RFC 6409/STD 72)
  • secure: (string) Use SSL or TLS to connect. DEFAULT: true (use 'tls' option, if available)
    • false (No encryption)
    • 'ssl' (Auto-detect SSL version)
    • 'sslv2' (Force SSL version 2)
    • 'sslv3' (Force SSL version 3)
    • 'tls' (TLS; started via protocol-level negotation over unencrypted channel; RECOMMENDED way of initiating secure connection)
    • 'tlsv1' (TLS direct version 1.x connection to server) [@since 1.3.0]
    • true (Use TLS, if available) [@since 1.2.0]
  • timeout: (integer) Connection timeout, in seconds. DEFAULT: 30 seconds
  • username: (string) The SMTP username. DEFAULT: NONE
  • xoauth2_token: (string) If set, will authenticate via the XOAUTH2 mechanism (if available) with this token. Either a string or a Horde_Smtp_Password object (since 1.1.0).

shutdown()

shutdown() 

Shutdown actions.

__clone()

__clone() 

This object can not be cloned.

serialize()

serialize() 

unserialize()

unserialize(  $data) 

Parameters

$data

__get()

__get(  $name) 

Parameters

$name

getParam()

getParam(string  $key) : mixed

Returns a value from the internal params array.

Parameters

string $key

The param key.

Returns

mixed —

The param value, or null if not found.

setParam()

setParam(string  $key, mixed  $val) 

Sets a configuration parameter value.

Parameters

string $key

The param key.

mixed $val

The param value.

queryExtension()

queryExtension(string  $ext) : mixed

Returns whether the SMTP server supports the given extension.

Parameters

string $ext

The extension to query.

Returns

mixed —

False if the server doesn't support the extension; otherwise, the extension value (returns true if the extension only supports existence).

isSecureConnection()

isSecureConnection() : boolean

Display if connection to the server has been secured via TLS or SSL.

Returns

boolean —

True if the SMTP connection is secured.

login()

login() 

Connect/login to the SMTP server.

Throws

\Horde_Smtp_Exception

logout()

logout() 

Logout from the SMTP server.

send()

send(mixed  $from, mixed  $to, mixed  $data, array  $opts = array()) : array

Send a message.

Parameters

mixed $from

The from address. Either a Horde_Mail_Rfc822_Address object or a string.

mixed $to

The to (recipient) addresses. Either a Horde_Mail_Rfc822_List object, a string, or an array of addresses.

mixed $data

The data to send. Either a stream or a string.

array $opts

Throws

\Horde_Smtp_Exception
\Horde_Smtp_Exception_Recipients
\InvalidArgumentException

Returns

array —

If no receipients were successful, a Horde_Smtp_Exception will be thrown. If at least one recipient was successful, an array with the following format is returned: (@since 1.5.0)

  • KEYS: Recipient addresses ($to addresses).
  • VALUES: Boolean true (if message was accepted for this recpieint) or a Horde_Smtp_Exception (if messages was not accepted).

resetCmd()

resetCmd() 

Send a reset command.

Throws

\Horde_Smtp_Exception

noop()

noop() 

Send a NOOP command.

Throws

\Horde_Smtp_Exception

processQueue()

processQueue(string  $host = null) 

Send request to process the remote queue.

Parameters

string $host

The specific host to request queue processing for.

Throws

\Horde_Smtp_Exception

_getEncryptKey()

_getEncryptKey() : string

Get encryption key.

Returns

string —

The encryption key.

_initOb()

_initOb() 

Do initialization tasks.

_hello()

_hello() 

Send "Hello" command to the server.

Throws

\Horde_Smtp_Exception

_startTls()

_startTls() : boolean

Starts the TLS connection to the server, if necessary. See RFC 3207.

Throws

\Horde_Smtp_Exception

Returns

boolean —

True if TLS was started.

_auth()

_auth(string  $method) 

Authenticate user to server for a given method.

Parameters

string $method

Authentication method.

Throws

\Horde_Smtp_Exception

_getResponse()

_getResponse(mixed  $code, array  $opts = array()) : array

Gets a line from the incoming stream and parses it.

Parameters

mixed $code

Expected reply code(s) (integer or array).

array $opts

Additional options:

  - error: (string) On error, 'logout' or 'reset'?
  - exception: (string) Throw an exception of this class on error.

Throws

\Horde_Smtp_Exception

Returns

array —

An array with the response text.

_processData()

_processData(array  $recipients) : array

Process the return from the DATA command.

Parameters

array $recipients

The list of message recipients.

Throws

\Horde_Smtp_Exception

Returns

array —

See _send().

_getHostname()

_getHostname() : string

Return the local hostname.

Returns

string —

Local hostname (null if it cannot be determined).