Oihana PHP Enums

SmtpSecurity uses ConstantsTrait

Symbolic values of an SMTP `secure` configuration key, and the rules that map them onto a {@see SmtpScheme} and a default port.

Replaces the inline match( $secure ) blocks often scattered through DI definitions when building a Symfony Mailer DSN:

$scheme = SmtpSecurity::scheme     ( $secure ) ; // 'smtp' | 'smtps'
$port   = SmtpSecurity::defaultPort( $secure ) ; // 465 | 587 | 25

The six accepted values are pairs of synonyms — both spellings are valid configuration input, so both are declared as constants and therefore recognised by validate(), includes() and enums():

secure scheme default port TLS
ssl / smtps smtps 465 implicit
tls / starttls smtp 587 STARTTLS
none / plain smtp 25 none (dev only)

An absent, empty or unknown value falls back to the STARTTLS behaviour (smtp / 587), the safe default for modern submission.

Tags
author

Marc Alcaraz

since
1.2.0
see
SmtpScheme

Table of Contents

Constants

NONE  : string = 'none'
Cleartext, no encryption (synonym of {@see self::PLAIN}). Scheme `smtp`, port `25` — dev only.
PLAIN  : string = 'plain'
Cleartext, no encryption. Scheme `smtp`, port `25` — dev only.
SMTPS  : string = 'smtps'
Implicit TLS. Scheme `smtps`, port `465`.
SSL  : string = 'ssl'
Implicit TLS (synonym of {@see self::SMTPS}). Scheme `smtps`, port `465`.
STARTTLS  : string = 'starttls'
Opportunistic STARTTLS. Scheme `smtp`, port `587`.
TLS  : string = 'tls'
Opportunistic STARTTLS (synonym of {@see self::STARTTLS}). Scheme `smtp`, port `587`.

Methods

defaultPort()  : int
Maps a `secure` value onto the conventional default SMTP port.
isImplicitTls()  : bool
Whether the mode negotiates TLS up front (`smtps`) rather than via STARTTLS.
scheme()  : string
Maps a `secure` value onto the SMTP DSN scheme.

Constants

NONE

Cleartext, no encryption (synonym of {@see self::PLAIN}). Scheme `smtp`, port `25` — dev only.

public string NONE = 'none'

PLAIN

Cleartext, no encryption. Scheme `smtp`, port `25` — dev only.

public string PLAIN = 'plain'

SMTPS

Implicit TLS. Scheme `smtps`, port `465`.

public string SMTPS = 'smtps'

SSL

Implicit TLS (synonym of {@see self::SMTPS}). Scheme `smtps`, port `465`.

public string SSL = 'ssl'

STARTTLS

Opportunistic STARTTLS. Scheme `smtp`, port `587`.

public string STARTTLS = 'starttls'

TLS

Opportunistic STARTTLS (synonym of {@see self::STARTTLS}). Scheme `smtp`, port `587`.

public string TLS = 'tls'

Methods

defaultPort()

Maps a `secure` value onto the conventional default SMTP port.

public static defaultPort(string|null $secure) : int
Parameters
$secure : string|null

One of the class constants (case-insensitive). Absent / empty / unknown falls back to STARTTLS.

Return values
int

465 (implicit TLS), 25 (cleartext) or 587 (STARTTLS).

isImplicitTls()

Whether the mode negotiates TLS up front (`smtps`) rather than via STARTTLS.

public static isImplicitTls(string|null $secure) : bool
Parameters
$secure : string|null

One of the class constants (case-insensitive).

Return values
bool

true for ssl / smtps, false otherwise.

scheme()

Maps a `secure` value onto the SMTP DSN scheme.

public static scheme(string|null $secure) : string
Parameters
$secure : string|null

One of the class constants (case-insensitive). Absent / empty / unknown falls back to STARTTLS.

Return values
string

Either SmtpScheme::SMTP or SmtpScheme::SMTPS.

On this page

Search results