This document details the various options available to the Zend\Mail\Transport\Smtp mail transport.
Basic SMTP Transport Usage
1 2 3 4 5 6 7 8 9 10 11 | use Zend\Mail\Transport\Smtp as SmtpTransport;
use Zend\Mail\Transport\SmtpOptions;
// Setup SMTP transport
$transport = new SmtpTransport();
$options = new SmtpOptions(array(
'name' => 'localhost.localdomain',
'host' => '127.0.0.1',
'port' => 25,
));
$transport->setOptions($options);
|
SMTP Transport Usage with PLAIN AUTH
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | use Zend\Mail\Transport\Smtp as SmtpTransport;
use Zend\Mail\Transport\SmtpOptions;
// Setup SMTP transport using PLAIN authentication
$transport = new SmtpTransport();
$options = new SmtpOptions(array(
'name' => 'localhost.localdomain',
'host' => '127.0.0.1',
'connection_class' => 'plain',
'connection_config' => array(
'username' => 'user',
'password' => 'pass',
),
));
$transport->setOptions($options);
|
SMTP Transport Usage with LOGIN AUTH
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | use Zend\Mail\Transport\Smtp as SmtpTransport;
use Zend\Mail\Transport\SmtpOptions;
// Setup SMTP transport using LOGIN authentication
$transport = new SmtpTransport();
$options = new SmtpOptions(array(
'name' => 'localhost.localdomain',
'host' => '127.0.0.1',
'connection_class' => 'login',
'connection_config' => array(
'username' => 'user',
'password' => 'pass',
),
));
$transport->setOptions($options);
|
SMTP Transport Usage with CRAM-MD5 AUTH
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | use Zend\Mail\Transport\Smtp as SmtpTransport;
use Zend\Mail\Transport\SmtpOptions;
// Setup SMTP transport using CRAM-MD5 authentication
$transport = new SmtpTransport();
$options = new SmtpOptions(array(
'name' => 'localhost.localdomain',
'host' => '127.0.0.1',
'connection_class' => 'crammd5',
'connection_config' => array(
'username' => 'user',
'password' => 'pass',
),
));
$transport->setOptions($options);
|
SMTP Transport Usage with PLAIN AUTH over TLS
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | use Zend\Mail\Transport\Smtp as SmtpTransport;
use Zend\Mail\Transport\SmtpOptions;
// Setup SMTP transport using PLAIN authentication over TLS
$transport = new SmtpTransport();
$options = new SmtpOptions(array(
'name' => 'example.com',
'host' => '127.0.0.1',
'port' => 587, // Notice port change for TLS is 587
'connection_class' => 'plain',
'connection_config' => array(
'username' => 'user',
'password' => 'pass',
'ssl' => 'tls',
),
));
$transport->setOptions($options);
|
Configuration Options
Fully-qualified classname or short name resolvable via Zend\Mail\Protocol\SmtpLoader. Typically, this will be one of “smtp”, “plain”, “login”, or “crammd5”, and defaults to “smtp”.
Typically, the connection class should extend the Zend\Mail\Protocol\AbstractProtocol class, and specifically the SMTP variant.
getName()
Returns the string name of the local client hostname.
setName(string $name)
Set the string name of the local client hostname.
Implements a fluent interface.
getConnectionClass()
Returns a string indicating the connection class name to use.
setConnectionClass(string $connectionClass)
Set the connection class to use.
Implements a fluent interface.
getConnectionConfig()
Get configuration for the connection class.
Returns array.
setConnectionConfig(array $config)
Set configuration for the connection class. Typically, if using anything other than the default connection class, this will be an associative array with the keys “username” and “password”.
Implements a fluent interface.
getHost()
Returns a string indicating the IP address or host name of the SMTP server via which to send messages.
setHost(string $host)
Set the SMTP host name or IP address.
Implements a fluent interface.
getPort()
Retrieve the integer port on which the SMTP host is listening.
setPort(int $port)
Set the port on which the SMTP host is listening.
Implements a fluent interface.
__construct(null|array|Traversable $config)
Instantiate the class, and optionally configure it with values provided.
Please see the Quick Start for examples.
The source code of this file is hosted on GitHub. Everyone can update and fix errors in this document with few clicks - no downloads needed.