Documentation

Smtp extends EsmtpTransport
in package
implements TransportInterface

SMTP transport class

Tags
category

Pop

author

Nick Sagona, III dev@noladev.com

copyright

Copyright (c) 2009-2026 NOLA Interactive, LLC.

license

https://www.popphp.org/license New BSD License

version
4.0.7

Table of Contents

Interfaces

TransportInterface
Mail transport interface

Properties

$buffer  : BufferInterface|null
Input-Output buffer for sending/receiving SMTP commands and responses
$domain  : string
The domain name to use in HELO command
$sourceIp  : string|null
Source IP
$started  : bool
Connection status

Methods

__call()  : mixed
Mixin handling method for ESMTP handlers
__construct()  : mixed
Create a new SMTP transport
__destruct()  : mixed
Destructor
create()  : Smtp
Create the SMTP transport
executeCommand()  : string
Run a command against the buffer, expecting the given response codes.
getBuffer()  : BufferInterface
Get the IoBuffer where read/writes are occurring.
getEncryption()  : string
Get the encryption type
getExtensionHandlers()  : array<string|int, mixed>
Get ESMTP extension handlers
getHost()  : string
Get the host to connect to
getLocalDomain()  : string
Get the name of the domain Swift will identify as
getPort()  : int
Get the port to connect to
getSourceIp()  : string|null
Returns the IP used to connect to the destination
getStreamOptions()  : array<string|int, mixed>
Returns the stream context options
getTimeout()  : int
Get the connection timeout
isStarted()  : bool
Test if an SMTP connection has been established
reset()  : void
Reset the current mail transaction.
send()  : int
Send the message
setEncryption()  : EsmtpTransport
Set the encryption type (tls or ssl)
setExtensionHandlers()  : EsmtpTransport
Set ESMTP extension handlers
setHost()  : EsmtpTransport
Set the host to connect to
setLocalDomain()  : AbstractSmtp
Set the name of the local domain which Swift will identify itself as.
setPort()  : EsmtpTransport
Set the port to connect to
setSourceIp()  : EsmtpTransport
Sets the source IP
setStreamOptions()  : EsmtpTransport
Sets the stream context options
setTimeout()  : EsmtpTransport
Set the connection timeout
start()  : void
Start the SMTP connection
stop()  : void
Stop the SMTP connection.
assertResponseCode()  : void
Throws an Exception if a response code is incorrect
doDataCommand()  : void
Send the DATA command
doHeloCommand()  : void
Overridden to perform EHLO instead
doMailFromCommand()  : void
Overridden to add Extension support
doRcptToCommand()  : void
Overridden to add Extension support
getBufferParams()  : array<string|int, mixed>
Get the params to initialize the buffer
getFullResponse()  : string
Get an entire multi-line response using its sequence number
getReversePath()  : null|string
Determine the best-use reverse path for this message
readGreeting()  : void
Read the opening SMTP greeting
streamMessage()  : void
Stream the contents of the message over the buffer
throwException()  : void
Throw a TransportException, first sending it to any listeners

Properties

$domain

The domain name to use in HELO command

protected string $domain = '[127.0.0.1]'

$sourceIp

Source IP

protected string|null $sourceIp = null

$started

Connection status

protected bool $started = false

Methods

__call()

Mixin handling method for ESMTP handlers

public __call(mixed $method, mixed $args) : mixed
Parameters
$method : mixed
$args : mixed
Tags
throws
Exception

__construct()

Create a new SMTP transport

public __construct([string $host = 'localhost' ][, int $port = 25 ][, string|null $security = null ][, BufferInterface|null $buffer = null ][, array<string|int, mixed>|null $handlers = null ]) : mixed
Parameters
$host : string = 'localhost'
$port : int = 25
$security : string|null = null
$buffer : BufferInterface|null = null
$handlers : array<string|int, mixed>|null = null

create()

Create the SMTP transport

public static create(array<string|int, mixed> $options) : Smtp
Parameters
$options : array<string|int, mixed>
Tags
throws
Exception
Return values
Smtp

executeCommand()

Run a command against the buffer, expecting the given response codes.

public executeCommand(string $command[, array<string|int, mixed> $codes = [] ]) : string

If no response codes are given, the response will not be validated. If codes are given, an exception will be thrown on an invalid response.

Parameters
$command : string
$codes : array<string|int, mixed> = []
Return values
string

getEncryption()

Get the encryption type

public getEncryption() : string
Return values
string

getExtensionHandlers()

Get ESMTP extension handlers

public getExtensionHandlers() : array<string|int, mixed>
Return values
array<string|int, mixed>

getHost()

Get the host to connect to

public getHost() : string
Return values
string

getLocalDomain()

Get the name of the domain Swift will identify as

public getLocalDomain() : string
Return values
string

getPort()

Get the port to connect to

public getPort() : int
Return values
int

getSourceIp()

Returns the IP used to connect to the destination

public getSourceIp() : string|null
Return values
string|null

getStreamOptions()

Returns the stream context options

public getStreamOptions() : array<string|int, mixed>
Return values
array<string|int, mixed>

getTimeout()

Get the connection timeout

public getTimeout() : int
Return values
int

isStarted()

Test if an SMTP connection has been established

public isStarted() : bool
Return values
bool

reset()

Reset the current mail transaction.

public reset() : void

send()

Send the message

public send(Message $message) : int
Parameters
$message : Message
Return values
int

setExtensionHandlers()

Set ESMTP extension handlers

public setExtensionHandlers(array<string|int, mixed> $handlers) : EsmtpTransport
Parameters
$handlers : array<string|int, mixed>
Return values
EsmtpTransport

setLocalDomain()

Set the name of the local domain which Swift will identify itself as.

public setLocalDomain(string $domain) : AbstractSmtp

This should be a fully-qualified domain name and should be truly the domain you're using.

If your server doesn't have a domain name, use the IP in square brackets (i.e. [127.0.0.1]).

Parameters
$domain : string
Return values
AbstractSmtp

setStreamOptions()

Sets the stream context options

public setStreamOptions(array<string|int, mixed> $options) : EsmtpTransport
Parameters
$options : array<string|int, mixed>
Return values
EsmtpTransport

start()

Start the SMTP connection

public start() : void

assertResponseCode()

Throws an Exception if a response code is incorrect

protected assertResponseCode(string $response, array<string|int, mixed> $wanted) : void
Parameters
$response : string
$wanted : array<string|int, mixed>

doDataCommand()

Send the DATA command

protected doDataCommand() : void

doHeloCommand()

Overridden to perform EHLO instead

protected doHeloCommand() : void

doMailFromCommand()

Overridden to add Extension support

protected doMailFromCommand(string $address) : void
Parameters
$address : string

doRcptToCommand()

Overridden to add Extension support

protected doRcptToCommand(string $address) : void
Parameters
$address : string

getBufferParams()

Get the params to initialize the buffer

protected getBufferParams() : array<string|int, mixed>
Return values
array<string|int, mixed>

getFullResponse()

Get an entire multi-line response using its sequence number

protected getFullResponse(string $seq) : string
Parameters
$seq : string
Tags
throws
Exception
Return values
string

getReversePath()

Determine the best-use reverse path for this message

protected getReversePath(Message $message) : null|string
Parameters
$message : Message
Return values
null|string

readGreeting()

Read the opening SMTP greeting

protected readGreeting() : void

streamMessage()

Stream the contents of the message over the buffer

protected streamMessage(Message $message) : void
Parameters
$message : Message

        
On this page

Search results